S04-12 - Passing Descriptors
Purpose: How one host process passes an open socket to another: who holds it when, how the receiver shows it holds it, when the sender closes its copy, and what a lost or bad acknowledgment does.
Requirements: SEC08-proj-isolationSEC08-proj-isolation: Per-project isolationEach project has its own guest user, state and history, and one project cannot persist into another., SEC13-bounded-resourcesSEC13-bounded-resources: Bounded resourcesCPU, memory and disk of each VM are capped.
Design
Section titled “Design”Why a sender keeps its copy
Section titled “Why a sender keeps its copy”On macOS 27 the kernel can collect a Unix domain socket that is in
flight in an SCM_RIGHTS message while no process holds another
descriptor of it. The receiver then gets a dead socket: a read returns
a record of 0 bytes, and a send fails with EINVAL (I637I637 (closed): Descriptor senders close their copy before the receiver holds it (darwin socket GC)Found while fixing #633.).
So a process that passes a socket keeps its own copy until the receiver shows it holds it (I647I647 (closed): wb-netd: keep a handed-off stream's end open until wb-proxyd holds it (macOS socket GC)wb-netd closes the stream end it hands to wb-proxyd right after the send: internal/netd/handoff/stream.go:98 (defer theirs.Close()), as the comment on StreamPair (internal/platform/fdchan/fdchan_darwin.go, around line…, I648I648 (closed): wb-vmd: keep a passed descriptor open until wb-hostd holds it (macOS socket GC)wb-vmd hands descriptors to wb-hostd and closes its copy at once: VMSupervisor.swift (the handoff.send(record, descriptor: transport.hostEnd) call, around line 219) and GuestConnector.swift (send(:descriptor:), which…). The proof is one of:
- an acknowledgment from the receiver that names the descriptor;
- the receiver’s first record or byte on the passed socket.
The rule applies on every platform, so the code has one path. These descriptors are exempt, because they are never in flight without a holder:
- a pipe, such as the payload pipes of the control channels (S04-architectureS04-architecture: ArchitectureName the processes, the boundaries between them, and which requirement each boundary serves., “Control channels”);
- a descriptor a process inherits at spawn, such as a daemon’s control and event channels and the data disk shim’s descriptors.
The legs
Section titled “The legs”| Leg | Passed | Proof the receiver holds it | Bound on the kept copy |
|---|---|---|---|
wb-vmd to wb-hostd |
a guest connection or the packet transport (HandoffMessage) |
HandoffAck |
wb-vmd’s connect timeout |
wb-hostd to wb-proxyd |
its end of a VM’s hand-off socket (HandoffSocket) |
HandoffSocketAck |
egress.AckTimeout (S07-20-handoff-socketsS07-20-handoff-sockets: Hand-off SocketsThe life of one VM's hand-off socket: its identity, the acknowledgments of both ends, how it closes, who a failure is charged to, what each restart does to it, and which of its decisions reach the audit log.) |
wb-hostd to wb-netd |
the other end (HandoffSocket) |
HandoffSocketHeld |
egress.AckTimeout |
wb-netd to wb-proxyd |
one end of a stream’s socketpair (Stream) |
wb-proxyd’s first byte on it, or a StreamReset for it |
StreamHoldTimeout |
S04-02-vm-providerS04-02-vm-provider: VM Provider and StreamsHow wb-vmd hands guest connections and the NIC endpoint to other processes, the fixed device set of a VM, and where wb-proxyd takes a stream's identity from. (“Hand-off on macOS”) has the first leg’s records and rules. S07-20-handoff-socketsS07-20-handoff-sockets: Hand-off SocketsThe life of one VM's hand-off socket: its identity, the acknowledgments of both ends, how it closes, who a failure is charged to, what each restart does to it, and which of its decisions reach the audit log. has the middle two, and S07-05-stream-hand-offS07-05-stream-hand-off: Stream Hand-offHow wb-netd hands each stream to wb-proxyd, and the checks that keep a compromised wb-netd from widening what a stream may reach. the last. Each bound is a value in code, named here so a reader can find it.
States of a passed descriptor
Section titled “States of a passed descriptor”A sender’s copy is in one of these states:
| State | Entered when | Left when |
|---|---|---|
| kept | the send returned | the proof arrives, or the bound passes |
| released | the proof arrived | never: the copy is closed |
| expired | the bound passed | never: the copy is closed |
A send that fails leaves nothing kept. The sender closes its copy at once and handles the failure as its leg says.
When the bound passes, the sender closes its copy and logs it with the
leg’s rule. An expired copy isn’t a refusal on the last leg, where a
stream whose client speaks first can be idle for longer than the bound
(stream-hold-expired). On the others it fails what waited on it.
A sender keeps each copy under the key the proof names: the request of the first leg, the hand-off socket’s number on the middle two, the stream on the last. One proof releases one copy.
Acknowledgments are input
Section titled “Acknowledgments are input”The receiver of an acknowledgment checks it as input from another process. It doesn’t trust that the sender of the acknowledgment is honest. For each case:
| The acknowledgment is | The receiver |
|---|---|
| lost | closes the copy when the bound passes |
| of the wrong form | refuses it, logs it, and reads on |
| for no kept copy: a duplicate, or one that comes after the bound | refuses it, logs it, and reads on |
So one bad acknowledgment never stops the reader, and the next hand-off is acknowledged as usual. On a control channel, a record of the wrong form follows the channel’s own rule instead, which treats it as a crash of the daemon that sent it (S04-architectureS04-architecture: ArchitectureName the processes, the boundaries between them, and which requirement each boundary serves., “Control channels”).
A reader that only reads acknowledgments, such as wb-vmd’s, ends in
these cases:
- its peer closed its end;
- a record came with control data that was cut. The process may then hold descriptors it can’t name, as S07-05-stream-hand-offS07-05-stream-hand-off: Stream Hand-offHow wb-netd hands each stream to wb-proxyd, and the checks that keep a compromised wb-netd from widening what a stream may reach. (“Message form”) says for every channel;
- a run of receives in a row that fail with an error from
recvmsgreaches a bound in code. A receive that succeeds resets the count.
It logs the end with its rule and the number of copies it keeps. Each kept copy then closes when its bound passes.
Records and the channel
Section titled “Records and the channel”Each leg sends one record per message, with at most one descriptor, on
a channel of internal/platform/fdchan (S12-01-platform-interfacesS12-01-platform-interfaces: Platform InterfacesHow platform-specific code is isolated behind interfaces, and what each host OS uses for each.,
“One package for the descriptor channels”). The interface doesn’t
change for this page: the caller keeps the copy, not fdchan.
Decisions
Section titled “Decisions”Keep the copy until the receiver holds it
Section titled “Keep the copy until the receiver holds it”A sender keeps its copy of a passed socket until an acknowledgment or the receiver’s first record or byte, bounded by a deadline.
- Why: on macOS 27 a socket in flight with no holder can arrive dead (I637I637 (closed): Descriptor senders close their copy before the receiver holds it (darwin socket GC)Found while fixing #633.). Keeping the copy costs a descriptor for a short time.
- Rejected:
- Close at once and retry a dead socket. The receiver can’t tell a dead socket from a peer that closed, so it would need a second proof anyway.
- Pass every socket at spawn, by inheritance. Hand-off sockets and streams are made while the daemons run.
- Decided: I637I637 (closed): Descriptor senders close their copy before the receiver holds it (darwin socket GC)Found while fixing #633. (2026-11-10), built in I647I647 (closed): wb-netd: keep a handed-off stream's end open until wb-proxyd holds it (macOS socket GC)wb-netd closes the stream end it hands to wb-proxyd right after the send: internal/netd/handoff/stream.go:98 (defer theirs.Close()), as the comment on StreamPair (internal/platform/fdchan/fdchan_darwin.go, around line… and I648I648 (closed): wb-vmd: keep a passed descriptor open until wb-hostd holds it (macOS socket GC)wb-vmd hands descriptors to wb-hostd and closes its copy at once: VMSupervisor.swift (the handoff.send(record, descriptor: transport.hostEnd) call, around line 219) and GuestConnector.swift (send(:descriptor:), which….
One bad acknowledgment never stops the reader
Section titled “One bad acknowledgment never stops the reader”A wrong, duplicate or late acknowledgment is refused and skipped. A dedicated reader ends only when its peer closes, on control data that was cut, or after a run of failed receives.
- Why: an ended reader leaves every later copy kept to its bound.
On the first leg each holds a connect place in
wb-vmdfor the full bound (I751I751 (closed): wb-vmd: a bad hand-off ack or failed receive is skipped, not the end of the ack readerBuilds S04-12-descriptor-passing, "Acknowledgments are input", in wb-vmd's acknowledgment reader (#754, PR #758).). Skipping a bad record fails closed as well, because an unacknowledged copy still closes at its bound. - Rejected:
- End the reader at the first bad record. That turns one bad record
into a slower VM until
wb-vmdrestarts. - Skip control data that was cut, too. The kernel installs the cut descriptors, which can’t be closed, so a run of them leaks descriptors without bound.
- End the reader at the first bad record. That turns one bad record
into a slower VM until
- Decided: I754I754 (closed): S07-05-stream-hand-off and S04: settle the hand-off contract end to end (descriptor passing, acks, identity, close, restarts, audit)The hand-off of sockets and streams between host processes keeps getting patched one review at a time:, in this spec (B754-handoff-contractB754-handoff-contract: What happens to one VM's hand-off socket, from its creation to its end?S04-12-descriptor-passing, S07-20-handoff-sockets and S07-21-vm-end settle the hand-off contract in one place.).
Status: Draft