A privileged document converter receives an input descriptor and a caller-supplied output pathname. It also needs write access to /var/lib/converter/accounting. A malicious caller chooses that accounting pathname as the output. The converter faithfully opens the requested name with its own authority and overwrites the file it was supposed to protect.
No memory-safety violation is required. Authentication succeeded, permissions behaved as configured, and the converter performed a permitted write. The failure is authority confusion: the converter could not tell whether a write request exercised authority delegated by the caller or ambient authority held for its own bookkeeping.
Name the actors and the authority
Protection answers whether a subject may perform an operation on an object in a state. The vocabulary must remain separate:
| term | precise role | example |
|---|---|---|
| principal | entity to which accountability or policy attaches | user, service identity, tenant |
| subject | active execution context acting for one or more principals | process, thread, protection domain |
| object | protected resource with stable identity | inode, endpoint, address space, device |
| operation | requested state transition or observation | read, map, signal, send, delegate |
| permission | policy relation allowing one operation | read on object 17 |
| authority | usable power to affect an object, including powers obtained by delegation | descriptor granting write to object 17 |
| credential | evidence used to establish a principal or attributes | UID, signed token, certificate |
Authentication establishes or supports a claim about a principal. Authorization decides whether the acting subject has the required authority. Auditing records a decision or action. None substitutes for the others.
For subjects objects and operation set an access matrix is
is the set of operations subject may invoke on object The matrix is a specification, not usually a dense implementation. An access-control list stores a column by object: which subjects have which rights. A capability list stores a row by subject: which object references and rights the subject possesses.
Object capability. An unforgeable reference that designates an object and carries authority to invoke a bounded set of operations on it. Possession supplies both designation and authorization.
Unforgeability can come from kernel-managed table entries, tagged hardware, cryptographic construction under a stated threat model, or another protected representation. A pathname string is not an object capability: it is forgeable data requiring a fresh namespace lookup and separate authorization.
Worked representation: one matrix, two indexes
Suppose:
| subject / object | upload U | cache directory C | audit endpoint L |
|---|---|---|---|
| parser P | read | — | send |
| renderer R | read | create | send |
| janitor J | — | list, remove | — |
Object C’s ACL is {R:create, J:list+remove}. R’s capability list is {U:read, C:create, L:send}. Both encode cells from the same abstract matrix, but their engineering costs differ:
- answering “who can remove from C?” is local in C’s ACL;
- handing R attenuated
createauthority to one worker is local with a delegable capability; - revoking all access to C is direct at a central ACL check;
- revoking one copied capability requires indirection, versioning, a revocation tree, object destruction, or another explicit mechanism.
The words ACL and capability do not decide policy quality. A capability carrying broad directory mutation can exceed least authority; an ACL can be narrowly scoped and completely mediated.
Retrieval checkpoint: designation versus authorization
Why can open("/tenant/report", O_WRONLY) be vulnerable even when every pathname component passes a permission check?
Reveal the missing distinctionExpandCollapse
The caller supplied a designation—a string interpreted in a mutable namespace. Permission checks answer whether the converter’s subject may traverse and write the object that the string resolves to. They do not establish that the caller was authorized to choose that object for this operation. A confused deputy exploits the converter’s broader authority. A sound protocol must bind caller-conferred authority to the designated object, for example by accepting an already opened descriptor with bounded rights or resolving beneath a directory capability supplied for this request.
Access control matrices, capabilities, and confused deputies
Evaluate each statement regarding access control models, capabilities, and system authority:
Classify each option as correct or incorrect, or leave uncertain options unanswered (“I don't know”) and verify at any time.
Derive the reference monitor obligations
A protection decision is trustworthy only if every relevant access path passes through a mechanism that policy controls.
Reference monitor obligations and failure modes:
| Obligation | Architectural implementation mechanism | Concrete failure mode when violated |
|---|---|---|
| Complete mediation | Hardware MMU checks every memory access; syscall trap checks all requests | Peripheral DMA bypasses CPU MMU; or stale cached capability permits revoked access |
| Tamper resistance | Hardware privilege rings (U-mode vs S-mode); kernel memory protected | Stack buffer overflow overwrites kernel PC; or writable mapping aliases page table |
| Verifiability | Minimal trusted computing base with formalized state invariants | Tens of millions of lines in a monolithic kernel preclude formal correctness proofs |
Complete mediation does not require a slow policy database lookup on every byte. A successful open can create a kernel-protected descriptor that embodies the authorized object and access mode; subsequent read operations mediate possession and rights of that descriptor. The cached decision is valid only while the policy contract permits it. Revocation semantics must say whether existing descriptors continue working.
Saltzer and Schroeder’s related design principles sharpen the mechanism:
- fail-safe defaults: authority is absent unless granted;
- least privilege/least authority: a subject receives only powers needed for the current task and duration;
- least common mechanism: minimize shared mechanism on which mutually distrusting subjects depend;
- separation of privilege: require independent conditions when one condition is too dangerous; and
- economy of mechanism/open design: make the trusted mechanism analyzable rather than relying on design secrecy.
These are design tests, not slogans. “Use least privilege” is incomplete until the object set, operations, duration, delegation, and failure state are enumerated.
Worked exploit: the pathname deputy
The converter runs with write authority to:
/var/lib/converter/accounting
/srv/jobs/<tenant-output>
Its API is convert(input_fd, output_path). It validates document syntax, then opens output_path itself. The attack trace is:
| step | subject and authority | transition |
|---|---|---|
| 1 | caller controls string but cannot write accounting | passes /var/lib/converter/accounting |
| 2 | converter has ambient write authority | resolves string under converter credentials |
| 3 | kernel authorizes converter | returns writable descriptor to accounting object |
| 4 | converter writes output | accounting object is corrupted |
The permission system did exactly what its input requested. The API discarded provenance: it could not express “use only write authority delegated by this caller for this job.”
Repair A: descriptor-oriented delegation
An authorized broker opens the output under the tenant’s approved directory, verifies object type, and passes the descriptor to a worker. The worker receives input-read, output-write, and bounded audit-send authority. It never receives a pathname-based ability to open arbitrary files.
The API becomes conceptually convert(input_fd, output_fd, audit_endpoint). The worker can corrupt the designated output if its conversion logic is faulty; it cannot select accounting unless the broker delegated that object.
Repair B: attenuated directory authority
If the worker must create a name, give it a descriptor for one tenant directory and use relative, confinement-aware resolution. Restrict mutation operations, final-component policy, symbolic links, and mount crossings according to the service contract. On capability systems, derive a child capability with reduced rights; on POSIX-like systems, compose directory descriptors, process credentials, namespaces, and kernel resolution controls.
Neither repair proves content safety, kernel correctness, or durability. It removes a specific authority path.
Application checkpoint: verify least authority
The worker needs to read one input, create one output in a tenant directory, and emit one audit record. It receives a read-write descriptor for the entire tenant root and a network socket able to contact any address. Identify excess authority and propose an attenuated set.
Reveal the authority deltaExpandCollapse
Excess powers include reading or overwriting unrelated tenant objects, traversing subdirectories, deleting or renaming names if the descriptor and APIs permit it, and sending arbitrary network traffic. A narrower set is: an input descriptor with read-only access; either an already opened output descriptor with write-only/truncate semantics or a create-only authority scoped to one directory and validated name; and a connected or brokered audit endpoint that accepts only the expected message form. Close or revoke each after the conversion.
The answer must discuss operations as well as object scope. Replacing “tenant root” with “tenant output directory” while retaining remove, rename, and read authority may still exceed the task.
Delegation, attenuation, and revocation
Capabilities make delegation explicit: subject A transfers or derives a reference for B. Safe derivation is monotonic attenuation—the child authority is no greater than the parent in object scope, operation set, or an enforced constraint such as time or quota.
Let a capability be modeled as where is an object, rights, and an optional guard. A derived capability is attenuated only if the kernel-enforced meaning satisfies
Matching object identifiers and checking is insufficient if a new guard broadens name resolution or if the derived reference reaches an alias outside the parent’s object scope.
Revocation is not automatic:
- an ACL check can reject future opens after an entry is removed, while already open descriptors may remain valid by policy;
- a direct object capability copied to many subjects may require deleting the object, traversing a derivation tree, or routing through a revocable proxy;
- time-limited signed capabilities rely on clock and key assumptions; and
- revocation that races an in-flight operation needs a defined linearization point.
Worked trace: delegated read with revocation proxy
Subject A owns object X and creates proxy P. B receives capability read(P), while P holds read(X).
- Before revocation, B invokes P; P checks its live state and forwards read to X.
- A marks P revoked under P’s lock.
- A later read beginning after that transition is rejected.
- A read already forwarded to X may complete unless the contract includes cancellation.
The proxy adds an indirection and a failure/availability dependency. It supplies a crisp future-use revocation point that an unmediated copied capability lacks. Destroying X revokes more broadly but may violate other clients’ availability.
Transfer checkpoint: choose the revocation contract
A signing service delegates “sign at most ten artifacts before 18:00” to a build worker. List the kernel or trusted-service state required to enforce both constraints, and explain why a bearer token containing those words is insufficient by itself.
Reveal the enforcement obligationsExpandCollapse
The operation count needs non-forgeable, race-free mutable state shared by all copies or a trusted online mediator that decrements a counter atomically. The deadline needs a trusted clock and a policy for clock rollback and in-flight operations. The object and key must remain bound to the authority; the worker must not possess an unrestricted signing-key copy. A bearer token is only serialized policy input until a trusted component verifies it and controls every signing path. Copying a ten-use token to two workers must not create twenty uses.
ACLs and capabilities fail in different ways
Consider an object store with one million objects and short-lived workers:
| question | ACL-centered pressure | capability-centered pressure |
|---|---|---|
| enumerate all users of one object | local to object policy | may require tracking distributed copies |
| delegate one object to a worker | update policy or mint scoped credential | transfer/derive object reference |
| revoke all future access | update central policy | revoke proxy/version/object or derivation subtree |
| avoid ambient object naming | naming and authorization remain separable | designation and authority can be one reference |
| audit principal intent | identity policy is direct | possession may need explicit principal/audit binding |
A system can combine them. The relevant review question is which component mediates which path and what state survives delegation, caching, process creation, and revocation.
Linux capabilities are not object capabilities
Linux divides powers traditionally associated with superuser into per-thread capability units such as CAP_CHOWN or CAP_NET_ADMIN. Permitted, effective, inheritable, ambient, and bounding sets govern their availability across operations and execve under detailed rules.
Despite the name, CAP_DAC_OVERRIDE is not an unforgeable reference to one file. It is broad privilege to bypass a class of discretionary access checks within the relevant namespace context. Granting it may increase ambient authority over many objects. By contrast, a descriptor opened to one file is closer to an object-specific capability: it designates one kernel object and carries bounded access mode, though surrounding APIs, ioctls, delegation, and revocation semantics still require review.
Similarly, a UID is a credential attribute, not a reference to every object that policy might allow that UID to access. “Use capabilities” is ambiguous until the mechanism is named.
Boundary checkpoint: seccomp and authority
A worker may call only read, write, close, and exit under a system-call filter. It inherits a writable descriptor for the host’s audit database. Is it least-authority with respect to that database?
Reveal the counterexampleExpandCollapse
No. write remains permitted and the inherited descriptor designates the database with write authority. Reducing syscall surface does not attenuate the descriptor. The worker needs the descriptor closed or replaced with a narrower endpoint. Conversely, closing the descriptor does not eliminate every kernel attack path; syscall filtering and object authority address different dimensions.
Deep Practice
Solve these problems to test and consolidate your understanding. Complete worked solutions and diagnostic hints are available for each problem.
Exercise 7.1.1: Access Matrix Row and Column Duality for ACLs and Capabilities
An access matrix defines permissions for three subjects across three objects
- Write the Access Control Lists (ACLs) associated with objects
- Write the Capability Lists associated with subjects
- Explain which representation is more efficient when revoking all access to versus revoking all access held by
HintExpandCollapse
ACLs partition matrix A by columns; capability lists partition matrix A by rows.
Worked solutionExpandCollapse
- Access Control Lists (Columns of
- Capability Lists (Rows of
- Revocation efficiency:
- Revoking all access to object Trivial with ACLs: the kernel modifies the single entry directly at the object. With capabilities, finding all references to requires traversing the capability lists of all subjects in the system (unless indirect capability indirection or generation counts are maintained).
- Revoking all access held by subject Trivial with capabilities: destroying ‘s capability list revokes all its access in one step. With ACLs, the kernel must scan every object’s ACL in the entire filesystem to purge entries naming
Exercise 7.1.2: Tracing and Repairing a Confused-Deputy Attack Scenario
A compiler daemon runs as root (uid 0) to compile user programs and write billing metrics to /var/log/billing.log. The user invokes the compiler with: compile --src main.c --out /var/log/billing.log.
- Trace how the compiler becomes a confused deputy and overwrites the billing log.
- Explain why checking the caller’s permissions via
access(out_path, W_OK)before opening fails to solve the architectural problem. - Formulate the capability-based architectural repair that eliminates the vulnerability.
HintExpandCollapse
The deputy combines client-chosen designation with server ambient authority. Pass an open descriptor instead.
Worked solutionExpandCollapse
- Exploitation trace:
- User inputs destination path
/var/log/billing.log. - The compiler exercises its ambient
rootauthority and callsopen("/var/log/billing.log", O_WRONLY | O_CREAT | O_TRUNC). - Because
rootpossesses write authority over/var/log, the open succeeds. - The compiler writes compiled machine code over the billing log, destroying audit history. The compiler was confused: it used its own ambient authority to access an object designated by an untrusted client.
- User inputs destination path
- Failure of
access()check:- First,
access()creates a time-of-check to time-of-use (TOCTOU) race condition: an attacker can replace the path with a symlink betweenaccess()andopen(). - Second, it relies on global ambient path lookup rather than conferring explicit authority.
- First,
- Capability-based repair:
The client must open the destination file in its own user context and pass the resulting open file descriptor to the compiler service over a Unix domain socket (
SCM_RIGHTS). The compiler writes exclusively through the provided descriptor. If an unprivileged user specifies/var/log/billing.log, the user’s initialopen()fails withEACCESbefore the compiler is ever invoked. Designation and authority are bundled into an unforgeable descriptor.
Exercise 7.1.3: Eliminating Time-of-Check to Time-of-Use (TOCTOU) Races via openat
A setuid-root program verifies that a target file in /tmp/scratch belongs to the user before writing to it:
struct stat st;
stat("/tmp/scratch/file", &st);
if (st.st_uid == getuid()) {
// [ATTACK WINDOW]
int fd = open("/tmp/scratch/file", O_WRONLY);
write(fd, payload, size);
}- Construct the concurrent race schedule whereby an attacker replaces
/tmp/scratch/filewith a symlink to/etc/shadowto overwrite password hashes. - Rewrite the code using
open()flags (O_NOFOLLOW) orfstat()on an opened descriptor to completely eliminate the TOCTOU race.
HintExpandCollapse
fstat on the opened descriptor inspects the exact inode that was opened; O_NOFOLLOW refuses symlinks.
Worked solutionExpandCollapse
- Attack schedule:
- Attacker creates regular file
/tmp/scratch/fileowned by their user UID. - Setuid-root process calls
stat("/tmp/scratch/file", &st). The checkst.st_uid == getuid()passes. - In the attack window before
open(), attacker executes:unlink("/tmp/scratch/file"); symlink("/etc/shadow", "/tmp/scratch/file"); - Setuid-root process resumes and calls
open("/tmp/scratch/file", O_WRONLY). The kernel resolves the symlink and opens/etc/shadowwith root privileges. - Setuid-root writes user payload into
/etc/shadow, corrupting system credentials.
- Attacker creates regular file
- Race-free repair:
Open the file first without following symlinks and inspect the resulting descriptor directly:
int fd = open("/tmp/scratch/file", O_WRONLY | O_NOFOLLOW); if (fd < 0) return -1; struct stat st; if (fstat(fd, &st) < 0 || st.st_uid != getuid() || !S_ISREG(st.st_mode)) { close(fd); return -1; } write(fd, payload, size); close(fd);fstat(fd, ...)inspects the identical in-memory inode that was opened. Any subsequent rename or symlink modification in/tmphas zero effect on the already opened file description.
Exercise 7.1.4: Contrasting Linux Thread Privileges with Fine-Grained Object Capabilities
Contrast Linux thread capability bits (CAP_SYS_ADMIN, CAP_NET_RAW, CAP_DAC_OVERRIDE) with object-capability systems (such as Capsicum or seL4). Explain why granting CAP_DAC_OVERRIDE to a service increases ambient authority rather than enforcing least authority.
HintExpandCollapse
Linux capabilities are coarse privilege flags; object capabilities are unforgeable handles to specific resources.
Worked solutionExpandCollapse
- Architectural distinction:
- Linux capabilities (
capabilities(7)): Partition the monolithicrootUID into approximately 40 coarse-grained privilege categories associated with a thread credential. They act as global permission flags checked by the kernel when an unprivileged operation is attempted. - Object capabilities (Capsicum / seL4): Unforgeable, fine-grained references that pair the identity of a specific resource (e.g., file descriptor 4, endpoint
0x10A) with a restricted bitmask of allowed methods (CAP_READ,CAP_SEEK). A thread can invoke operations only on resources for which it holds an explicit capability.
- Linux capabilities (
- Ambient authority hazard of
CAP_DAC_OVERRIDE:CAP_DAC_OVERRIDEinstructs the VFS to bypass all discretionary file read, write, and execute permission checks across the entire filesystem hierarchy. GrantingCAP_DAC_OVERRIDEto a service that needs to modify a single configuration file does not restrict it to that file; it grants the ambient power to read or overwrite every file, shadow password, and device node on the system. It maximizes ambient authority rather than enforcing least authority.
References & Further Reading
- Saltzer and Schroeder, “The Protection of Information in Computer Systems” (1975) — primary statement of design principles and protection mechanisms.
- Norman Hardy, “The Confused Deputy (or why capabilities might have been invented)” — primary confused-deputy formulation and capability-oriented diagnosis.
- Dennis and Van Horn, “Programming Semantics for Multiprogrammed Computations” (MIT-LCS-TR-023) — primary capability-oriented protection model.
- Watson et al., “Capsicum: Practical Capabilities for UNIX” — object-capability application compartmentalization on a UNIX interface.
- seL4 Reference Manual and capability tutorial — kernel-object capability semantics and rights.
- Linux kernel documentation, Credentials in Linux — task, file, UID/GID, key, and capability credential structures.
- Linux man-pages,
capabilities(7)— Linux privilege-unit semantics and capability sets. - Linux man-pages,
openat2(2)— resolution controls relevant to descriptor-relative confinement.