Skip to content

S06-13 - Data Disk Format

Purpose: How the host formats a VM’s new data disk, the one exception SEC15-no-guest-disk-mountSEC15-no-guest-disk-mount: The host never mounts a guest-written diskA disk image is guest-written once a guest has run with it attached, and every copy or clone of a guest-written image is guest-written too. makes, and the checks before a VM starts with its disk.

The host formats a new data disk before any guest has run with it (S06-05-disksS06-05-disks: DisksA VM's system disk and data disk: how the data disk keeps what the guest flushes, and how the guest mounts it., “Disks”).

  • A volume the guest formats APFS is encrypted at rest. A fresh system disk with fresh auxiliary storage couldn’t unwrap its key, so it doesn’t mount after a swap.
  • A volume the host makes on the image isn’t encrypted at rest.

On macOS 27.0.1, a host-made volume was not encrypted in the guest across two system disk swaps, and wb-diskfmt formatted it under its own profile, with diskutil and no hdiutil (X08-data-diskX08-data-disk: Data disk for homesGuest user homes on a second disk, surviving a system-disk replacement., “Follow-up (I228I228 (closed): X08-data-disk follow-up: measure that a host-made data volume stays unencrypted and returns freed spaceX08-data-disk (PR #227) recommends option A: the host formats the data disk as APFS.)”).

The formatting runs in wb-diskfmt, a shim. wb-hostd starts it through the fixed wb-launcher entry of the VM’s slot, wb-diskfmt-work or wb-diskfmt-isolated. The entry’s profile parameter is that VM’s bundle (S04-architectureS04-architecture: ArchitectureName the processes, the boundaries between them, and which requirement each boundary serves.). The shim never takes a path from the request. It confines itself to the data disk’s two names in that bundle (S04-04-vm-processesS04-04-vm-processes: Per-VM ProcessesOne wb-vmd for each VM, the wb-vmd-layer entry of the Claude Code layer build, the wb-vmd-recipe entry of a named image's recipe, and wb-diskfmt, which formats a VM's new data disk., “wb-diskfmt”), and then:

  1. It creates the image under a temporary name in the bundle, with O_CREAT|O_EXCL and mode 0600. It makes the image sparse at the data disk’s size, and keeps that descriptor open.
  2. It checks the file’s identity. lstat on the temporary name and fstat on the descriptor must give the same st_dev and st_ino, with st_nlink 1 and st_blocks 0.
  3. It attaches the file with diskutil image attach --noMount. It checks that the backing image path of the device it got is the temporary name (the backing path check). The backing path comes from the device’s properties in the I/O Registry, read in the shim’s own process. On macOS 27 the attach output doesn’t name a backing path, and diskutil has no command that reports it. When the attach output does name a backing image, it must name the temporary name, once and as a path.
  4. Right before it runs diskutil eraseDisk APFS on that device, it repeats the identity check and the backing path check. A name replaced before the attach, or after it, and not put back fails the identity check here, and the device is detached before any format.
  5. The format mounts the new, empty volume on the host once. It is a volume the host just made, not one a guest wrote.
  6. wb-diskfmt reports the volume’s UUID, unmounts the volume, and detaches the image.
  7. wb-hostd records the volume UUID and the temporary name in state.db.
  8. The shim repeats the identity check on the kept descriptor, without the block count, and renames the file to its final name with renamex_np and RENAME_EXCL. That fails with the rule when a file has that name.
  9. wb-hostd records the disk as formatted.

When a check fails, the shim fails with the rule. It detaches only a device it attached.

wb-diskfmt leads its own process group, and each diskutil it runs is in that group. When the exchange has closed and the shim doesn’t exit in time, the whole group is killed, so no diskutil keeps running after the shim. A diskutil stopped part-way leaves its request with the daemon it asked, which finishes or abandons it.

The shim’s parent sends the kill, and only while it hasn’t reaped the shim. The shim’s process ID, which is also its group’s ID, isn’t reused before that reap, so the kill can’t reach another process group. Only the parent’s own wait reaps the shim, so only the parent knows that the ID is still the shim’s.

After the kill, or a kill that failed, wb-hostd logs the rule data-disk-shim-exit. With wb-launcher, the line holds the launcher’s answer, or that no answer came in time (S04-04-vm-processesS04-04-vm-processes: Per-VM ProcessesOne wb-vmd for each VM, the wb-vmd-layer entry of the Claude Code layer build, the wb-vmd-recipe entry of a named image's recipe, and wb-diskfmt, which formats a VM's new data disk., “wb-diskfmt’s kill”). When the shim hadn’t answered the format, the line also names the temporary image, which a device may still be attached to. wb-hostd doesn’t detach that device: only the shim attaches and detaches (S04-04-vm-processesS04-04-vm-processes: Per-VM ProcessesOne wb-vmd for each VM, the wb-vmd-layer entry of the Claude Code layer build, the wb-vmd-recipe entry of a named image's recipe, and wb-diskfmt, which formats a VM's new data disk., “wb-diskfmt”). The device is attached until the user ejects it or the host restarts. A later format is still safe. It deletes the leftover temporary file without attaching it, and its checks guard the device it attaches itself.

Each diskutil step has a deadline, but the confined shim can’t signal diskutil, so a diskutil that hangs runs past it. The bound is wb-hostd’s wait for the format’s answer, and then the group kill by the shim’s parent. A slow run that keeps to its deadlines gets its answer in time, because the wait is longer than the sum of the deadlines on their longest path.

The final name is data.wbdisk, and the temporary name data.wbdisk.tmp, both in the VM’s bundle (S06-05-disksS06-05-disks: DisksA VM's system disk and data disk: how the data disk keeps what the guest flushes, and how the guest mounts it., “Bundle files”).

A data disk is unencrypted at rest, except by the host’s own FileVault. A user who mounts it by hand gives the host kernel a guest-written filesystem.

wb-hostd checks the slot’s record and the final name with lstat, and never opens the file:

Formatting a blank image the host itself created, before any guest has run with it, is the one exception SEC15-no-guest-disk-mountSEC15-no-guest-disk-mount: The host never mounts a guest-written diskA disk image is guest-written once a guest has run with it attached, and every copy or clone of a guest-written image is guest-written too. makes. The steps above keep it to that file:

  • the shim attaches only the file it just created under its temporary name;
  • a VM starts only with a disk that state.db records as formatted.

The exception ends when the VM first starts with the disk.

The checks are on the name, not on what the attach opened. A process of the host user can rename another image to the temporary name before the attach, and the shim’s file back before the checks. Both checks then pass, and the format writes to that image. The kernel has also read the other image’s partition map at the attach. That is a residual within the host user, whom T00-indexT00-indexboundary 6 is the host terminal stream. trusts.

The VM’s system disk, auxiliary storage and saved state are guest-written too. The Virtualization API in wb-vmd is the one host code that opens them.

The shim’s parent kills its process group

Section titled “The shim’s parent kills its process group”
  • Rejected: wb-hostd signals the group itself, with the group ID the launcher reports. Its confined profile denies signal, and it can’t tell whether the launcher has reaped the shim, so the ID could name another group by then.
  • Rejected: the shim kills its own group on a timer. Its profile has no signal rule, and the kill is for a shim that hangs.
  • Rejected: a kill request for any launcher entry. Only wb-diskfmt needs one so far, and the narrower request channel is the stricter choice.
  • Decided: I370I370 (open): wb-launcher: own wb-diskfmt's process group kill once it starts the shimFrom the security review of #369 (finding 3), for #355.. wb-launcher sends the kill once it is the shim’s parent, and wb-hostd asks for it.

A host-formatted data disk on an image file

Section titled “A host-formatted data disk on an image file”

Status: Draft