Skip to content
Tutorials Center
My learning

Topics

Lesson 56 of 66 ยท Protection, Security and Virtualization

Protection, Domains and Access Control

Learn how an operating system enforces protection with dual-mode operation, protection domains, the access matrix, ACLs, capabilities, least privilege and RBAC, with a Python access-matrix model.

A modern computer runs programs from many users and from sources nobody fully trusts. A buggy editor must not corrupt the kernel, one user must not read another user's mail, and a web page script must not touch your files. Protection is the set of mechanisms inside the operating system that controls which processes may access which resources, and in what way. (Security, the next lesson, is the wider question of defending against deliberate attackers, inside and outside the system.)

A useful way to remember the split: protection is about mechanisms (how do we enforce access rules?) and policy (what do we decide the rules to be?). A good OS provides flexible mechanisms and lets administrators choose policy.

Hardware foundations

Software alone cannot protect the kernel from software. The CPU helps:

  • Dual-mode (user/kernel) operation. A mode bit distinguishes privileged execution from ordinary programs. Privileged instructions, such as I/O, changing page tables and halting the CPU, trap if run in user mode. A user program enters the kernel only by a system call, which jumps to a fixed, kernel-chosen address.
  • Memory protection. The MMU (see paging) gives every process its own address space and marks pages as read, write or execute. Touching memory you do not own raises a fault and the OS ends the process.
  • CPU protection. A timer interrupt guarantees the OS regains control, so no process can hold the CPU forever.

Rings go further on some architectures: x86 has four privilege levels (ring 0 for the kernel, ring 3 for applications), and ARM has exception levels.

Principle of least privilege

Give each program, user or module only the rights it needs for its current task, and no more. A web server needs to read its site files, not the password database. A PDF viewer does not need network access. When something goes wrong, least privilege limits the damage. Closely related principles:

  • Need to know: reveal only the information required for the job.
  • Separation of duties: do not give one person or process all the powers for a sensitive action.
  • Fail-safe defaults: deny unless explicitly allowed.
  • Complete mediation: check every access, every time.

Protection domains

A domain is a set of access rights, each a pair (object, operations): for example (file F, {read, write}). A process runs inside one domain at a time and can do whatever that domain permits. A domain can correspond to:

  • a user (everything that user may do),
  • a process (rights that a process holds),
  • a procedure (a function with special access, such as an entry point into the kernel).

Domains may be static (fixed for the lifetime of the process) or dynamic (the process switches domain, for example when it makes a system call or runs a setuid program that temporarily takes the owner's rights).

The access matrix

The conceptual model of protection is a table: rows are domains, columns are objects, and each cell lists the operations that domain may perform on that object.

Domain File1 File2 Printer Domain 2
D1 read switch
D2 read, write print
D3 read, execute read

The matrix is huge and mostly empty, so nobody stores it as a table. Instead, systems store it by column or by row:

  1. Access control list (ACL): by column. Each object keeps a list of who may do what. File1: D1:read; D3:read,execute. Easy to see "who can touch this file?" and to revoke access to it. Used by file permissions (Unix mode bits are a tiny ACL, getfacl shows extended ones) and Windows NTFS.
  2. Capability list: by row. Each domain holds unforgeable tokens, capabilities, naming an object and its rights. Holding the token is the proof of access. Easy to see "what can this process do?" and to pass rights along, but hard to revoke. File descriptors are capabilities: once you have an open descriptor you can use it without another permission check.
flowchart LR
    M["Access matrix<br/>(domains x objects)"] --> A["Column view:<br/>ACL stored with each object"]
    M --> C["Row view:<br/>capabilities held by each domain"]
    A --> U["Unix permissions,<br/>NTFS ACLs"]
    C --> F["File descriptors,<br/>Fuchsia/seL4 handles"]

The same policy can be stored two ways: by what each object allows, or by what each process holds.

Python An access matrix: ACLs versus capabilities

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Revoking with an ACL is one edit at the object. With capabilities, copies may already sit in other processes, so systems add an indirection (a revocable proxy) or an expiry time.

Unix permissions and extended ACLs

Unix is the best-known ACL-based system: each file has an owner, a group and nine bits (rwx for owner, group, others). Decoding them was covered in the Unix file system lesson. Extended POSIX ACLs let you name additional users and groups for one file. Windows uses access control entries (ACEs) with allow/deny rules and inheritance from parent folders. Linux capabilities split root's power into pieces (CAP_NET_BIND_SERVICE to bind port 80, CAP_SYS_TIME to set the clock) so a program can have one privilege without being all-powerful.

Role-based access control (RBAC)

Assigning rights user by user does not scale. In RBAC, rights belong to roles such as accountant, admin or student, and users are assigned roles. When someone changes jobs, you change their roles, not hundreds of individual permissions.

Python Role-based access control

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Mandatory versus discretionary control

  • Discretionary access control (DAC): the owner decides who may access an object. Unix permissions and most desktop systems work this way. Flexible but fragile: a user (or malware running as that user) can hand out access.
  • Mandatory access control (MAC): the system enforces central rules that owners cannot override, often with labels such as "secret" and "public". SELinux and AppArmor on Linux and the sandboxes on Android and iOS apply MAC to confine even a compromised program that runs as root.

Language-based protection

Compilers and runtimes can enforce protection too. Java and Rust reject programs that access memory they should not, and the JVM's older security manager checked code permissions at run time. Language safety removes whole classes of attacks such as the buffer overflow in the next lesson.

Check your understanding

Quick check ยท 5 questions

of 5 answered You scored / 5 ยท perfect!

  1. 1. Why is the mode bit (user/kernel) important for protection?

    Privileged instructions trap when run in user mode, so applications cannot disable protection or touch devices directly.
  2. 2. Which is stored per object, listing who may do what?

    An ACL is the column of the access matrix: one list attached to each object.
  3. 3. Which structure makes revoking access to a single file easiest?

    With an ACL you edit the file's list. Capabilities may already be copied into many processes.
  4. 4. What does the principle of least privilege say?

    Limiting rights limits the damage a bug or attacker can do.
  5. 5. What is the main advantage of RBAC?

    Roles group permissions, which makes large systems manageable and auditable.

Summary

  • Protection uses hardware support (dual mode, memory protection, timers) plus OS policy to control access to resources.
  • Least privilege, fail-safe defaults and complete mediation guide design.
  • Domains hold access rights; the access matrix is stored as ACLs (by object) or capabilities (by domain).
  • Unix permissions are a compact ACL; Linux capabilities, SELinux and sandboxes provide finer and mandatory control; RBAC groups permissions into roles.

Next: Security Threats and Defenses