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.
Design
Section titled “Design”Formatting a data disk
Section titled “Formatting a data 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 shim
Section titled “The shim”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:
- It creates the image under a temporary name in the bundle, with
O_CREAT|O_EXCLand mode 0600. It makes the image sparse at the data disk’s size, and keeps that descriptor open. - It checks the file’s identity.
lstaton the temporary name andfstaton the descriptor must give the samest_devandst_ino, withst_nlink1 andst_blocks0. - 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, anddiskutilhas 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. - Right before it runs
diskutil eraseDisk APFSon 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. - The format mounts the new, empty volume on the host once. It is a volume the host just made, not one a guest wrote.
wb-diskfmtreports the volume’s UUID, unmounts the volume, and detaches the image.wb-hostdrecords the volume UUID and the temporary name instate.db.- The shim repeats the identity check on the kept descriptor,
without the block count, and renames the file to its final name
with
renamex_npandRENAME_EXCL. That fails with the rule when a file has that name. wb-hostdrecords the disk as formatted.
When a check fails, the shim fails with the rule. It detaches only a device it attached.
When wb-diskfmt doesn’t exit
Section titled “When wb-diskfmt doesn’t exit”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.
- With
wb-launcher(macOS, S04-07-supervisionS04-07-supervision: SupervisionWho starts and restarts each host process, what happens when wb-hostd stops or the bundle is upgraded, and daemon outages., “Who starts whom”),wb-launcheris the shim’s parent and reaps it. It sends the group kill whenwb-hostdasks for it on the request channel.wb-hostdkeeps the wait and decides when to ask. It never signals the shim itself: once it confines itself, its profile deniessignalto other processes, its children included. - Without
wb-launcher,wb-hostdstarts the shim itself, is its parent, and sends the kill.
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 temporary and final names
Section titled “The temporary and final names”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”).
- The host never attaches a file at the final name.
- A leftover temporary file is deleted, never attached.
- A file can have its final name while
state.dbdoesn’t record it as formatted, as after a crash between the rename and the record.wb-hostdthen refuses to start the VM withdata-disk-unrecorded. The refusal nameswb vm reset-data.wb-hostdnever deletes the file. - The final name has no extension that Launch Services opens as a disk image (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., “Names on the host”). So a double click doesn’t mount it.
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.
Before a VM starts
Section titled “Before a VM starts”wb-hostd checks the slot’s record and the final name with lstat,
and never opens the file:
- a disk recorded as formatted, and a file at the final name: the VM starts;
- a disk recorded as formatted, and no file: the start is refused with
data-disk-missing, which nameswb vm reset-data.wb-hostddoesn’t make a new disk on its own (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., “After a crash”); - a file at the final name not recorded as formatted:
data-disk-unrecorded, as above; - no file at the final name and no formatted disk recorded:
wb-diskfmtmakes a new disk, deleting a leftover temporary file first.
The one exception
Section titled “The one exception”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.dbrecords 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.
Decisions
Section titled “Decisions”The shim’s parent kills its process group
Section titled “The shim’s parent kills its process group”- Rejected:
wb-hostdsignals the group itself, with the group ID the launcher reports. Its confined profile deniessignal, 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-diskfmtneeds 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-launchersends the kill once it is the shim’s parent, andwb-hostdasks for it.
A host-formatted data disk on an image file
Section titled “A host-formatted data disk on an image file”- Rejected: a volume the guest formats, because it doesn’t mount after a swap.
- Rejected: a USB data disk. Without a grant, TCC denies every guest process access to it (X08-data-diskX08-data-disk: Data disk for homesGuest user homes on a second disk, surviving a system-disk replacement.).
Status: Draft