Skip to content

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.

Tests: C11-host-daemonsC11-host-daemons: Host Daemons, Audit, and DisksThe test cases for the host daemons' own checks: wb-vmd's device set and slots, the image build bundle, supervision, the accounting and event channels, the daemon log pipes, the audit writer, free space, and the data…

Brief: 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.

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:

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.

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.

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:

It logs the end with its rule and the number of copies it keeps. Each kept copy then closes when its bound passes.

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.

A sender keeps its copy of a passed socket until an acknowledgment or the receiver’s first record or byte, bounded by a deadline.

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.

Status: Draft