π§© Topic: Files and Protection
ποΈ What is a File?
A file is a collection of related data stored on secondary storage (e.g., HDD, SSD) that is used by programs and users.
π Files are the unit of logical storage in an operating system.
π¦ File Attributes
Each file has a set of attributes stored in the directory entry:
| Attribute | Description |
|---|---|
| Name | Human-readable name of the file |
| Type | File extension (e.g., .txt, .exe) |
| Size | Current size of the file in bytes |
| Location | Disk address where the file is stored |
| Protection | Access permissions (read/write/exec) |
| Time | Creation/modification/access timestamps |
ποΈ File Operations
OS provides system calls to perform file operations like:
| Operation | Description |
|---|---|
| Create | Create a new file |
| Delete | Remove a file |
| Open | Load file metadata into memory |
| Close | Flush buffers and release resources |
| Read/Write | Access or modify file contents |
| Seek | Move file pointer to a specific byte |
| Rename | Change file name |
| Append | Add data to end of file |
π File Protection
File protection ensures that unauthorized users cannot access, modify, or delete files.
π Access Rights / File Permissions
Permissions control who can do what with a file. Common permissions:
| Permission | Meaning |
|---|---|
| Read (r) | View contents |
| Write (w) | Modify or delete |
| Execute (x) | Run the file (if itβs a program) |
π₯ User-Based Access Control
Most systems divide users into three categories:
| User Category | Applies To |
|---|---|
| Owner | The creator of the file |
| Group | A group of users |
| Others | All other system users |
Example (Linux): rwxr-x--x
β Owner: rwx (all access)
β Group: r-x (read and execute)
β Others: --x (only execute)
π Access Control Matrix
A matrix where:
- Rows = Subjects (users/processes)
- Columns = Objects (files)
- Cells = Permissions (r, w, x)
Example:
| File A | File B | |
|---|---|---|
| User 1 | r, w | r |
| User 2 | β | r, x |
β Simple to understand β Can be large and inefficient for big systems
π Techniques for File Protection
| Technique | Description |
|---|---|
| Access Control Lists (ACL) | Lists permissions for each user/group |
| Password Protection | File access allowed only with password |
| Encryption | Data is stored in an unreadable form without a key |
| File Locking | Prevents simultaneous conflicting access (used in DBs) |
β οΈ Need for Protection
- Prevent data loss or corruption
- Enforce user privacy and confidentiality
- Avoid accidental or malicious changes
β Summary
| Concept | Description |
|---|---|
| File | Logical unit of data storage |
| Attributes | Metadata stored about each file |
| Operations | OS provides methods to manipulate files |
| Protection | Prevents unauthorized access to files |
| Permissions | r (read), w (write), x (execute) |
| Control Mechanisms | ACLs, passwords, encryption, access matrix |
π§© Topic: File System Organization
π§ What is a File System?
A File System is a method used by operating systems to organize, store, retrieve, and manage files and directories on storage devices (like HDDs or SSDs).
It defines:
- How files and directories are arranged
- How metadata and permissions are stored
- How the OS locates file contents on disk
ποΈ File System Components
| Component | Description |
|---|---|
| Files | Collection of related data (text, image, etc.) |
| Directories | Containers for organizing files |
| Blocks | Unit of data allocation on disk (e.g., 4 KB) |
| Metadata | Info like file name, size, type, timestamps |
| File Allocation Info | Tracks which blocks are used for which file |
| Free Space Info | Tracks which blocks are free |
ποΈ Levels of File System Organization
| Level | Description |
|---|---|
| Application Level | User interacts with files via programs |
| Logical File System | Manages metadata, directories, and file protection |
| File Organization Module | Allocates logical blocks to physical blocks |
| Basic File System | Reads and writes physical blocks to storage device |
| I/O Control | Handles device drivers and hardware communication |
π File System Organization Types
πΉ 1. Single-Level Directory
- All files are stored in one directory
β Pros:
- Simple and easy to manage
β Cons:
- No grouping β name conflicts
- Not suitable for many users
πΉ 2. Two-Level Directory
- Each user has their own separate directory
β Pros:
- No name conflicts between users
- Better file separation
β Cons:
- No subdirectories
- Poor grouping within user files
πΉ 3. Tree-Structured Directory
- Files organized in hierarchical tree structure
/
βββ user1/
β βββ docs/
β βββ pics/
βββ user2/
βββ work/
β Pros:
- Good grouping, scalable
- Allows full paths and easy navigation
β Cons:
- More complex than flat structures
πΉ 4. Acyclic Graph Directory
- Allows shared subdirectories and files using links (hard/soft)
β Pros:
- Useful for shared projects and teams
β Cons:
- Need cycle detection to avoid infinite loops
πΉ 5. General Graph Directory
- Allows full sharing and multiple links, including cycles
β Powerful β Requires garbage collection and careful tracking
π¦ Examples of File Systems
| File System | Used In | Notes |
|---|---|---|
| FAT32 | Windows | Simple, widely supported, no permissions |
| NTFS | Windows | Supports ACLs, journaling, compression |
| ext3/ext4 | Linux | Journaling, good performance |
| APFS | macOS | Modern, secure, snapshots |
π Features of a Good File System
- Fast access
- Efficient space usage
- File protection & security
- Support for large files
- Fault tolerance (journaling)
- Easy to navigate structure
β Summary
| Area | Key Point |
|---|---|
| File system | Organizes files on storage |
| Directory structures | Single-level, two-level, tree, graph |
| Metadata | Stores info like name, size, timestamps |
| Allocation | Tracks where file blocks are stored |
| Access control | Protects files using permissions |
π§© Topic: File Operations
π§ What are File Operations?
File operations are actions provided by the operating system that allow users and programs to interact with files.
π These operations are performed using system calls (e.g., in C, Python, Java) and are essential for file management.
π οΈ Basic File Operations
| Operation | Description |
|---|---|
| Create | Make a new file in a directory |
| Open | Load file metadata and prepare for reading or writing |
| Read | Retrieve data from the file into memory |
| Write | Store new data into the file |
| Append | Add data to the end of the file without overwriting |
| Seek | Move file pointer to a specific position for reading/writing |
| Close | Terminate access and flush file buffers to disk |
| Delete | Remove a file from the file system |
| Rename | Change the name of a file |
| Truncate | Remove all contents while keeping the file (size = 0) |
π System Call Example (Linux/Unix)
| Operation | System Call (C) |
|---|---|
| Create | creat() or open() |
| Open | open() |
| Read | read() |
| Write | write() |
| Seek | lseek() |
| Close | close() |
| Delete | unlink() |
π How File Operations Work
- Open system call β returns a file descriptor
- File descriptor used in read/write/seek
- Close system call β frees system resources
π Access Control in Operations
-
The OS checks permissions before allowing any operation:
-
Read-only: Only reading allowed
- Write-only: Cannot read from the file
- Read/Write: Both actions allowed
- Execute: Only for binary/program files
π§ Use Case Examples
| Scenario | Operation(s) Used |
|---|---|
| Editing a document | Open β Read β Write β Close |
| Viewing a file | Open β Read β Close |
| Uploading a log | Open (Append) β Write β Close |
| Deleting old records | Open β Truncate or Delete |
| Compiling a program | Create (for .out file) β Write β Execute |
β Summary
| Operation | Purpose |
|---|---|
| Create | Make a new file |
| Read/Write | Access and modify contents |
| Append | Add to end without erasing |
| Seek | Navigate to specific location |
| Delete | Permanently remove the file |
| Close | Finish file access safely |
π§© Topic: File Access Methods
π§ What are File Access Methods?
Access methods define how data in a file is read or written. Different types of applications require different ways of accessing file data.
π Operating systems provide multiple access methods to suit different use cases like media streaming, databases, and logs.
π Types of File Access Methods
| Method | Key Idea | Example Use Case |
|---|---|---|
| 1. Sequential | Access data in order from beginning | Logs, media files |
| 2. Direct | Access any block of data directly | Databases, index files |
| 3. Indexed | Use an index to access data blocks | Searchable filesystems |
πΉ 1. Sequential Access
- Data is read one record after another in a fixed order (start to end).
- Most common and simplest method.
π§± Operations:
read nextwrite next- No skipping or jumping
β Advantages:
- Simple to implement
- Efficient for large, continuous reads
β Disadvantages:
- Slow if you need data in the middle or end
- No random access
π Example:
Reading a text file line by line
πΉ 2. Direct (Random) Access
- File viewed as a series of numbered blocks/records.
- Access any record using its position/index.
π§± Operations:
read nwrite n- Can jump forward or backward
β Advantages:
- Fast access to specific records
- Ideal for databases and large files
β Disadvantages:
- More complex to implement
- May require fixed record sizes
π Example:
Bank database fetching customer record #105
πΉ 3. Indexed Access
- Uses an index (like a book index) to maintain pointers to data blocks.
- Index maps a key or block number to its storage location.
β Advantages:
- Combines speed of direct access with flexibility
- Efficient for both sequential and random access
β Disadvantages:
- Index overhead (extra memory/storage)
- Slower than direct access alone
π Example:
Retrieving a chapter from an eBook using its table of contents
π Comparison Table
| Feature | Sequential Access | Direct Access | Indexed Access |
|---|---|---|---|
| Access Order | Linear only | Random | Random or Sequential |
| Speed (Random) | Slow | Fast | Moderate |
| Flexibility | Low | High | Very High |
| Use Case | Logs, media | Databases | Large structured files |
| Implementation | Easy | Medium | Complex |
β Summary
- Sequential Access: Simple, linear read/write (e.g., text logs)
- Direct Access: Jump to any block using offset (e.g., database)
- Indexed Access: Uses an index to improve access (e.g., book or filesystem)
π§© Topic: Consistency Semantics
π§ What are Consistency Semantics?
Consistency semantics define the rules and behavior the operating system follows when multiple processes access or modify the same file concurrently.
π In simple terms:
βIf two users or programs are reading/writing the same file at the same time, what should they see?β
π― Why Is It Important?
- Ensures data integrity during concurrent access
- Prevents race conditions, data loss, and inconsistent views
- Supports multi-user and networked environments (e.g., cloud storage, file servers)
π Types of Consistency Semantics
| Semantics | Description |
|---|---|
| 1. UNIX Semantics | Changes made by one process are immediately visible to all others |
| 2. Session Semantics | Changes made by a process are only visible after file is closed |
| 3. Immutable-Shared Files | Files are never changed; a new version is created for each update |
| 4. Transactional Semantics | All changes happen in an atomic transaction β fully completed or not at all |
πΉ 1. UNIX Semantics
- When a process writes to a file, all other processes see the change immediately.
- Most common in local file systems (like ext4, NTFS).
β Real-time collaboration β Race conditions if not synchronized
πΉ 2. Session Semantics
- Changes are only visible after the file is closed.
- Used in NFS (Network File System).
β Prevents partial writes β May confuse users expecting real-time updates
πΉ 3. Immutable-Shared File Semantics
- File once written cannot be modified.
- Any update creates a new version.
β Very safe for read-only and version-controlled systems β Requires more storage
π Example: Git, Dropbox (file history)
πΉ 4. Transactional Semantics
- All changes are treated as a transaction: either fully done or rolled back.
- Used in databases and journaling file systems.
β Ensures consistency even during crashes β Ideal for financial/data-critical apps
π Comparison Table
| Semantics | Visibility of Changes | Used In | Pros | Cons |
|---|---|---|---|---|
| UNIX | Immediately after write | Local OS file systems | Real-time, simple | Needs sync for safety |
| Session | After file is closed | NFS, distributed FS | Safer than UNIX | Delayed visibility |
| Immutable-Shared | Never changed | Git, versioned systems | No conflict, version control | Storage overhead |
| Transactional | After commit | DBMS, ext4/ext3 with journaling | Safe, atomic updates | Complex and slower |
β Summary
- Consistency semantics determine how file updates are seen by multiple users/processes.
- Important for ensuring safe, predictable behavior in file access.
- Different systems use different semantics based on speed, safety, and use-case.
π§© Topic: Directory Structure Organization
π§ What is a Directory?
A directory is a special type of file used by the operating system to organize and manage files.
It stores information such as:
- File names
- Attributes (size, permissions)
- Locations (pointers to file data on disk)
π Directories help users navigate, group, and control access to files easily.
π Objectives of Directory Structure
- Efficient file lookup and access
- Organize files logically
- Manage user access rights
- Support file sharing and naming
π§± Types of Directory Structures
πΉ 1. Single-Level Directory
- All files are stored in one directory
- Simple and easy to implement
β Advantages:
- Easy to understand and use
- Quick access to files
β Disadvantages:
- Name conflicts if multiple files have the same name
- Difficult to manage large number of files
πΉ 2. Two-Level Directory
- A separate directory for each user.
root
βββ user1
βββ user2
β Advantages:
- File names can be same for different users
- Separation of user files
β Disadvantages:
- No subdirectories
- Poor organization within user space
πΉ 3. Tree-Structured Directory
- Hierarchical structure with root directory
- Users can create subdirectories inside directories
/
βββ user1/
β βββ docs/
β βββ pics/
βββ user2/
βββ projects/
β Advantages:
- Logical organization of files
- Supports path-based access (e.g.,
/user1/docs/file.txt)
β Disadvantages:
- Requires careful management of paths
πΉ 4. Acyclic Graph Directory
- Allows sharing of files or directories using links
/docs/project.txt (linked from /user1 and /user2)
β Advantages:
- Efficient for collaboration
- No duplication of files
β Disadvantages:
- Complexity in maintaining links
- Requires cycle detection
πΉ 5. General Graph Directory
- Similar to acyclic graph, but allows cycles
- Complex reference and link management
β Advantages:
- Full file sharing flexibility
β Disadvantages:
- Garbage collection and reference tracking are required
- Can create infinite loops during traversal
π Comparison Table
| Structure | Sharing | Subdirs | Complexity | Use Case |
|---|---|---|---|---|
| Single-Level | β | β | Low | Small systems |
| Two-Level | β | β | Medium | Multi-user systems |
| Tree | β | β | Medium | Most desktop OS |
| Acyclic Graph | β | β | High | Collaborative projects |
| General Graph | β | β | Very High | Rare, advanced systems |
π Directory Operations
| Operation | Description |
|---|---|
| Create | Add a new file or directory |
| Delete | Remove a file or directory |
| Rename | Change the name of a file/directory |
| Search | Locate a file within the structure |
| Traverse | List all contents of a directory |
β Summary
- Directory structures help manage and organize files in a system.
- Common types: Single-level, Two-level, Tree, Acyclic Graph, General Graph.
- More advanced structures support file sharing and collaboration.
- The choice depends on system size, user count, and file-sharing needs.
π§© Topic: File Protection
π What is File Protection?
File protection refers to the mechanisms provided by the operating system to prevent unauthorized access or modification of files.
π It ensures confidentiality, integrity, and availability of files, especially in multi-user or networked systems.
π― Objectives of File Protection
- Prevent accidental or malicious changes
- Ensure only authorized users can access files
- Protect critical system and user data
- Enforce access policies
π Access Rights / Permissions
Most file systems define three basic types of permissions:
| Permission | Symbol | Description |
|---|---|---|
| Read | r |
View file contents |
| Write | w |
Modify or delete the file |
| Execute | x |
Run the file as a program/script |
π₯ User Classes (in Unix/Linux)
Files are protected against unauthorized access based on user categories:
| Class | Applies To |
|---|---|
| Owner | The user who created the file |
| Group | Other users in the same group |
| Others | All other system users |
Example Permission:
-rwxr-x--x
- Owner:
rwxβ full access - Group:
r-xβ read and execute - Others:
--xβ only execute
ποΈ Protection Mechanisms
πΉ 1. Access Control Lists (ACLs)
- A list that specifies individual user or group permissions on a file.
- More flexible than standard UNIX permissions.
Example:
user1: rw-
user2: r--
group_dev: rwx
β Fine-grained access control β More complex to manage
πΉ 2. Password Protection
- File can only be accessed by providing a password.
- Mostly used in older systems or simple applications.
β Easy to apply β Not scalable or secure for large systems
πΉ 3. Encryption
- File content is stored in encrypted form.
- Requires a key or password to decrypt and access.
β High-level security β Requires key management
πΉ 4. File Locking
- Prevents concurrent access by multiple users/programs to avoid conflicts.
- Used in databases, log files, configuration files.
| Type | Description |
|---|---|
| Shared | Multiple processes can read |
| Exclusive | Only one process can read or write |
πΉ 5. Access Matrix
A conceptual model representing who can do what on which file.
| File A | File B | |
|---|---|---|
| User1 | r, w | r |
| User2 | - | r, x |
π Common File Attacks and Risks
| Threat | Description |
|---|---|
| Unauthorized Read | Stealing confidential info |
| Unauthorized Write | Modifying/deleting important data |
| Program Execution | Running malicious code via execute permission |
β Summary
| Aspect | Description |
|---|---|
| Purpose | Prevent unauthorized file access |
| Permissions | Read, Write, Execute |
| Protection Methods | ACLs, encryption, file locking, passwords |
| User Classes | Owner, Group, Others |
| Importance | Ensures system and data security |
π§© Topic: File System Implementation Issues
π§ What Are File System Implementation Issues?
While designing or implementing a file system, the operating system faces several technical challenges related to:
- How files are stored
- How directories are organized
- How data blocks are allocated
- How to manage metadata, free space, and performance
π§ Key Implementation Issues in File Systems
1. Disk Layout and Partitioning
- A disk is divided into partitions (also called volumes).
-
Each partition contains:
-
Boot block (bootloader)
- Superblock (metadata about file system)
- Inode table or FAT table
- Data blocks
π OS must define how to organize and access these efficiently.
2. File Control Block (FCB)
-
Stores metadata about each file:
-
File name
- File size
- File type
- Permissions
- Disk block pointers
π FCB is stored in inode (Linux) or directory entry (Windows).
3. Directory Implementation
- OS must store and manage file names and metadata in directories.
Two main methods:
| Method | Description |
|---|---|
| Linear list | Simple list of files; slow for search |
| Hash table | Uses hash of file name for faster lookup |
4. File Allocation Methods
How the OS stores file data on disk blocks:
| Method | Description | Pros | Cons |
|---|---|---|---|
| Contiguous | Files stored in continuous blocks | Fast access | Fragmentation, resizing |
| Linked list | Each block points to next | No fragmentation | Slow random access |
| Indexed | Use index block to store pointers to blocks | Fast random access | Overhead of index block |
5. Free Space Management
OS needs to track available (free) blocks for file allocation.
Techniques:
- Bit map: 1 = used, 0 = free (efficient but large)
- Free list: Linked list of free blocks
- Grouping: Store addresses of free blocks inside other free blocks
6. File Access Methods
-
How users/programs read or write data:
-
Sequential
- Direct (random)
- Indexed
π Implementation must support the required access pattern efficiently.
7. File Protection and Security
- Enforce permissions (r/w/x) for users, groups, and others
- Use Access Control Lists (ACLs), encryption, etc.
8. Caching and Buffering
- OS uses memory buffers to store recently accessed files or data blocks
- Reduces disk I/O and increases speed
π Must handle cache coherence and synchronization
9. Consistency and Recovery
-
In case of a system crash, OS must:
-
Detect corruption
- Restore file system consistency
Techniques:
- Journaling (write log before actual changes)
- FSCK (File System Consistency Check)
β Summary
| Issue | Description |
|---|---|
| Disk Layout | Structure of partitions and blocks |
| File Metadata | Managed via inodes or FAT |
| Directory Implementation | Linear list or hash table |
| Allocation Methods | Contiguous, linked, indexed |
| Free Space Management | Bit maps, free lists, grouping |
| Access Methods | Sequential, direct, indexed |
| Protection & Security | Permissions, ACLs, encryption |
| Performance Optimization | Caching, buffering |
| Consistency & Recovery | Journaling, FSCK |
π§© Topic: Security Threats
π‘οΈ What are Security Threats?
Security threats are potential dangers that can harm the confidentiality, integrity, or availability of data and system resources in an operating system.
π These threats may come from:
- Internal or external users
- Malicious programs
- System vulnerabilities
π Goals of Security in OS
| Goal | Description |
|---|---|
| Confidentiality | Prevent unauthorized access to data |
| Integrity | Ensure data is not modified by unauthorized users |
| Availability | Ensure services/data are accessible when needed |
| Authentication | Verify user identity |
| Authorization | Give access based on permissions |
π¨ Types of Security Threats
1. Program Threats
Malicious code embedded in programs.
| Threat | Description |
|---|---|
| Trojan Horse | Program that appears harmless but performs malicious actions |
| Trapdoor (Backdoor) | Hidden entry point in a program to bypass security |
| Logic Bomb | Triggers malicious action when certain conditions are met |
| Virus | Self-replicating code that spreads and corrupts files |
| Worm | Similar to virus but spreads via networks |
2. System Threats
Target the system as a whole (OS, file system, network).
| Threat | Description |
|---|---|
| Denial of Service (DoS) | Overloading a system to make services unavailable |
| Spoofing | Attacker pretends to be another user/system |
| Phishing | Tricking users into revealing sensitive info |
| Session Hijacking | Taking over an active session without userβs consent |
3. User Threats
Security threats due to careless or malicious user behavior.
| Threat | Description |
|---|---|
| Social Engineering | Manipulating people to reveal confidential data |
| Weak Passwords | Easy-to-guess passwords expose system access |
| Unauthorized Access | Users accessing restricted data intentionally |
4. Physical Threats
Damage due to natural disasters, theft, or hardware failure.
| Threat | Description |
|---|---|
| Theft | Physical stealing of devices or storage |
| Fire/Flood | Natural hazards damaging data centers |
| Hardware Failure | Disk crash or power loss |
π§ Security Measures to Prevent Threats
| Technique | Purpose |
|---|---|
| Authentication | Validate user identity (passwords, biometrics) |
| Authorization | Define access rights using ACLs or roles |
| Encryption | Convert data into unreadable format |
| Firewalls | Control incoming/outgoing network traffic |
| Antivirus/Antimalware | Detect and remove malicious software |
| Regular Updates | Patch known vulnerabilities |
| Backups | Restore data after failures or attacks |
β Summary
| Threat Type | Examples |
|---|---|
| Program Threats | Trojan horse, virus, worm, logic bomb |
| System Threats | DoS, spoofing, phishing, session hijack |
| User Threats | Social engineering, unauthorized access |
| Physical Threats | Theft, fire, hardware damage |
π Remember:
- Always combine technical measures (encryption, firewalls) with user awareness (training, password hygiene) to build a secure system.
π§© Topic: Attacks on Security
π‘οΈ What are Security Attacks?
A security attack is any action that attempts to compromise the security of an operating system by violating its principles of confidentiality, integrity, or availability.
π These attacks can be:
- Passive: Monitoring or eavesdropping
- Active: Modification or destruction of data
π Types of Security Attacks
πΉ 1. Passive Attacks
These attacks do not alter data but try to gain unauthorized access to information.
| Attack Type | Description |
|---|---|
| Eavesdropping | Intercepting data (e.g., reading network traffic) |
| Traffic Analysis | Studying communication patterns to infer data |
β Hard to detect β No direct harm but breaches privacy
πΉ 2. Active Attacks
These attacks alter system resources or disrupt normal operations.
| Attack Type | Description |
|---|---|
| Masquerading (Impersonation) | Attacker pretends to be a legitimate user |
| Replay Attack | Reusing valid data (like credentials) to gain access |
| Message Modification | Changing the content of a message in transit |
| Denial of Service (DoS) | Overloading the system to make it unavailable |
| Man-in-the-Middle (MitM) | Attacker secretly intercepts and alters communication |
| Session Hijacking | Taking control of an active session |
π₯ Common OS-Level Security Attacks
| Attack | Description |
|---|---|
| Privilege Escalation | Gain higher access rights than authorized |
| Buffer Overflow | Overwrites memory to run malicious code |
| Malware Injection | Inserting Trojan, virus, or worm into OS files |
| Race Condition Attack | Exploits timing issues in file or resource access |
π§° Techniques Used in Security Attacks
| Technique | Description |
|---|---|
| Sniffing | Capturing unencrypted data from network traffic |
| Spoofing | Faking identities (IP, MAC, DNS) |
| Phishing | Tricking users into revealing sensitive information |
| Rootkits | Hide malicious processes from the OS |
| Keylogging | Recording keystrokes to steal credentials |
π§± Effects of Security Attacks
- Unauthorized data access
- System crashes or instability
- Data corruption or deletion
- Loss of service or denial of access
- Financial or reputation damage
π‘οΈ How to Prevent Security Attacks
| Defense Mechanism | Purpose |
|---|---|
| Authentication | Verify user identity (passwords, biometrics) |
| Authorization | Restrict user access based on roles |
| Encryption | Protect data during transmission or storage |
| Firewalls & IDS | Monitor and control network traffic |
| Patch Management | Fix known OS vulnerabilities |
| Anti-malware Tools | Detect and remove malicious software |
β Summary
| Attack Type | Examples | Prevention |
|---|---|---|
| Passive | Eavesdropping, traffic analysis | Encryption, secure protocols (TLS) |
| Active | DoS, spoofing, MitM, data alteration | Firewalls, authentication, IDS |
| OS-specific | Buffer overflow, privilege escalation | Patch updates, access control |
π§© Topic: Security Violations Through Parameters
π What are Security Violations Through Parameters?
Security violations through parameters refer to attacks or exploits that occur when an attacker manipulates inputs (parameters) passed to programs, system calls, or OS interfaces to gain unauthorized access, cause data corruption, or disrupt system behavior.
π These often exploit improper input validation and insecure coding practices.
π¨ Common Parameter-Based Security Violations
1. Buffer Overflow Attack
- Occurs when a program writes more data to a buffer than it can hold.
- Extra data can overwrite adjacent memory, including return addresses.
π Used to inject malicious code into memory.
Example:
char name[10];
gets(name); // dangerous: no length check
β Prevention:
- Input validation
- Use of secure functions (
fgets(),strncpy())
2. Format String Attack
- Caused by user-controlled input passed directly to functions like
printf().
Example:
printf(user_input); // if user_input = "%x %x %x", leaks memory
- Can lead to memory leaks or arbitrary code execution.
β Prevention:
- Use formatted functions carefully (e.g.,
printf("%s", user_input))
3. Command Injection
- User-supplied input is used in a system call or shell command.
- Attackers inject malicious commands.
Example:
os.system("ping " + user_input)
# user_input = "127.0.0.1 && rm -rf /"
β Prevention:
- Sanitize and validate inputs
- Avoid using system-level calls with raw user input
4. SQL Injection
- Injecting SQL code into user input fields to bypass authentication or manipulate databases.
Example:
SELECT * FROM users WHERE name = '$input';
# input = ' OR '1'='1
β Prevention:
- Use prepared statements or ORMs
- Sanitize inputs
5. Path Traversal Attack
- Input manipulation to access unauthorized files or directories by changing file paths.
Example:
GET /view?file=../../etc/passwd
β Prevention:
- Restrict file access to specific directories
- Normalize and validate paths
6. Improper Parameter Bounds or Type Checking
- Passing unexpected parameter types, lengths, or values to system APIs or kernel modules.
Example:
- Giving a negative array index
- Supplying a floating-point number where an integer is expected
β Prevention:
- Enforce strict type and boundary checks at every interface
π‘οΈ How OS Can Prevent Parameter-Based Violations
| Technique | Description |
|---|---|
| Input Validation | Check format, type, and length of all inputs |
| Bounds Checking | Prevent data from exceeding allocated memory |
| Privilege Separation | Limit permissions of processes using user inputs |
| Use Safe Libraries | Prefer safe APIs over unsafe ones |
| Auditing & Logging | Detect misuse and alert admins |
β Summary
| Attack Type | Exploit Method | Prevention |
|---|---|---|
| Buffer Overflow | Exceeding buffer size | Input validation, bounds checking |
| Format String Attack | Unfiltered format strings | Format user input before using |
| Command Injection | Executing user input as commands | Input sanitization, no raw system calls |
| SQL Injection | Injecting SQL through input | Prepared statements, sanitization |
| Path Traversal | Manipulating file paths | Validate file paths and access limits |
π¦ Topic: Computer Virus
π§ What is a Computer Virus?
A computer virus is a type of malicious software (malware) that can replicate itself and spread from one system or file to another, often without the user's knowledge.
π It attaches itself to a host program or file and activates when the infected file is executed.
π― Main Goals of a Virus:
- Disrupt system operation
- Steal or corrupt data
- Damage software or hardware
- Spread to other systems or networks
π Characteristics of a Virus
| Feature | Description |
|---|---|
| Self-replication | Can make copies of itself |
| Activation | Gets triggered by specific events (like opening a file) |
| Infection | Attaches to executables, boot sectors, macros, etc. |
| Damage | May delete data, corrupt files, slow systems |
π¬ Types of Computer Viruses
| Type | Description | Example |
|---|---|---|
| File Infector Virus | Attaches to executable files (.exe, .com) |
Cascade |
| Boot Sector Virus | Infects the systemβs boot sector | Michelangelo |
| Macro Virus | Infects Word/Excel macro-enabled documents | Melissa |
| Polymorphic Virus | Changes code to avoid detection | Storm Worm |
| Resident Virus | Loads into memory and infects files actively | Randex |
| Worm (related) | Spreads without needing a host file (network-based) | Blaster, WannaCry |
π¨ Symptoms of Virus Infection
- Slow performance
- Crashing or freezing
- Files missing or corrupted
- Unknown programs running
- Excessive pop-ups or system errors
π‘οΈ How to Prevent Computer Viruses
| Prevention Method | Description |
|---|---|
| Antivirus Software | Detects and removes known viruses |
| Regular Updates | Patch OS and apps to fix security holes |
| Avoid Untrusted Sources | Do not open unknown email attachments or links |
| Firewall | Blocks unauthorized access |
| Backup | Regular data backup in case of infection |
| Disable Macros | Disable macros in documents unless trusted |
β Summary
| Feature | Details |
|---|---|
| Definition | Self-replicating malicious program |
| Behavior | Infects, spreads, causes harm |
| Common Types | File infector, boot sector, macro, polymorphic |
| Prevention | Antivirus, updates, caution with unknown sources |
π§© Topic: Security Design Principles
π What are Security Design Principles?
Security design principles are fundamental guidelines used to build secure operating systems and software. These principles aim to minimize vulnerabilities and prevent misuse or attacks.
π Think of them as the best practices for designing secure systems.
π§± Key Security Design Principles
πΉ 1. Principle of Least Privilege
- A user or program should have only the minimum privileges necessary to perform its function.
β Reduces potential damage from a compromised account or process.
πΉ 2. Principle of Fail-Safe Defaults
- Access should be denied by default, and only explicitly granted when necessary.
β Prevents accidental access due to misconfiguration.
πΉ 3. Principle of Economy of Mechanism
- Security mechanisms should be simple and small.
β Easier to analyze, test, and maintain β Complex systems are harder to secure
πΉ 4. Principle of Complete Mediation
- Every access to every object (file, memory, etc.) must be checked for proper authorization.
β Prevents caching of permissions that might change later.
πΉ 5. Principle of Open Design
- The system's security should not depend on secrecy of its design, only on secrecy of keys or passwords.
β Promotes transparency, public testing, and trust β Obscurity β security
πΉ 6. Principle of Separation of Privilege
- System should require multiple conditions to be met before access is granted (e.g., two-factor authentication).
β Adds an extra layer of security
πΉ 7. Principle of Least Common Mechanism
- Minimize sharing of mechanisms used by multiple users.
β Reduces chance of information leakage or side-channel attacks
πΉ 8. Principle of Psychological Acceptability
- Security mechanisms should be easy to use and understand by users.
β Encourages users to follow security rules β If too complex, users may bypass or ignore them
π Summary Table
| Principle | Key Idea |
|---|---|
| Least Privilege | Minimal required access |
| Fail-Safe Defaults | Deny by default |
| Economy of Mechanism | Keep it simple |
| Complete Mediation | Check every access |
| Open Design | Security β secrecy of design |
| Separation of Privilege | Multiple checks for access |
| Least Common Mechanism | Reduce shared components |
| Psychological Acceptability | Easy and usable security |
β Why They Matter
Applying these principles:
- Reduces system vulnerabilities
- Improves user trust
- Builds a strong security foundation
π§© Topic: Authentication
π What is Authentication?
Authentication is the process of verifying the identity of a user, program, or device before granting access to system resources.
π It answers the question:
βWho are you?β
π― Goals of Authentication
- Ensure that only authorized users can access the system
- Protect against impersonation and unauthorized use
- Serve as the first line of defense in security
π§© Types of Authentication
1. Password-Based Authentication
- The most common method
- User provides a username and password
β Simple to implement β Weak against guessing, brute-force, and phishing
π Best Practice: Use strong, hashed, and salted passwords
2. Biometric Authentication
-
Uses physical or behavioral traits of the user:
-
Fingerprint
- Facial recognition
- Iris scan
- Voice recognition
β Difficult to forge β Can raise privacy concerns, needs specialized hardware
3. Token-Based Authentication
- Uses a hardware or software token that generates a one-time password (OTP)
β Common in Two-Factor Authentication (2FA) β Tokens can be lost or stolen
4. Certificate-Based Authentication
- Uses digital certificates issued by trusted Certificate Authorities (CAs)
β Secure for network and system authentication β Needs public key infrastructure (PKI) management
5. Multi-Factor Authentication (MFA)
-
Combines two or more methods from:
-
Something you know (password)
- Something you have (token)
- Something you are (biometrics)
β Strongest form of authentication β Requires more resources and user effort
π§± Authentication Process Flow
1. User requests access
2. System asks for credentials
3. User submits credentials
4. OS verifies them
5. If verified β grant access; else β deny
π§― Common Attacks on Authentication
| Attack Type | Description |
|---|---|
| Brute Force Attack | Trying many password combinations |
| Phishing | Trick users into revealing credentials |
| Keylogging | Capturing typed passwords |
| Replay Attack | Reusing captured credentials |
β Best Practices for Secure Authentication
- Use strong and complex passwords
- Implement account lockout after failed attempts
- Use MFA (Multi-Factor Authentication)
- Encrypt passwords with hashing (e.g., SHA-256 + salt)
- Use secure channels (HTTPS, SSH)
π Summary Table
| Method | Factor Used | Strength | Example |
|---|---|---|---|
| Password | Knowledge | WeakβModerate | Gmail login |
| Biometrics | Inherence (you are) | Strong | Fingerprint unlock |
| Token | Possession (you have) | Strong | OTP via SMS or app |
| Certificate | Possession + trust | Very Strong | SSL client cert login |
| MFA | Combination of above | Very Strong | Banking login with OTP |
π§© Topic: Authentication
π What is Authentication?
Authentication is the process of verifying the identity of a user, program, or device before granting access to system resources.
π It answers the question:
βWho are you?β
π― Goals of Authentication
- Ensure that only authorized users can access the system
- Protect against impersonation and unauthorized use
- Serve as the first line of defense in security
π§© Types of Authentication
1. Password-Based Authentication
- The most common method
- User provides a username and password
β Simple to implement β Weak against guessing, brute-force, and phishing
π Best Practice: Use strong, hashed, and salted passwords
2. Biometric Authentication
-
Uses physical or behavioral traits of the user:
-
Fingerprint
- Facial recognition
- Iris scan
- Voice recognition
β Difficult to forge β Can raise privacy concerns, needs specialized hardware
3. Token-Based Authentication
- Uses a hardware or software token that generates a one-time password (OTP)
β Common in Two-Factor Authentication (2FA) β Tokens can be lost or stolen
4. Certificate-Based Authentication
- Uses digital certificates issued by trusted Certificate Authorities (CAs)
β Secure for network and system authentication β Needs public key infrastructure (PKI) management
5. Multi-Factor Authentication (MFA)
-
Combines two or more methods from:
-
Something you know (password)
- Something you have (token)
- Something you are (biometrics)
β Strongest form of authentication β Requires more resources and user effort
π§± Authentication Process Flow
1. User requests access
2. System asks for credentials
3. User submits credentials
4. OS verifies them
5. If verified β grant access; else β deny
π§― Common Attacks on Authentication
| Attack Type | Description |
|---|---|
| Brute Force Attack | Trying many password combinations |
| Phishing | Trick users into revealing credentials |
| Keylogging | Capturing typed passwords |
| Replay Attack | Reusing captured credentials |
β Best Practices for Secure Authentication
- Use strong and complex passwords
- Implement account lockout after failed attempts
- Use MFA (Multi-Factor Authentication)
- Encrypt passwords with hashing (e.g., SHA-256 + salt)
- Use secure channels (HTTPS, SSH)
π Summary Table
| Method | Factor Used | Strength | Example |
|---|---|---|---|
| Password | Knowledge | WeakβModerate | Gmail login |
| Biometrics | Inherence (you are) | Strong | Fingerprint unlock |
| Token | Possession (you have) | Strong | OTP via SMS or app |
| Certificate | Possession + trust | Very Strong | SSL client cert login |
| MFA | Combination of above | Very Strong | Banking login with OTP |
π‘οΈ Topic: Protection Mechanism
π What is a Protection Mechanism?
Protection mechanisms in an operating system control how resources (files, memory, devices, CPU) are accessed by users and processes.
π It ensures that:
"Only authorized entities can perform allowed operations on protected resources."
π― Objectives of Protection:
- Prevent unauthorized access
- Isolate processes from one another
- Maintain data confidentiality and integrity
- Enforce system security policies
π§© Key Elements of Protection Mechanism
πΉ 1. Access Control
Controls who can access what, and in what way.
πΈ Access Rights:
- Read β View contents
- Write β Modify contents
- Execute β Run program
- Delete β Remove resource
πΈ User Categories:
- Owner (User)
- Group
- Others (World)
πΉ 2. Access Control Matrix
A conceptual model representing rights of each user over each object.
Example:
| File A | File B | Printer | |
|---|---|---|---|
| Alice | Read, Write | Read | None |
| Bob | None | Write | Use |
β Clearly defines who has what permissions β Can be large and inefficient for real systems
πΉ 3. Access Control List (ACL)
- Each object has a list of users and their permissions.
Example (for File A):
Alice: Read, Write
Bob: Read
β More scalable than access matrix β Checking access may be slow if the list is long
πΉ 4. Capability List
- Each user (or process) has a list of objects it can access and how.
Example (for Alice):
File A: Read, Write
Printer: None
β Easy to manage per user β More difficult to revoke access globally
πΉ 5. Domain-Based Protection
- Divide the system into domains (logical units with resources and permissions).
- A process runs in a domain and has rights specific to that domain.
β Useful for role-based access β Supports dynamic switching between domains
πΉ 6. Protection Rings (in hardware)
- Protection is enforced at hardware level using rings (privilege levels).
| Ring | Level | Description |
|---|---|---|
| 0 | Highest | Kernel (OS code) |
| 3 | Lowest | User applications |
β Prevents user programs from affecting kernel
πΉ 7. Password and Encryption
- Password: For user authentication
- Encryption: Protects data from being read by unauthorized users
β Summary Table
| Mechanism | Description |
|---|---|
| Access Control Matrix | Table defining user access to objects |
| ACL (Access Control List) | Permissions stored per object |
| Capability List | Permissions stored per user/process |
| Domain Protection | Processes restricted to domain-based access |
| Hardware Protection | Privilege levels using rings |
| Encryption & Passwords | Protect against unauthorized data access |
π Example Scenario:
If Bob tries to write to File A:
- OS checks ACL or capability list
- If βWriteβ permission not found β Access Denied
π§© Topic: Security in Distributed Environment
π What is a Distributed Environment?
A distributed system consists of multiple computers or nodes communicating over a network to achieve a common goal. Examples: Cloud systems, web apps, shared file systems, microservices.
π Why is Security Crucial in Distributed Systems?
Unlike single-computer systems, distributed systems involve:
- Multiple users, locations, and devices
- Open networks, increasing vulnerability
- Shared resources, making access control complex
π Therefore, ensuring secure communication, authentication, and resource protection becomes critical.
π§± Major Security Challenges in Distributed Environments
| Challenge | Description |
|---|---|
| Authentication | Verifying identities across different nodes/systems |
| Authorization | Controlling what authenticated users can do |
| Data Integrity | Preventing unauthorized data modification |
| Confidentiality | Protecting data from unauthorized access |
| Availability | Ensuring services are always accessible |
| Trust Management | Establishing and managing trust between systems |
π Security Techniques Used
1. Authentication Mechanisms
| Method | Description |
|---|---|
| Passwords | Basic method, prone to attack |
| Public Key Infrastructure (PKI) | Uses digital certificates and keys |
| Kerberos | Uses tickets and secret keys for secure authentication |
| Biometrics/2FA | Used in higher security layers |
2. Encryption
- Symmetric Encryption (e.g., AES): Same key for encryption/decryption
- Asymmetric Encryption (e.g., RSA): Public and private keys
- TLS/SSL: Secure communication over HTTP
π Protects data in transit and at rest
3. Digital Signatures & Certificates
- Verifies data origin and integrity
- Uses hash functions and public key cryptography
4. Firewalls & Intrusion Detection Systems (IDS)
- Firewalls: Block unauthorized traffic
- IDS: Detect suspicious behavior or patterns
5. Access Control Policies
| Type | Description |
|---|---|
| Discretionary Access Control (DAC) | Owner sets access permissions |
| Mandatory Access Control (MAC) | Access decided by system labels |
| Role-Based Access Control (RBAC) | Based on userβs job role |
6. Secure Naming and Address Resolution
- Use trusted DNS services and DNSSEC to prevent DNS spoofing
- Secure mapping of service names to IP addresses
7. Auditing and Logging
- Track user activity and system events
- Helps in forensics and attack detection
π§― Common Attacks in Distributed Systems
| Attack Type | Description |
|---|---|
| Eavesdropping | Intercepting communication |
| Man-in-the-Middle (MitM) | Attacker alters messages between systems |
| Replay Attacks | Reusing valid credentials to impersonate users |
| Denial of Service (DoS) | Flooding systems to make services unavailable |
| Spoofing | Forging identity (IP, DNS, etc.) |
β Summary Table
| Security Goal | How It's Achieved |
|---|---|
| Authentication | Passwords, PKI, Kerberos |
| Authorization | ACLs, RBAC, MAC |
| Confidentiality | Encryption (TLS, VPN) |
| Integrity | Digital signatures, hashing |
| Availability | DoS protection, redundancy, failover systems |
| Auditing | Logs, intrusion detection systems |
π§ Key Takeaway:
Security in distributed systems must be layered, trust-aware, and adaptable to account for network vulnerabilities, remote users, and data sharing.