Section 1.40

Capability security

Definition

Capability security is a way of controlling access in which authority is carried by capabilities. A capability is an unforgeable reference that both names one object, such as a file, a memory region or a device, and grants a set of rights to it, such as read or write. A program can act on an object only by presenting a capability for it. It obtains capabilities only by creating objects or by receiving capabilities from their holders. The system checks what the requester holds, not who the requester is.

The idea

In most operating systems a program’s rights come from the user it runs as: a program running as Alice may open any file that Alice may open, simply by naming it. This is ambient authority: the program holds it all the time and uses it without saying which part it means to use. Ambient authority causes the confused deputy problem §1.25, which Norm Hardy described in 1988 [416]. A compiler service has permission to write a billing file. A user asks the compiler to write debugging output to a file the user names, and names the billing file. The compiler opens that file with its own permission and overwrites the bill. Every check passed; the compiler used authority it held for another purpose.

With capabilities, the user passes the compiler a capability for the output file instead of a name, and the user can hold that capability only if the user may write the file. The compiler writes through it and cannot reach the billing file with it. A house key is a fair picture: the lock opens for whoever holds the key and does not ask who the holder is. The picture stops at copying: anyone with the tools can copy a metal key, while a capability system controls copying and makes it impossible to build a capability from arbitrary bits.

How it works

Jack Dennis and Earl Van Horn introduced the term in 1966 [421]. A capability system needs four things.

  1. A name with rights. Each capability names one object and carries a set of rights, and often bounds, such as the first and last address of a memory region, and a lifetime.

  2. Unforgeability. Only the trusted part of the system, such as the kernel, the hardware or a reference monitor §1.17 (the component that checks every access), can create a capability.

  3. A check on every use. The trusted part confirms that the capability presented is still valid, names this object and includes this right.

  4. Controlled transfer. A holder can pass a capability over a channel it already holds, called delegation, or pass a weaker copy, such as a read-only one, called attenuation. No holder can add rights.

Three implementations are common.

Revocation, taking authority back, is the hard part, because holders may have passed copies on. Either the owner hands out a capability to a forwarder, an object that relays each use and that the owner can disable, which cuts off every copy at once; or each table entry and each capability carries a generation number that the system increases when it withdraws the authority, so that older capabilities stop matching.

Worked example

A guest program asks a host to read and write objects for it. Design 1: raw addresses. Object A is 64 bytes long and starts at address 0x20001000. Since 64 is 0x40 in hexadecimal, A ends at 0x2000103F.

Design 2: checked handles. The host keeps a protected table for this guest. Each entry holds an object, its length, its rights and a generation number, and the guest names an object by a handle, the pair (slot, generation). Slot 2 holds A, 64 bytes, read-only, generation 3, and the guest holds the handle (2, 3). Every request must pass four checks: the slot number lies inside the table and the slot is in use, the generations are equal, the right is included, and every byte accessed lies within the length, so the offset plus the access width is at most the length.

The generation needs enough bits. With 4 bits, slot 2’s number returns to 3 after 24=162^4 = 16 reuses, and the stale handle (2, 3) is accepted again for whatever object then occupies the slot. With 16 bits this takes 216=65,5362^{16} = 65{,}536 reuses. A design either makes counter wraparound §6.21 impossible within the life of any handle, or retires a slot before its generation wraps. The failure is a form of the ABA problem §9.25, named after a value that changes from A to B and back to A: an unchanged number is taken as proof that nothing changed.

Stated precisely

Access rights can be drawn as an access matrix: one row per subject (a program or process), one column per object, and in each cell the subject’s rights over the object. An access-control §1.7 list (ACL) stores the matrix by column: each object lists who may do what, and each access is checked against the requester’s identity. A capability system stores the matrix by row: each subject holds capabilities for the cells of its own row, and each access is checked against the capability presented.

Write a capability as a pair c=(o,R)c = (o, R), where oo is an object and RR is a set of rights. A capability system enforces three rules.

  1. Access only by capability. A subject ss performs operation op\mathrm{op} on object oo only if ss holds some c=(o,R)c = (o, R) with op∈R\mathrm{op} \in R.

  2. No forgery. The capabilities that ss holds grow in only three ways: ss starts with them, ss creates a new object and receives a capability for it, or a holder passes a capability to ss over a channel that both already hold.

  3. No amplification. A capability derived from (o,R)(o, R) has the form (o,R′)(o, R') with R′⊆RR' \subseteq R, where ⊆\subseteq means “is a subset of”.

A system with lifetimes adds a fourth rule, validity: once oo is destroyed or the capability revoked, every use of the capability fails and none reaches another object.

The rules rest on two assumptions. First, complete mediation §1.16: the trusted part sees every access, and no path bypasses it. Second, untrusted code cannot write the memory where capabilities are kept except through the trusted part, or, for cryptographic tokens, cannot guess or compute a valid token.

Limits and common mistakes

A capability limits who can use an object, not where information goes afterwards. A program that holds a read capability for a secret can copy the secret into any message it is able to send. Information-flow control §1.41 addresses that question.

Copying a transferable capability copies its authority, so a capability system confines a program only by controlling which channels the program holds.

Capabilities do not give least privilege §1.15 by themselves. A system that hands every program a capability for everything has capabilities and no restriction.

A capability is not secret by definition. In the table and hardware forms the system protects it, and another program that learns the index or the bits gains nothing. Only bearer tokens rely on secrecy.

Bounds alone give spatial memory safety §2.28: an access cannot run past its object. Temporal memory safety §2.29, no use of an object after it is freed, also needs lifetime information, such as generation numbers or revocation of every copy.

Questions answered

Why might an integer address be a poor capability?

An integer address is a poor capability because it names a location without establishing any authority: it is forgeable and carries no rights, no bounds and no lifetime. A capability is an unforgeable reference that names one object and grants specific rights to it. Against that standard, a raw address fails in five ways.

An integer can still serve as a handle if a trusted component resolves it in a protected table that belongs to the holder and checks rights, bounds and a generation number on every use, as a Unix kernel resolves a file descriptor in the process’s own table. The protection then comes from the table and the check, not from the integer.

Related entries: Least privilege (§1.15), Complete mediation (§1.16), Temporal memory safety (§2.29), Confused deputy (§1.25), Authorization (§1.7), Spatial memory safety (§2.28). Further reading: [156, 416, 421].