decisions DECIDED

13. Capability revocation and untyped reclamation (frames)

Decided and built 2026-07-22 (milestone 13). The direction was parked in "Open design ideas" and notes/capability-lifecycle.md. The concrete mechanism is designed here, because it is a capability-model change gated on a memory-safety precondition.

What it closes

A granted capability could not be retracted and a spent page could not be reclaimed. That was safe only by a structural accident: retyped frames are spend-only and never reused, so a peer that still mapped a shared frame after the granter left was mapping valid, non-reused memory. untyped::destroy carried a tripwire spelling this out: wiring up any reclamation before revocation exists turns those dangling mappings into a use-after-free.

The scope: frame revocation, not the full tree

seL4 keeps a capability-derivation tree and revokes a subtree (revoke Bob's copy while keeping Alice's and my own). We build the unmap side only and revoke all derivatives of a page, which is exactly what reclamation wants and is the memory-safety-critical half. The full tree buys subtree granularity, which nothing on the roadmap needs, so by ยง4 it waits for a driver. This is a considered terminal design, not a way-station. If subtree revoke is ever required, the machinery here (unmap-from-any-address-space, the revoke-before-reclaim discipline, untyped::destroy) is reused unchanged. Only the index (an object-to-holders list) is rebuilt as a tree. design/roadmap/0013-capability-revocation.md has the argument.

The mechanism

A mapping database, lite (revoke.rs): every mapping of an untyped-derived page, (phys, root, va), recorded at Untyped::MAP and Frame::MAP, and forgotten when an address space is torn down (so a stale root is never walked after its tables are freed and reused). To revoke a page:

Correction, 2026-08-05 (milestone 108). "Every mapping" was false as written, and had been since the Frame object existed. There are three routes into an address space and only two are recorded: Frame::MAP and Aspace::MAP_INTO both reach the database, while Spawn::maps does not, because AddressSpace::map_physical establishes the mapping and returns. A spawn-delivered page could not be revoked: Frame::REVOKE found no capability to delete and no record to unmap, and the mapping outlived the capability. That was true of every driver in the tree until milestone 108 migrated them to map their own pages. The mechanism below was never wrong; the population it covered was smaller than this sentence claimed. disk_tests::the_roster_can_be_revoked_out_from_under_its_holder now fails if the old shape returns.

  1. Delete every Frame capability to it from every cspace, so no Frame::MAP started afterward can re-establish a mapping.
  2. Unmap it from every address space that held it, with the broadcast TLB flush we already use, so SMP and the no-ASID case are covered.

There are two entry points. Frame::REVOKE is a method needing GRANT, the un-share trigger; it does not reclaim, since the untyped is spend-only. untyped::destroy is the reclaim trigger: revoke every mapped page in the region, then return the pages to the allocator. Reclamation is now safe because "no live mapping survives" replaces "spend-only, never reused".

Tests

revoke_unmaps_a_shared_page_from_every_address_space (a page mapped in two address spaces is unmapped from both), destroy_unmaps_a_region_before_reclaiming_it (the tripwire's use-after-free made impossible: the mapping is gone before the frame returns to the allocator), and, at EL0, a_process_revokes_a_frame_and_loses_the_capability.

Deferred, deliberately

The one honest race

A Frame::MAP in flight on another core, between a revoke's cap-delete and its unmap, can slip a mapping past the revoke. seL4 closes this with a mapping-database lock held across the whole operation. That lock is the deferred full-database machinery. Named, not hidden.