Contents
The core access-control model
Access control is a protection wall with a guarded gate. A subject cannot directly reach a resource; a reference monitor intercepts the request and checks the policy.
Subject
An active entity that requests access; in Unix, normally a process.
Object
An entity on which an operation is performed; often a file or directory.
Right
An allowed operation such as read, write, execute, delete, or signal.
Complete mediation: every access to every protected resource must pass through the check. An unguarded path defeats the model even if the main path is correct.
Access matrix
Rows represent subjects, columns represent objects, and each cell contains the rights that its row subject has over its column object.
| Subject ↓ / Object → | Report | Payroll | Backup process |
|---|---|---|---|
| Alice process | r,w,own | — | signal |
| Auditor process | r | r | — |
| Backup process | r | r | own |
Access-matrix lookup
Select a subject and object. The result is the contents of exactly one matrix cell.
Users, principals, and subjects
High-level policy is usually about people, but Unix grants rights to accounts and processes perform the accesses. The operating system therefore needs a reliable way to determine which principal a process represents.
- One human may have multiple principals, such as separate ordinary and administrative accounts.
- Each principal should map to one human so actions remain attributable.
- Unix identifies accounts with UIDs; UID 0 traditionally denotes the superuser.
- Groups let a policy name collections of principals more succinctly.
Objects in Unix
An object is anything on which a subject can perform a mediated operation. Files, directories, memory segments, and even processes can be objects.
Trace a filename through the filesystem
Choose a directory entry. Follow how Unix resolves its name to an inode, then follows the inode’s pointers to data blocks.
1. Directory /home/alice
Stores name → inode mappings.
2. Inode table
The inode stores metadata—not the filename.
- inode #
- 42
- type
- regular file
- owner
- alice
- mode
- -rw-r—–
- size
- 6,200 bytes
- links
- 2
- pointers
- 120, 121
3. Data blocks
The pointers locate contents on storage.
Notice: the directory stores the name, while inode 42 stores metadata and block pointers. Its link count is 2 because two directory names point to the same inode.
| Object | Example operations | Important policy location |
|---|---|---|
| Regular file | Read, write, execute | Owner, group, and permission bits in metadata |
| Directory | List names, look up names, create or remove entries | Directory permissions and special bits |
| Process | Signal, suspend, resume, communicate | Process credentials and kernel rules |
| System resource | Halt, mount, bind a privileged port | Traditionally restricted to root or finer-grained privileges |
Key distinction: a directory is not just a container. It is a file-like object that maps names to inode numbers, so its permission bits govern name lookup and entry modification.
Unix permission semantics
Unix first selects one permission class: owner if the effective identity matches the owner; otherwise group if the process belongs to the file’s group; otherwise other. It does not combine bits from several classes.
| Bit | Regular file | Directory |
|---|---|---|
r |
Read file contents. | List the names stored in the directory. |
w |
Change file contents. | Modify directory entries; normally paired with x for create/delete. |
x |
Execute the file as a program. | Traverse/search: look up a known name and continue through the path. |
Reason about the operation, not just the target
- Reading
/d1/d2/f3needsxond1andd2, thenronf3. - Writing that file changes its contents, so it needs path traversal plus
won the file. - Deleting it changes the parent directory entry, so it normally needs
w+xond2, not permission onf3. - Renaming within one directory likewise changes directory entries.
Common surprise: directory
rlets you list names, while directoryxlets you use a name you already know. Either permission can exist without the other.
The special permission bits
| Bit | Executable file | Directory |
|---|---|---|
| setuid | On execution, set EUID and saved UID to the file owner’s UID. | No relevant effect in this context. |
| setgid | On execution, set EGID and saved GID to the file’s group. | New files inherit the directory’s group. |
| sticky | No modern executable-file role here. | Restricts deletion so users cannot freely delete files owned by others. |
These bits modify normal behavior; they are not a fourth set of rwx rights. Their meaning also depends on whether the object is a file or directory.
Reading s and S in ls -l
ls -l displays setuid or setgid in the position normally used for x. The letter’s case tells you whether execute/search is also present.
| Example mode | Meaning |
|---|---|
-rwsr-xr-x |
Owner execute and setuid are both set, so lowercase s replaces the owner’s x. |
-rwSr-xr-x |
Setuid is set but owner execute is absent, so uppercase S appears. |
drwxr-s--- |
Group search/execute and setgid are both set. On a directory, new entries inherit its group. |
drwxr-S--- |
Setgid is set but group search/execute is absent. Group members cannot traverse the directory. |
Why can
ls -asl asay “Permission denied”?
The-a,-s, and-loptions change the requested output, not the caller’s permissions. Ifais a directory,lsneeds directoryrto enumerate its names and directoryxto search those names and obtain each entry’s metadata. Without applicablex, a long listing may show names but fail to inspect entries, producing “Permission denied” or question marks.
- The special
sbit does not independently grant read, write, or traversal. - Lowercase
sincludesx, but only for its displayed class: owner or group. - If the process is neither the owner nor a member of the directory’s group, the other bits apply; a group
sdoes not help. - Every parent directory in the pathname must also grant the applicable class
x.
Process identity and setuid
| Identity | Role |
|---|---|
| Real UID (RUID) | The original user identity—the owner of the process. |
| Effective UID (EUID) | The identity used in most access-control decisions. |
| Saved UID | A retained identity that can support temporary privilege changes. |
fork copies all three UIDs to the child. A normal exec replaces the program but preserves the UIDs. Executing a setuid file preserves RUID while changing EUID and saved UID to the file owner’s UID.
Trace the password-changing process
The ordinary shell acts entirely as user 500.
Why setuid programs are risky
Some tasks require authority not represented by ordinary file permissions—for example, changing protected account data in a controlled way. A setuid-root program can provide that controlled operation, but a bug may expose far more root authority than the task needs.
- Keep the privileged code path small.
- Validate all untrusted input before using privilege.
- Drop privilege as soon as the privileged operation is complete.
- Prefer permanent drops when the privilege will never be needed again.
Access-control design checklist
Use this sequence when analyzing a new system. A complete answer covers both policy and enforcement.
- Objects: What resources need protection, and how are they organized?
- Subjects and principals: Who requests access, and on whose behalf?
- Human mapping: How are people authenticated and made accountable?
- Operations: Which rights can subjects exercise on each object?
- Policy storage: Where are permissions recorded, and who may update them?
- Mediation: Where is each request intercepted, and are all paths covered?
- Residual threats: What assumptions or bypasses could still defeat protection?
Common pitfalls
- Confusing a human user, account/principal, and process/subject.
- Putting objects in matrix rows or subjects in columns.
- Thinking complete mediation means checking only the first access.
- Treating a filename as the file itself rather than a directory-to-inode mapping.
- Giving directory
r,w, andxtheir regular-file meanings. - Assuming permission on a file controls deletion of its directory entry.
- Combining owner, group, and other permission classes.
- Assuming
sis an extra access right; it marks setuid/setgid and occupies an execute position. - Forgetting that lowercase
sincludes execute/search while uppercaseSdoes not. - Saying RUID normally determines access; EUID usually does.
- Thinking a temporary privilege drop removes the privileged saved UID.
- Calling setuid itself safe or unsafe without examining the privileged code path.
Applied questions and scenarios
Select an answer for each question, then check the highlighted choices.
Worked scenarios
A directory grants an unrelated user --x. The user knows the name of a readable file inside. Can the user list the directory or read the file?
The user cannot list names without directory r. The user can traverse the directory using the known name and read the file if the file grants the applicable class r.
ls -ld a shows drwxr-S---. Why might a group member get “Permission denied” from ls -asl a?
The uppercase S means setgid is set but group execute/search is not. The member may be able to read directory names if group r applies, but cannot traverse those names to retrieve the long-listing metadata. Setgid affects group inheritance; it does not replace the missing search permission.
Why should one human be allowed several principals while each principal identifies one human?
Separate principals support roles and least privilege, while the unique reverse mapping preserves accountability for actions taken through each account.
A setuid-root tool temporarily changes EUID from 0 to 500 while saved UID remains 0. Has it permanently surrendered root?
No. The saved UID retains root identity, so the process may restore EUID 0. A permanent drop removes the privileged value from all relevant UID slots.