path:line references, verified against the current tree. The failure was reproduced live on the dev box, and the fix was verified there with the regression test described at the end. Timings do not matter here, so there are none.
Problem and how it was found
The symptom, from the first reproduction: fork a snapshot, write a file in the fork, stop the fork, fork the same snapshot again, and read the file in the second fork.EBADMSG) when a metadata checksum does not match. The guest was reading a filesystem that disagreed with its own memory.
The snapshot’s own disk gave the direct evidence. After the first fork wrote /root/fork1-marker and stopped, the file was visible on the snapshot’s rootfs, read from the host without any VM running:
debugfs found the inode. The marker was on the snapshot’s disk, not on the fork’s. The fork had no disk of its own.
The earlier history matters. An earlier version of the daemon had a related bug where a fork shared its source’s rootfs file, and the fix recorded in the docs and in the previous revision of post 6 was that fork, retain-history resume and restore each clone the rootfs. That fix existed in the sense that a clone was made. It did not stop the guest from writing the original file.
Why the first test said everything was fine
The first test of isolation was the obvious one: write a marker in fork 1, stop it, fork again, check that fork 2 does not see the marker. It passed. Fork 2 did not see the marker. That result was a false “isolated”. The second guest resumed from the snapshot’s memory image, and that image includes the guest’s page cache and dentry cache as they were when the snapshot was taken. Its cached view of/root contained no marker, so cat /root/fork1-marker answered from cache with “No such file” and never read the disk that fork 1 had already changed. The damage was on the disk. The cache covered it.
The test checked what the guest believed, and the guest believed its own stale memory. Dropping the guest’s caches before reading forces it to read the disk:
Root cause
A Firecracker snapshot is two files, guest memory and device state, and the device state records the root drive by host path, not by contents.Vm::snapshot documents this (core/crates/vmm/src/vm/snapshot.rs:45-48), and post 6 explains why the path must stay put. The consequence for resume is that PUT /snapshot/load reopens whatever file sits at the recorded path.
Before the fix, Vm::resume sent a load with resume_vm: true and nothing else. The guest started running immediately, on the snapshot’s original disk file. There was no field in ResumeConfig to say otherwise.
The daemon did make a clone. It made it after the resume, from the source path, in the fork path, and it recorded the clone’s path on the Sandbox. That looked like isolation in every place a human or a test would look: the record had its own path, the destroy path deleted that path, the metrics counted a clone. Nothing told Firecracker about the clone. The live VM kept the original file open, and the clone was a copy of a disk that no process ever opened. The daemon’s bookkeeping and the guest’s reality had diverged, and the bookkeeping was the thing everyone read.
The inverse flaw in retain-history resume and restore
The same root cause had a second shape, in the time-travel path. A resume withretain_history true (the default) is supposed to leave the checkpoint pristine so it can be restored later.
retire_snapshot_filescloned the rootfs after the resume and gave the clone to the new sandbox record. The live VM, resumed on the recorded path, wrote the checkpoint’s original disk. The checkpoint was the part that got corrupted, while the sandbox record held an unused copy.- Restore cloned the checkpoint’s disk, then resumed, and never passed the clone to anything. The restored VM wrote the checkpoint’s original disk, so restoring the same checkpoint a second time read a disk the first restore had changed.
The change
The fix has two halves: give the resume a way to name a different disk, and make every caller that must keep the snapshot reusable use it.Firecracker mechanism
ResumeConfig gained rootfs_override: Option<PathBuf> (core/crates/vmm/src/vm/snapshot.rs:31). Vm::resume now branches on it (snapshot.rs:96-116):
PUT /snapshot/loadwithresume_vmset torootfs_override.is_none(). With an override the VM loads paused, so the guest does not run a single instruction before its drive is repointed.PATCH /drives/rootfswith{"drive_id": "rootfs", "path_on_host": <clone>}. This is the call that makes Firecracker open the clone instead of the recorded path.PATCH /vmwith{"state": "Resumed"}. The guest runs for the first time, on the clone.
Daemon call sites
resume_vm in the daemon takes the override (core/crates/daemon/src/http/routes/snapshot.rs:767), and its doc comment states the rule: pass a private clone for anything that must leave the snapshot reusable, and None only when the snapshot is being consumed. The three call sites:
- Fork (
fork_snapshot,snapshot.rs:649). The disk is cloned first (:679), wrapped instorage::OwnedFile, and passed toresume_vm(:688). The guard deletes the clone on any failure beforekeep(). A clone failure is fatal, because a fork on the snapshot’s own disk is silently unsafe, not degraded, and the fork lock is released. - Retaining resume (
resume_snapshot_by_id,snapshot.rs:455). Withretain_historytrue the clone is made first (:481-498) and passed toresume_vm(:502). If the clone fails the resume degrades to the consuming mode with a warning, because failing the caller’s resume would be worse than losing a restorable checkpoint for one call. If the resume fails, the clone is removed and the snapshot record is put back. - Restore (
restore_snapshot_history_by_id,snapshot_history.rs:149-171). The clone is made from the retired checkpoint’s disk and passed as the override. A failed resume removes the clone. The checkpoint is never opened by the restored VM, so it can be restored any number of times.
retire_snapshot_files (snapshot.rs:381) no longer clones. It only moves state.snap and mem.bin into the retired directory, because the clone already exists by the time it runs.
A non-retaining resume (?retain_history=false) still resumes with None and uses the disk in place. That is correct, not a leftover: the snapshot is being consumed, nothing will resume from it again, and a clone would be pure overhead.
Result
After the change, the regression testscripts/integration-tests/26-snapshot-disk-isolation.sh passes against a real daemon and a real microVM. It has 13 checks across three scenarios:
- Fork against fork. Fork a snapshot, write
/root/fork1-marker, stop the fork, fork again, drop caches, read. The second fork must not seefrom-fork1, must not print “Bad message”, and must still see the snapshot’s ownbase-marker. - Retaining resume, then restore twice. Resume with history, write
/root/resumed-marker, stop. Restore the checkpoint, drop caches, check that the post-checkpoint write is absent, write/root/restore1-marker, stop. Restore again, drop caches, check that the first restore’s write is absent and that there is no “Bad message”. - Status checks on every create, snapshot, fork, resume and restore call, so a failing step cannot read as an isolation pass.
drop_caches step is in the test for the reason the first test failed. The script’s header comment says so in one sentence. A restore or a fork now reads a disk that matches the memory it was captured with, in all the orderings the test exercises.
The snapshot’s disk is the thing being protected, so the host-side check is the same debugfs command from the first section: on the fixed build the marker is expected to be absent from the snapshot’s rootfs. The script does not run debugfs; it checks through the guest, with caches dropped.
What it cost or risks
- One more disk copy per resume that keeps history. The default resume and every pool claim now clone the rootfs before resuming (pool claims go through
resume_snapshot_by_idwithretain_historytrue,core/crates/daemon/src/lifecycle/pool_claim.rs:150). On a reflink filesystem that is metadata only, and the clone phase was measured at about 0.08 ms in the create path (post 17). On a filesystem without reflink support it is a full copy, so the placement advice in post 4 now applies to resume latency as well as create. I did not re-measure resume latency with the clone in front of it, so I do not claim a number here. - Resume is now two extra API calls. The
PATCH /drives/rootfsandPATCH /vmcalls are local socket requests to a process that is already up. I have not isolated their cost from the surrounding resume time. - A degraded mode remains, on purpose. If the clone fails for a retaining resume, the daemon resumes in the consuming mode and logs a warning. That keeps the caller’s sandbox alive, and it means that for that one resume no restorable checkpoint exists. It is the same trade the retire step already made.
- Snapshots taken by an earlier build may already be damaged. Nothing in this fix repairs a snapshot whose disk was written by a resumed fork. A snapshot disk that disagrees with its memory image cannot be told apart from a healthy one by the daemon. Anyone who ran the old build and forked or restored snapshots they care about should treat those snapshots as suspect.
- The override relies on Firecracker accepting a drive patch on a paused, freshly loaded VM. That is true of the Firecracker version on the dev box, and the regression test would catch a version that refuses it, because the resume would fail. It is a dependency on a Firecracker behaviour, not on a local invariant.
- The comments in the daemon are not all current. Some doc comments in
http/routes/snapshot.rsandhttp/routes/sandbox.rsstill describe the pre-fix design (for example, that Firecracker has no way to redirect a resumed VM’s drive, and that a fork does not own its rootfs). They are outside this change’s documentation scope and should be corrected with the code.
How to reproduce
Everything below runs on the dev box, since it needs KVM. Usescripts/remote.sh ssh or scripts/remote.sh run as described in the repository’s AGENTS.md.
To see the bug, build the parent of the fix and run the regression script against it:
ROOTFS_DIR is the daemon’s rootfs_dir setting. The snapshot’s disk is the source sandbox’s file, named by storage::rootfs_path (core/crates/daemon/src/storage.rs:62). On the old build debugfs prints the inode. On the fixed build the marker lands in the fork’s clone, so it should report the file as not found; the script does not assert this host-side check. If an auth token is configured, add the Authorization header to each call.
Then show why the naive check lies, and how to defeat it:
cat: /root/fork1-marker: Bad message. On the fixed build both are clean. To verify the fix, check out the current tree, restart the daemon, re-run scripts/integration-test.sh, and confirm topic 26 passes all 13 checks. The unit tests do not cover this path, because the resume needs a real Firecracker. Only the integration topic does.