Skip to content

S04-11 - Starting `wb-vmd`

Purpose: What wb-vmd inherits from its spawner, the socket it serves gRPC on, its lifeline, and the checks on each connection. How it confines itself is in S04-03-self-sandboxingS04-03-self-sandboxing: Self-SandboxingHow each host daemon confines itself at startup, and the wb-launcher that starts confined programs on macOS..

wb-vmd takes no arguments, and refuses any with vmd-arguments. It inherits four descriptors, and in the build slot a fifth:

Descriptor What it is
0 the lifeline: a pipe or socket from its spawner that it only reads
2 the log pipe (S04-03-self-sandboxingS04-03-self-sandboxing: Self-SandboxingHow each host daemon confines itself at startup, and the wb-launcher that starts confined programs on macOS., “Daemon logs”)
3 a listening AF_UNIX stream socket for gRPC
4 the hand-off socket: AF_UNIX, SOCK_DGRAM (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”)
5 build slot only: the read end of the build password pipe, which wb-guestadmin-build writes (S15-04-guest-adminS15-04-guest-admin: The Guest Admin UserHow the host keeps the password of the guest admin user wbadmin, from the image build to each VM's first contact., “Build”)

Descriptor 5 is the one exception of S12-01-platform-interfacesS12-01-platform-interfaces: Platform InterfacesHow platform-specific code is isolated behind interfaces, and what each host OS uses for each., “Rules” (S04-10-vmd-installS04-10-vmd-install: Installing macOS in `wb-vmd`The wb-vmd-install entry of an image build: its install rules, the restore image it reads, the build bundle it installs into, and its Install call., “The build password pipe”).

Its profile allows no path outside its bundle, so it can’t bind a socket. The spawner binds it in <data>/run/ (S04-architectureS04-architecture: ArchitectureName the processes, the boundaries between them, and which requirement each boundary serves., “Inter-process contracts”) and passes the listening descriptor. The spawner is wb-hostd through wb-launcher, or a test. wb-hostd names the socket vmd-<slot>-<generation>.sock, so no two runs share a path, and removes it when the run ends.

The socket follows these endpoint rules of S04-architectureS04-architecture: ArchitectureName the processes, the boundaries between them, and which requirement each boundary serves., “Inter-process contracts”:

  • The socket is in the run directory, which wb-hostd makes and checks before it serves, and which the dialer checks before each connect.
  • The socket file has mode 0600 after the bind.
  • Each end checks the other’s user ID: wb-hostd dials through localipc, and wb-vmd checks each peer it accepts.

The socket has no .lock of its own. wb-hostd holds the lock of its own endpoint for its life, so one wb-hostd at a time makes and removes vmd-*.sock files. When it stops, it keeps the lock after it has closed its own socket, until every wb-vmd it spawned has ended. Before the bind, wb-hostd refuses any file already at the path, a symbolic link included, with ipc-endpoint-unsafe and leaves it, because bind(2) follows a dangling link.

When wb-hostd crashes, its sockets stay. The next wb-hostd removes every vmd-*.sock that is a socket once it holds its endpoint’s lock, before it builds the VM manager. It doesn’t probe them with a connect, because the wb-vmd processes of the crashed wb-hostd exited when their lifelines closed. A file of that name that isn’t a socket is left and logged with ipc-endpoint-unsafe.

Right after the deny probe (S04-03-self-sandboxingS04-03-self-sandboxing: Self-SandboxingHow each host daemon confines itself at startup, and the wb-launcher that starts confined programs on macOS., “Confined first thing in main”), wb-vmd checks each descriptor: open, and of the kind in the table. Descriptors 0 and 2 must be a pipe or a socket, and descriptor 0 must block. Descriptor 3 must have a path of its own and no peer. Anything else is refused with vmd-descriptor-invalid. So it never serves on a descriptor its spawner didn’t mean.

Status: Draft