Skip to content

S06-15 - The Xcode Disk

Purpose: How the host builds the read-only disk that holds Xcode and the simulator runtimes for an image build, under the wb-diskfmt shim’s profile, and what the build records.

Requirements: FR06-native-toolsFR06-native-tools: Native guest toolsAgent tool calls run tools native to the guest operating system (on macOS guests: Homebrew packages, Xcode command line tools, optionally full Xcode)., SEC02-no-host-fs-shareSEC02-no-host-fs-share: No host filesystem sharingNo host directory is mounted into the guest, read-only or otherwise., SEC12-least-privilegeSEC12-least-privilege: Least privilege on the hostNo root or administrator rights at run time and no extra host user accounts., SEC13-bounded-resourcesSEC13-bounded-resources: Bounded resourcesCPU, memory and disk of each VM are capped., 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.

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…

The Xcode disk is a disk image the host builds. It isn’t a shared directory (SEC02-no-host-fs-shareSEC02-no-host-fs-share: No host filesystem sharingNo host directory is mounted into the guest, read-only or otherwise.). The checks it starts with, and what the guest does with it, are in S06-14-xcode-imageS06-14-xcode-image: The Xcode ImageHow an image gets full Xcode and the simulator runtimes from the host, as a read-only disk the host builds, and who runs Xcode's first launch..

wb-diskfmt builds it, started through a third fixed wb-launcher entry, wb-diskfmt-xcode, whose WB_DISKFMT_SLOT is xcode (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”). Only wb-hostd starts it, during an image build. wb-hostd clones the parent into the new, empty build bundle, then starts wb-diskfmt-xcode, and starts no wb-vmd in that bundle until wb-launcher has reported the shim’s exit. Then it starts wb-vmd-layer. As for the data disk entries, its instance cap is one, and its shim is started as the leader of a new process group.

The entry’s profile parameters are the build bundle, <data>/images/macos-build.noindex, the real path of the Xcode app and <data>/xcode-runtimes. The shim resolves /Applications/Xcode.app with realpath itself before it confines itself, and applies the /Applications/*.app rule (S06-14-xcode-imageS06-14-xcode-image: The Xcode ImageHow an image gets full Xcode and the simulator runtimes from the host, as a read-only disk the host builds, and who runs Xcode's first launch., “Where Xcode comes from”). The shim takes none of these paths from the request or the environment. For the xcode slot, the slot’s bundle of diskfmt-slot-bundle-mismatch is the build bundle.

The profile is wb-diskfmt’s (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 profile”), with xcode.img and its temporary name in the build bundle in place of the data disk’s names, plus:

X06-guest-xcodeX06-guest-xcode: Guest users and XcodeCan builds and simulators run for a guest user without a GUI login?, “The profile”, lists every rule the measured runs needed, and I681I681 (open): wb-diskfmt-xcode: check the host's Xcode and runtimes and build the read-only Xcode diskPackage IMG.8 of docs/implementation-plan.md, part 1 of 4 (IMG.8a). starts from that list. Each rule the shim’s profile adds to wb-diskfmt’s, a Mach service or any other, needs a measured failure without it, and this page then says what a subverted shim gains from it.

codesign with no Mach service refuses Apple’s own signatures with CSSMERR_TP_NOT_TRUSTED. With com.apple.trustd.agent alone, the deep check of Xcode against S06-14-xcode-imageS06-14-xcode-image: The Xcode ImageHow an image gets full Xcode and the simulator runtimes from the host, as a read-only disk the host builds, and who runs Xcode's first launch.’s requirement and the check of a runtime’s disk image both pass, and a wrong requirement still fails. ditto doesn’t need one (X06-guest-xcodeX06-guest-xcode: Guest users and XcodeCan builds and simulators run for a guest user without a GUI login?, “Follow-up (I624I624 (closed): S06-14-xcode-image: measure the host export, signature checks and offline import of Xcode and runtimesFrom #194 (S06-14-xcode-image, the Xcode image variant).)”, “The profile”). The profile doesn’t allow another service: not com.apple.trustd, com.apple.SecurityServer (the keychain) or com.apple.ocspd, nor the user database lookup the base profile denies.

com.apple.trustd.agent runs outside the sandbox as the host user, so a subverted shim can ask it to evaluate any certificate, and it may fetch from the network to do so (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 profile”). The names are in code, and the opt-in host test’s confined run checks them (I681I681 (open): wb-diskfmt-xcode: check the host's Xcode and runtimes and build the read-only Xcode diskPackage IMG.8 of docs/implementation-plan.md, part 1 of 4 (IMG.8a).).

The shim knows its volume only by device. diskutil image attach reports the device it attached. The shim’s volume is a volume of the APFS container whose one physical store is that device, read from the I/O Registry. APFS reports a mounted volume’s f_mntfromname as a volume of that synthesized container, never as the attached device. The shim never looks a volume up by its name or its mount point, so it never takes a leftover volume named wb-xcode for its own. When the I/O Registry can’t be read, or the container holds more than one volume, the build refuses (xcode-volume-unknown).

As for a data disk (S06-13-data-disk-formatS06-13-data-disk-format: Data Disk FormatHow the host formats a VM's new data disk, the one exception SEC15-no-guest-disk-mount makes, and the checks before a VM starts with its disk., “The shim”), the shim:

  1. creates xcode.img in the build bundle under a temporary name, with the same identity checks. Its size is the sum of the inputs’ file sizes (st_size) plus slack, within a bound in code. The copy drops APFS file compression, so the blocks the source takes on the host are too few: an Xcode of 4.0 GB on the host took 10 GB on the volume;
  2. attaches it, makes an APFS container on it with a volume named wb-xcode, and mounts the volume only on xcode-mnt, a new directory in the build bundle, as “Never mounted in /Volumes” below says. An existing xcode-mnt refuses the build (xcode-mnt-exists). Before any write, statfs on xcode-mnt has to give that path as f_mntonname and a volume of its container as f_mntfromname (xcode-mount-mismatch). Its f_flags have to hold MNT_NOSUID, MNT_NODEV and MNT_DONTBROWSE, and not MNT_IGNORE_OWNERSHIP (xcode-mount-options). The volume’s root has to be empty, apart from a fixed list in code of what macOS makes on a new volume (xcode-volume-not-empty). Its owner and mode have to be the measured ones, with no group or other write and no ACL (xcode-volume-root-mode);
  3. copies the app to Xcode.app on the volume, and each exported runtime to Runtimes/, with ditto --norsrc --noextattr --noacl --noqtn;
  4. removes every _MASReceipt and every .DS_Store from the copied app, at any depth, with a walk that uses lstat and never follows a symbolic link. An App Store install’s receipt names the host’s purchase and device. Removing them is also an integrity step (“What the signature doesn’t seal” below). The copy without them still meets the code requirement, and Gatekeeper in the guest accepts it;
  5. checks the copy, which catches a change to the source during the copy, and a short copy, since ditto exited 0 after a file it failed to write:
  6. checks the device and the root again, as in steps 2 and 5, with step 2’s fixed list accepted at the root. It then unmounts the volume by its device and detaches it, neither with force, and renames the file to xcode.img. A busy volume or device refuses the build (xcode-unmount-busy).

The copy keeps each exported runtime’s other files. The guest’s import is given only the disk image (S06-14-xcode-imageS06-14-xcode-image: The Xcode ImageHow an image gets full Xcode and the simulator runtimes from the host, as a read-only disk the host builds, and who runs Xcode's first launch., “In the build VM”), but it was measured only beside its Firmware files. I684I684 (open): Xcode image on the maintainer's Mac: build a named image with the host's Xcode and a runtime, and check it in a sessionPackage IMG.8 of docs/implementation-plan.md, part 4 of 4 (IMG.8d). tries an import with the disk image alone. If that works, the shim copies only the disk image. If not, the import reads those files unsigned, and the build records their SHA-256 too. Until then the walk in step 5 holds them to their names and types.

With owners, the files the shim writes belong to the host user’s ID on the volume. install-xcode reads only Xcode.app and Runtimes, and gives the copy to root:wheel whatever owner the volume shows.

Each ditto and codesign run has a deadline in code, as each diskutil step has, set above the times X06-guest-xcodeX06-guest-xcode: Guest users and XcodeCan builds and simulators run for a guest user without a GUI login?, “Follow-up (I624I624 (closed): S06-14-xcode-image: measure the host export, signature checks and offline import of Xcode and runtimesFrom #194 (S06-14-xcode-image, the Xcode image variant).)”, measured. The deep check took 53 to 107 s on the source and 45 to 46 s on the copy. Each runtime’s disk image took 22 to 27 s, and is checked on the source and again on the copy. The kill of S06-13-data-disk-formatS06-13-data-disk-format: Data Disk FormatHow the host formats a VM's new data disk, the one exception SEC15-no-guest-disk-mount makes, and the checks before a VM starts with its disk., “When wb-diskfmt doesn’t exit”, applies to the shim as to the data disk entries, and wb-hostd’s wait covers the sum of its deadlines.

A path in the copy is governed by the resource rules (rules2 in _CodeSignature/CodeResources) of one bundle, relative to its resource root (Contents, Versions/<v>, or the bundle itself). That is the top bundle, or a nested bundle that an enclosing governing bundle’s files2 lists with a cdhash. Any other bundle, its CodeResources included, is plain files under the enclosing seal (X06-guest-xcodeX06-guest-xcode: Guest users and XcodeCan builds and simulators run for a guest user without a GUI login?, “Follow-up (I624I624 (closed): S06-14-xcode-image: measure the host export, signature checks and offline import of Xcode and runtimesFrom #194 (S06-14-xcode-image, the Xcode image variant).)”).

codesign --verify --deep --strict doesn’t check _MASReceipt, nor a path that a governing omit rule matches: .DS_Store at any depth, Info.plist and PkgInfo at the resource root, and a locversion.plist in a .lproj directory. Step 4 removes _MASReceipt and .DS_Store. After the signature check, the shim in step 5 (xcode-volume-unexpected) and install-xcode (xcode-copy-invalid) accept a file or symbolic link in Xcode.app only when it is:

  • in the files2 of the governing bundle whose seal covers it;
  • in that bundle’s _CodeSignature, its main executable, or the Info.plist its code directory binds;
  • one of a framework’s root symbolic links;
  • an omitted PkgInfo that is a regular file of 8 bytes.

A governing CodeResources without rules2, without ^.* set to true, or with an omit rule outside that list refuses the build (xcode-seal-rule-unknown).

diskutil eraseDisk mounts a new volume in /Volumes at once (X06-guest-xcodeX06-guest-xcode: Guest users and XcodeCan builds and simulators run for a guest user without a GUI login?, “Follow-up (I624I624 (closed): S06-14-xcode-image: measure the host export, signature checks and offline import of Xcode and runtimesFrom #194 (S06-14-xcode-image, the Xcode image variant).)”), where another local account may be able to write to it until the unmount. So the shim doesn’t use eraseDisk. It runs diskutil apfs createContainer, then diskutil apfs addVolume -nomount, then diskutil mount -mountOptions owners,nobrowse,nosuid,nodev -mountPoint on xcode-mnt. addVolume -mountpoint needs root on macOS 27.2, and I681I681 (open): wb-diskfmt-xcode: check the host's Xcode and runtimes and build the read-only Xcode diskPackage IMG.8 of docs/implementation-plan.md, part 1 of 4 (IMG.8a). doesn’t run diskutil as root. I681I681 (open): wb-diskfmt-xcode: check the host's Xcode and runtimes and build the read-only Xcode diskPackage IMG.8 of docs/implementation-plan.md, part 1 of 4 (IMG.8a). measures this route. If a step of it mounts the volume in /Volumes, I681I681 (open): wb-diskfmt-xcode: check the host's Xcode and runtimes and build the read-only Xcode diskPackage IMG.8 of docs/implementation-plan.md, part 1 of 4 (IMG.8a). stops and reports it, and doesn’t accept the window.

Before the mount, <data>, each directory from it down to the build bundle, the build bundle and xcode-mnt have to be directories the host user owns, with no group or other permission and no ACL. So no other account can enter any of them (xcode-mnt-exposed). The empty-root check of step 2 and the exact-contents check of step 5 also catch a writer in the host user’s own account.

The mount on xcode-mnt is 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.’s one exception, as for a data disk (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., “Formatting a data disk”): a blank image the host itself created, before any guest has run with it. The shim fills the volume as the bundle build fills the guest tools disk.

The host never mounts or opens the file again once a guest had it, and it is deleted with the build bundle. That delete doesn’t follow links, and stops at a directory whose st_dev isn’t the bundle’s. A volume left mounted on xcode-mnt refuses the build with xcode-mount-left, which names the mount point.

A killed shim can leave its volume attached, or mounted on xcode-mnt. As with a killed data disk shim, wb-hostd logs the temporary image, and the device is attached until the user ejects it or the host restarts (S06-13-data-disk-formatS06-13-data-disk-format: Data Disk FormatHow the host formats a VM's new data disk, the one exception SEC15-no-guest-disk-mount makes, and the checks before a VM starts with its disk., “When wb-diskfmt doesn’t exit”). That volume never reaches a guest, because its file is never renamed to xcode.img, and a later build finds its own volume by device.

The shim reports Xcode’s version and build and the SHA-256 of each runtime’s disk image, all read from the checked copy, to wb-hostd, which treats them as untrusted, as it treats every answer of the shim. state.db records them for the image.

wb-hostd never reads Xcode, the runtimes or the license record itself. It decides between the layer-only path of S06-01-image-layersS06-01-image-layers: Image Layers and the Toolchain PrefixThe layers of a guest image, and the toolchain prefix that project layers install into., “Only the layer”, and a full build after a check-only run of the shim, which makes the checks of S06-14-xcode-imageS06-14-xcode-image: The Xcode ImageHow an image gets full Xcode and the simulator runtimes from the host, as a read-only disk the host builds, and who runs Xcode's first launch., reports the same values from the source, and builds no disk. That run also gets a new, empty build bundle. The layer-only path requires them to equal the recorded ones. A new Xcode on the host changes nothing until the next wb image build. That build then builds every layer.

  • The route of “Never mounted in /Volumes” run on the host: no mount in /Volumes, and the options kept on xcode-mnt.
  • What macOS makes on the root of a new volume mounted with owners,nobrowse, which is the list xcode-volume-not-empty allows, whether each entry stays empty during the copy, and the root’s owner and mode.
  • The I/O Registry lookup of the container, and the profile rule it needs.
  • Whether the confined shim needs any service besides com.apple.trustd.agent.

The host’s build of the Xcode disk has its own page, apart from S06-14-xcode-imageS06-14-xcode-image: The Xcode ImageHow an image gets full Xcode and the simulator runtimes from the host, as a read-only disk the host builds, and who runs Xcode's first launch..

The blank volume is only ever mounted on xcode-mnt in the build bundle, which no other account can enter.

  • Other local accounts as an adversary beyond this volume.
  • Building the disk on a host other than macOS, which Xcode doesn’t run on.
  • Removing the runtimes that the export leaves installed on the host.

Status: Draft