Unix Access Control: Inodes, Permissions, and setuid

A practical guide to access matrices, Unix filesystem objects and permissions, process identity, setuid behavior, and the design of complete access-control systems.

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.

SubjectActive entity requests an operation.
Reference monitorIntercepts and checks the request.
PolicyStates whether the right is present.
ObjectReceives only an allowed operation.

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.



Choose a row and column, then look up the cell.

Users, principals, and subjects

Human userThe real-world person.
AuthenticationMaps the person to an account.
PrincipalThe account that receives rights.
SubjectThe process acting for that principal.

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.

report.txt → inode 42 → blocks 120, 121

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
pointers
120, 121

3. Data blocks

The pointers locate contents on storage.

block 120 · first bytes
block 121 · remaining bytes

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/f3 needs x on d1 and d2, then r on f3.
  • Writing that file changes its contents, so it needs path traversal plus w on the file.
  • Deleting it changes the parent directory entry, so it normally needs w+x on d2, not permission on f3.
  • Renaming within one directory likewise changes directory entries.

Common surprise: directory r lets you list names, while directory x lets 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 a say “Permission denied”?
The -a, -s, and -l options change the requested output, not the caller’s permissions. If a is a directory, ls needs directory r to enumerate its names and directory x to search those names and obtain each entry’s metadata. Without applicable x, a long listing may show names but fail to inspect entries, producing “Permission denied” or question marks.

  • The special s bit does not independently grant read, write, or traversal.
  • Lowercase s includes x, 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 s does 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




RUID500
EUID500
Saved UID500

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.

  1. Objects: What resources need protection, and how are they organized?
  2. Subjects and principals: Who requests access, and on whose behalf?
  3. Human mapping: How are people authenticated and made accountable?
  4. Operations: Which rights can subjects exercise on each object?
  5. Policy storage: Where are permissions recorded, and who may update them?
  6. Mediation: Where is each request intercepted, and are all paths covered?
  7. 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, and x their regular-file meanings.
  • Assuming permission on a file controls deletion of its directory entry.
  • Combining owner, group, and other permission classes.
  • Assuming s is an extra access right; it marks setuid/setgid and occupies an execute position.
  • Forgetting that lowercase s includes execute/search while uppercase S does 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.

1. In an access matrix, what does one cell represent?



2. What does directory execute permission provide?



3. What normally controls deletion of /d1/f?



4. User 500 executes a root-owned setuid program. What are the IDs immediately after exec?



5. A maintenance interface reaches an object without the normal policy check. What failed?





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.