notes

Delegating a capability

For most of this project nife called itself a capability system while quietly not being one in the way that matters. Capabilities existed, rights existed, GRANT existed, and derive (copy a capability with narrowed rights) was written and unit-tested. But a running process could not use any of it. Every capability was minted by the kernel and placed in a process's table at spawn, and there was no operation for a process to hand a capability to another process. The kernel was a central authority-granting oracle. That is ambient authority wearing a capability costume: the thing §10 argued against, moved one layer down.

This note is the fix. A process can now delegate a capability to another process over an IPC endpoint, and that is the operation that makes the model composable by the processes themselves.

The shape: capabilities ride the same channels as messages

The delegation path reuses the endpoints we already had. Two new methods:

This is the seL4 model: capabilities move as part of IPC, not through a side channel. It fits what we already built, and it means the receiver never names a slot it doesn't own. The kernel picks the slot and tells the receiver where the capability went.

Two rights, two different questions

SEND_CAPABILITY checks two rights, and conflating them would be a bug:

And the rights the receiver ends up with must be a subset of what the sender holds. Delegation narrows, never widens. If it could widen, the model is theater: you would delegate yourself a better capability than the one you were given. The kernel rebuilds the requested rights from their bits, masks them to the defined set, and rejects anything that is not a subset. So a sender can drop GRANT on the way (hand over the use of a thing without the right to pass it on further), which is exactly what the demo does.

The mechanism, and where the capability actually moves

The transfer happens at the rendezvous, under the scheduler lock, because that is the one moment both processes' capability tables are reachable at once:

If the receiver's capability table is full the capability is dropped and the receiver sees NO_CAPABILITY; the data word still arrives. One honest wart: SEND_CAPABILITY and plain RECEIVE (or SEND and RECEIVE_CAPABILITY) share the same endpoint queues and do not check that both sides agree to carry a capability. A correct protocol uses the matching pair. Mixing them does not corrupt anything, it just delivers a capability nobody reads, or reports NO_CAPABILITY to someone who expected one.

What the test proves, and how it can fail

a_capability_can_be_delegated_over_ipc_and_grant_gates_re_delegation wires two user processes and checks the three things that have to hold:

  1. The receiver gets the capability. RECEIVE_CAPABILITY returns a real slot, not NO_CAPABILITY.
  2. The capability works when the receiver invokes it. The receiver SENDs a distinctive word on the delegated capability, and a RECEIVE on the other end collects it. A capability minted by one process carries real authority when invoked by another.
  3. GRANT gates re-delegation. The receiver was handed the capability narrowed to WRITE (no GRANT), so when it tries to SEND_CAPABILITY it onward, the kernel refuses before any rendezvous.

Verified it can fail: stub the GRANT check to accept, and claim 3 collapses. The receiver's re-delegation is now permitted, blocks forever on the empty rendezvous it tried to send over, and the whole test suite hangs. The gate is load-bearing, not decoration.

What this unlocks

Delegation is the prerequisite for the next simplification worth making: a PageFrame capability. Today every shared page (the console buffer, the DMA region) is mapped into both parties by the kernel at spawn. With delegation in place, a process can hold a PageFrame capability and pass it to whoever it wants to share memory with, narrowing the rights, instead of the kernel pre-wiring the sharing. That is "IPC carries control, shared memory carries data" (§10) done by the processes rather than arranged for them. See DECISIONS' open ideas and cap.rs's note on the PageFrame object.