Chapter 25 · Part XI
Hardening: threat model, fuzzing and sandboxing
Course progress: chapter 25 is 26 of the 26 chapters written so far (numbering starts at 00)
Warm-up: three questions from earlier chapters
Answer each one in your head or on paper before you open its answer. They change on each visit.
From chapter 13: Loading kernels: arm64 Image, initramfs and ELF
The eight bytes at offset
0x10of an Image header are00 00 2a 02 00 00 00 00, andtext_offsetis 0. Where does the kernel's memory start and end in our plan?Show answer
The field is
image_size, little-endian:0x022a0000. The kernel starts at the 2 MiB-aligned base0x4020_0000plustext_offset0, so it owns0x4020_0000..0x424a_0000(start plusimage_size, end exclusive).From chapter 13: Loading kernels: arm64 Image, initramfs and ELF
That kernel ends at
0x424a_0000. Where does our plan put a 9 MB initramfs, and which part of that choice comes from the boot protocol and which from us?Show answer
At
0x4260_0000, the end rounded up to the next 2 MiB boundary. The protocol only requires that it lie outside the kernel'simage_sizespan and, with the kernel, inside one 1 GiB-aligned window of at most 32 GiB; the 2 MiB rounding is our choice, to keep the numbers readable.From chapter 13: Loading kernels: arm64 Image, initramfs and ELF
A
--kernelfile begins with the bytes4d 5aand haszimgat offset 4. What is it, what does our VMM do with it, and what do you run instead?Show answer
An EFI zboot wrapper: a compressed kernel packaged as a UEFI program (the
MZis the PE/COFF signature). The VMM refuses it with "EFI zboot image" and exit code 2 before creating a VM;cargo xtask unzboot(run byscripts/fetch.sh linux) unwraps it on the host into the raw Image.From chapter 13: Loading kernels: arm64 Image, initramfs and ELF
An Image's
flagsfield is6. Does our loader accept it?Show answer
No. Bit 0 is 0 (little-endian, fine), but bits 1 and 2 read
0b11= 3, "64 KiB pages", which Apple Silicon does not implement. The loader refuses it with a named error rather than let the kernel die in early boot with no output.From chapter 13: Loading kernels: arm64 Image, initramfs and ELF
A header claims
image_size = 0xFFFF_FFFF_FFFF_FFFF. Why doesload + image_size <= ram_endnot catch it, and what does?Show answer
With wrapping arithmetic the sum overflows to a small number (here
0x401F_FFFF), which passes the comparison; in a Rust debug build+panics instead.load.checked_add(image_size)returnsNoneon overflow, and the range check (RamRange::contains) treats that as "outside RAM", so the plan fails with exit code 2.From chapter 13: Loading kernels: arm64 Image, initramfs and ELF
An ELF program header of type
PT_LOADsaysp_filesz = 0x100andp_memsz = 0x80. What does the loader do?Show answer
Refuse the file. A segment cannot hold more file bytes than memory:
p_filesz <= p_memszmust hold, and the difference is the zero-filled tail (the BSS). Copyingp_fileszbytes into ap_memszslot would write past the segment.From chapter 13: Loading kernels: arm64 Image, initramfs and ELF
List the register values our vCPU starts a Linux kernel with, and the one system-register setting that goes with them.
Show answer
PC = the kernel's first byte (
0x4020_0000),x0= the device tree's address (0x4000_0000),x1,x2andx3= 0,CPSR=0x3c5(EL1h with D, A, I and F masked). The MMU is off:SCTLR_EL1.M(and the cache-enable bits C and I) cleared.From chapter 13: Loading kernels: arm64 Image, initramfs and ELF
macvmm run --dry-run ...printed a full boot plan and exited 0 from a binary that lacks the hypervisor entitlement. What does that prove, and why is it worth designing for?Show answer
That planning makes no Hypervisor.framework call: without the entitlement,
hv_vm_createwould have failed withHV_DENIED. Keeping placement a pure computation means every overlap and bound can be printed, unit-tested and property-tested on any machine, and is checked before a VM exists.From chapter 09: A device is a state machine: the bus, PL011 and PL031
A guest reads the PL011's flag register
FRand gets0x90. May it write a byte toDRnow, and is there a byte for it to read?Show answer
0x90is bit 7 (TXFE, transmit FIFO empty) plus bit 4 (RXFE, receive FIFO empty). It may send: the transmit side is empty, so TXFF (full) is clear. There is nothing to read: RXFE says the receive FIFO is empty, and aDRread now would return 0.From chapter 09: A device is a state machine: the bus, PL011 and PL031
The host typed one letter,
a(0x61), and the guest reads the PL011'sDRtwice in a row. What does each read return, and why do they differ?Show answer
0x61, then 0. ADRread pops the receive FIFO: the first read removes the byte it returns, so the second finds the FIFO empty. A register whose read changes the device cannot be modelled as a stored value.From chapter 09: A device is a state machine: the bus, PL011 and PL031
IMSCis 0 when a byte arrives at the PL011. What doRISandMISread, and is the interrupt line high or low?Show answer
RIShas the receive bit (bit 4,0x10) set, and in our model the receive-timeout bit (bit 6) too: the device remembers that it wants attention.MISisRIS & IMSC= 0 and the line stays low: the mask says not to say so. SettingIMSCbit 4 later raises the line at once, because the condition still holds.From chapter 09: A device is a state machine: the bus, PL011 and PL031
The bus holds the PL011 at
0x0900_0000with size0x1000. What doesBus::insertanswer for a device at0x0900_0ff8with size0x10, and for one at0x0900_1000with size0x1000?Show answer
The first is refused with
BusError::Overlap: its first eight bytes fall inside the PL011's window. The second is accepted: it starts exactly where the PL011 ends, so the two windows are adjacent, not overlapping.From chapter 09: A device is a state machine: the bus, PL011 and PL031
A guest makes a 4-byte read at
0x0900_0ffe, two bytes below the end of the PL011's window. Which register does the PL011 see?Show answer
None. The access starts inside the window but runs past its end, so the bus answers
BusError::Straddleand the VMM treats it like an access to no device at all. No device ever sees a partial access, so no device has to reason about one.From chapter 09: A device is a state machine: the bus, PL011 and PL031
The guest stops reading its UART, and you keep typing. Why must the stdin thread's push into
SerialInputdrop bytes instead of waiting for room?Show answer
The same thread reads Ctrl-A x. If it blocked waiting for the guest, a guest that never reads would also stop the host from seeing the quit keys, and the user would lose every in-band way out. So
SerialInputholds 4 KiB, drops and counts the rest, and the thread goes straight back toread.From chapter 09: A device is a state machine: the bus, PL011 and PL031
You press Ctrl-A x in a running
macvmm, and in another run you send it SIGTERM. Which exit code do you get each time, and why that number?Show answer
130 both times. 130 is the shell's code for "ended by SIGINT" (128 + 2), and macvmm uses it for every user quit. A program killed by SIGTERM would report 143, but macvmm catches the signal, stops the VM cleanly and chooses its own code.
From chapter 09: A device is a state machine: the bus, PL011 and PL031
A guest prints the four bytes
ESC [ 6 nto the UART. What would your terminal do with them, and what does macvmm's output filter do?Show answer
They ask the terminal for the cursor position, and the terminal types its answer into the program's input, where the guest, or after macvmm exits your shell, would read it. The default (
safe) filter drops the sequence, so it never reaches the terminal.From chapter 09: A device is a state machine: the bus, PL011 and PL031
Why does the PL031 read the host's wall clock on every
RTCDRaccess instead of storing the boot time and adding the time elapsed since?Show answer
A monotonic clock such as Rust's
Instantstops while the Mac sleeps, so "boot time + elapsed" would fall behind the real date by every hour of sleep. Reading the wall clock each time stays right; the reference also never lets the value go backwards if the host clock is stepped back.From chapter 09: A device is a state machine: the bus, PL011 and PL031
A driver makes an 8-byte read of the PL011's
FR(offset0x18), then a 1-byte read of the same register. What does each return?Show answer
The 8-byte read returns 0, with a rate-limited warning: the PL011's registers are at most 32 bits wide, so that access names no register and is read-as-zero, write-ignored. The 1-byte read returns the low byte of
FR,0x90after reset: a narrow access at a register's offset reaches the register.From chapter 04: Guest memory: the only safe access is a copy
A guest asks the VMM to read 8 bytes at address
0xFFFF_FFFF_FFFF_FFFC. Guest RAM is0x4000_0000..0x4400_0000. Computeaddr + lenin 64-bit wrapping arithmetic, and say whether the checkaddr >= 0x4000_0000 && addr + len <= 0x4400_0000accepts the access.Show answer
The true sum is
0x1_0000_0000_0000_0004, which needs 65 bits; wrapped to 64 bits it is0x4. Both halves of the check pass (0xFFFF_FFFF_FFFF_FFFCis above the base,0x4is below the end), so a wrapping check accepts an access that starts 4 bytes below the top of the address space.checked_addreturnsNoneinstead, and the access is refused.From chapter 04: Guest memory: the only safe access is a copy
hv_vm_mapis asked to map 4 KiB of host memory at guest address0x4000_0000, which is 16 KiB-aligned. What does it answer on a Mac with the default configuration?Show answer
HV_BAD_ARGUMENT. The address is fine, but the size must be a whole number of 16 KiB host pages, because HVF's stage-2 table, the one that maps guest memory to ours, uses the Mac's 16 KiB page size by default.From chapter 04: Guest memory: the only safe access is a copy
A guest RAM made of two adjacent regions,
0x4000_0000(64 KiB) and0x4001_0000(64 KiB). Is an 8-byte read at0x4000_FFFCvalid, and why?Show answer
No. The range crosses from the first region into the second. The two regions are separate host allocations that only look contiguous to the guest, so one copy from a single host pointer would run off the end of the first allocation. An access must lie inside one region.
From chapter 04: Guest memory: the only safe access is a copy
Why does the
GuestMemorycontract have noget_slicethat returns a&[u8]into guest RAM?Show answer
A
&[u8]promises the compiler that nobody changes those bytes while the reference lives, and the compiler uses that promise (it may load a byte once and reuse the value, or load it twice and assume both loads agree). The guest, another vCPU or a device thread can change guest RAM at any moment, so the promise would be false. The contract hands out copies instead, and the VMM checks its own copy.From chapter 04: Guest memory: the only safe access is a copy
check_range(GuestAddress(0x4000_0000), 0)on a valid RAM region: true or false, and why does the contract choose that answer?Show answer
False. A zero-length range is never a valid access, so
readandwriterefuse an empty buffer too, andcheck_rangeis true exactly when the matchingreadwould succeed.From chapter 04: Guest memory: the only safe access is a copy
Name two things a volatile load guarantees and two things it does not.
Show answer
It guarantees that the compiler performs the load, at its size, every time the program says so, in program order relative to other volatile accesses, and never assumes the value is unchanged. It does not make an access of several elements atomic, and it gives no ordering or visibility guarantee towards other threads or the guest (that needs atomics and barriers, chapter 16). Volatile does not mean thread-safe.
From chapter 04: Guest memory: the only safe access is a copy
write_u32(GuestAddress(0x4000_0010), 0xdead_beef)succeeds. Which byte doesread_u8(GuestAddress(0x4000_0010))return, and why?Show answer
0xef. The helpers are little-endian, like the guest: the least significant byte of the value goes to the lowest address, so the bytes in memory areef be ad de.From chapter 04: Guest memory: the only safe access is a copy
A region table is given the region
base = 0xFFFF_FFFF_FFFF_C000, size = 0x8000. Both are 16 KiB multiples. Which construction rule rejects it, and what would go wrong without that rule?Show answer
The overflow rule:
base + sizepassesu64::MAX. Without it, the region's end would wrap to0x4000, and a test of the formaddr < endwould place the region's end in low memory, so the table would answer nonsense for addresses near zero.From chapter 04: Guest memory: the only safe access is a copy
Your VMM's bounds check uses
addr + lenwith Rust's default release settings, where overflow is not checked. A guest calls the memory-hash debug call withaddr = 0xFFFF_FFFF_FFFF_FFF0, len = 0x20. What happens, and what changes if overflow checks are on?Show answer
Without overflow checks the sum wraps to
0x10, the range test passes, and the VMM forms a host pointer far outside the RAM allocation: a guest-chosen read of host memory, unless a second check catches it. With overflow checks on, the addition panics, and the guest has crashed the VMM. Both are wrong: onlychecked_add, which turns the overflow into an ordinary error, keeps the VMM running and safe.
Concepts you'll need
Chapters before this one: chapter 16, Split virtqueues: shared memory with an adversary.
- Core, taught here: the trust boundaries of a virtual machine monitor (VMM) and a threat model; terminal injection in full; fuzzing (a seeded pseudo-random number generator, structure-aware mutation, a corpus, invariants, minimisation); the hostile guest; confining the VMM process after set-up.
- Core, from earlier: the guest as an adversary (chapter 04); virtqueues, the hop budget, TOCTOU and copy-then-validate (chapter 16); the output filter (chapter 09); containment and the opt-in
,learnpeer (chapter 19); UNDEF injection and exit codes (chapter 08); the reset limit and PSCI, the power state coordination interface (chapters 08, 14);DEVICE_NEEDS_RESET(chapter 15);CPU_ON(chapter 20); accesses whose instruction syndrome is not valid (ISV=0) and the injected abort (chapter 21). - Primers (read first):
macos-sandbox(Seatbelt, SBPL profiles,sandbox_init, the "checked when a resource is acquired" rule, rlimits and core dumps,umask,O_CLOEXEC, why the run path never forks). - Primers (review):
tty-termios(escape sequences, the terminal attack strings);codesign-entitlements(its "going deeper" parts: an entitlement is a permission, not a fence; the hardened runtime). - Pointers: STRIDE and
docs/security/threat-model.md(an Aside);cargo fuzzand coverage-guided fuzzing (an Aside); the confused deputy (one sentence and a link). - Forward definitions: none.
Outside two quarantined places (the hvf crate, which holds the hypervisor calls and a few host calls such as the sandbox, and the guest-memory mapping), our VMM forbids unsafe code. Now delete one line from chapter 16's descriptor-chain walker, the hop budget, and point a program that invents hostile virtqueues at it. Then plant a subtler bug that fires only when a chain holds three buffers and the first and third share an address. How long does an automatic search need for each?
Predict For the missing hop budget, and then for the three-buffer bug: will a fuzzer find it in about 10 seconds, about 10 minutes, or never?
Write both guesses, with one sentence of reasoning each, under ## Predict in your journal. Sitting A runs both plants with the reference's fuzzer; then you time your own fuzzer on the same two.
Chapter 00's problem ledger listed what a kernel assumes it owns. Every row is now closed, and each mechanism that closed one (exits, memory-mapped I/O (MMIO), rings, the console) is also a door the guest can push on. This chapter adds no row; it reads the ledger the other way round: every row is also an input the guest controls, so what can a guest that is trying to hurt us do with each one? Sitting A (about 3.5 hours) is the threat model, the reference's fuzzer, and your own fuzzer; sitting B (about 2.5 hours, at your Mac) is the hostile guest and the sandbox.
Objectives: by the end you can
- (Sitting A) Write a threat model for your VMM in STRIDE style (a six-letter checklist of threat kinds, below): assets, every trust boundary, what each attacker can do. Cross-check it against the reference's
docs/security/threat-model.md. - (Sitting A) Build a dependency-free fuzz harness (a seeded generator, structure-aware mutation of descriptor chains, invariants checked after every input) that runs device models on the host, find each planted bug in the queue code, and minimise each reproducer.
- (Sitting B) Run the hostile guest's eight attack phases (MMIO, ISV=0, system registers, SMCCC (SMC calling convention, where SMC is the Secure Monitor Call instruction) calls, virtqueues with a live time-of-check-to-time-of-use (TOCTOU) race, terminal strings, a reset storm, an output flood) and explain each expected exit code.
- (Sitting B) Confine the process after set-up with a sandbox that is on by default (
--no-sandboxopts out), setRLIMIT_COREto 0, and measure what the sandbox denies.
Before you start. From the repository root, run scripts/learner start 25; it copies this chapter's journal to learner/journal/25.md, "your journal" below. There is no starter code: you create learner/crates/fuzz/ and learner/crates/macvmm/src/sandbox.rs in Your turn.
Memory-safe is not the same as safe
The tempting belief is "Rust is memory safe, so a Rust VMM is secure". forbid(unsafe_code) rules out reading past a buffer, using freed memory, a race that tears a value in half. It cannot rule out a program that is memory safe and wrong. Five classes survive, each with a candidate in our VMM:
| Class | What the guest controls | An instance in our VMM |
|---|---|---|
| logic bug | the numbers we check | a range check that adds addr + len with wrapping arithmetic (chapter 04) |
| resource exhaustion | how much work it asks for | a --trace file the guest could grow without bound, had it no size cap |
| infinite loop | the shape of a data structure | a descriptor whose next points at itself (chapter 16) |
| TOCTOU (time of check to time of use) | the bytes between our two reads | a descriptor len read once to check and again to use (chapter 16) |
| confused deputy | a name we act on with our rights | a --serial file: path (chapter 09) that names the guest's own disk image |
A confused deputy is a privileged program tricked into using its rights for someone else (Hardy, 1988). Our VMM can open any file you can, so a path handed over for one purpose must never serve another.
None of these is a crash. The worst return Ok with a wrong answer, so a test that only asks "did it panic?" finds none of them.
A threat model on one page
Before hunting bugs, decide what you are protecting and from whom. Writing that down is a threat model. It has three parts.
Assets, what an attacker wants: your user account (files, keys, shell), your terminal, the VMM process itself (it holds guest RAM and open disk images), the disk images and the files near them, and the Mac's CPU, memory and disk space.
Trust boundaries, where data crosses from someone you trust less to someone you trust more:
guest (hostile) macvmm process (your rights) host+--------------+ traps into +--------------------------+ writes to +---------------+| guest kernel | ---------> | exit decode, devices, | --------> | your terminal || and its apps | | GuestMemory copies, | +---------------+| | =========> | loaders, CLI | <-------- | your files, |+--------------+ shares RAM +--------------------------+ reads | .cache/macvmm | with ^ +---------------+ | plant links for, ^ | connect to | downloads into +-------------------+ +---------------+ | other local users | | internet | +-------------------+ +---------------+Each row below is an arrow; the guest has two, because it reaches us by trapping and through shared RAM.
| Boundary | Who is distrusted | What crosses |
|---|---|---|
| guest to VMM | the guest, fully | every register on an exit, every MMIO value, every byte of guest RAM, at any moment |
| VMM to terminal | the guest's output | serial and console bytes, which can be escape sequences: terminal injection |
| host files to VMM | the file's content | Image, ELF, initramfs and disk bytes (you chose the path, not what is inside) |
| internet to cache | the download | anything until its sha256 matches the pinned value |
| other users to VMM | other accounts on the Mac | planted symlinks, world-readable outputs, connections to sockets |
Attackers and their capabilities. The malicious guest runs any code at exception level 1 (EL1, the guest kernel's level) on every virtual CPU (vCPU) at once, rewrites RAM while we read it, traps as often as it likes and chooses every value it hands us; stage 2 keeps it out of host memory. A malicious file can be any bytes. Another local user can create files and symbolic links in shared directories such as /tmp before macvmm does, and connect to any socket macvmm leaves open to everyone; the umask 077 below and opens that never follow a symbolic link answer that (see the next paragraph). A network attacker on the download path can serve any bytes; the pinned sha256 answers that. A compromised VMM is what you get if any of them succeeds: code running as you, with the hypervisor entitlement and every file descriptor macvmm holds. Sitting B shrinks that last one.
Chapter 10 promised to explain why the reference's open_output (in crates/vmm/src/backend/hostio.rs), which opens every file macvmm writes, checks more than "no symbolic link". Each check answers one of the attackers above. It resolves the directory you named once (a link you typed, such as /tmp, is your intent), then opens the file with a flag that refuses a symbolic link anywhere in that path, so a link planted as the file's name, or swapped in afterwards, is refused. It requires a regular file owned by you, so a file another user planted at the name is refused rather than written. It requires a link count of 1, because macOS lets any user make a hard link (a second name for the same file) to a file they do not own: a hard link to one of your files, planted in /tmp, passes the owner check, and writing through it would empty the original. It refuses a file that is already open as an input or output, the confused-deputy row of the table above: --serial file: naming the guest's own disk image. Only after every check passes does it empty the file.
STRIDE is a checklist so no kind of threat is forgotten. Each letter is a kind of threat: Spoofing (pretending to be someone else), Tampering (changing data you rely on), Repudiation (doing something and denying it), Information disclosure (reading what you should not), Denial of service (making the VMM stop or crawl), Elevation of privilege (gaining rights you were not given). Walk each boundary through the six letters and write the mitigation, or "n/a", next to each. One row, worked:
guest to VMM S n/a: the guest is the only party on this boundary T rewrites descriptors mid-walk -> copy-then-validate (chapter 16) R n/a: we do not hold the guest to account I reads past its buffer -> bounds-checked GuestMemory (chapter 04) D a descriptor chain that loops -> the hop budget (chapter 16) E runs code inside macvmm -> the sandbox, on by default (sitting B)Aside
STRIDE comes from Microsoft (their description). The reference's docs/security/threat-model.md has a STRIDE table naming each surface and mitigation; its row tags (VQ-5, MEM-7, SBX-2 and so on) reappear in the reference's code and messages below.
Write yours now in learner/docs/security/threat-model.md: the assets, the boundary table, five attackers with one paragraph each, and a STRIDE row for each of the other four boundaries. It is the evidence for journal question 2.
Let a program write the hostile inputs
Chapter 16's hostile tests are cases someone thought of; the bugs that survive are the ones nobody did. So let a program build millions of slightly wrong inputs, run the real code on each, and check that nothing went wrong. That is fuzzing. Five decisions turn the idea into a tool; the reference's crates/fuzz/ depends only on the workspace's own crates (vmm and xtask).
Randomness you can replay. A bug found once and never again is useless, so inputs come from a seeded PRNG (pseudo-random number generator): arithmetic that turns a starting number, the seed, into a random-looking stream, identical on every run. Ours is xorshift64*, three shifts and a multiply:
/// The next 64 random bits.pub fn next_u64(&mut self) -> u64 { let mut x = self.0; x ^= x >> 12; x ^= x << 25; x ^= x >> 27; self.0 = x; x.wrapping_mul(0x2545_f491_4f6c_dd1d)}Iteration i derives its own generator from the seed and i, so iteration 23,338,941 could be regenerated from those two numbers alone, without the 23 million before it. In practice the saved input replays it (below); a --start N flag would be a small addition to your own fuzzer:
/// A generator derived from `(seed, stream)`, so iteration `n` of a run can be regenerated/// without replaying iterations `0..n`. SplitMix64's finalizer decorrelates the two.pub fn derive(seed: u64, stream: u64) -> Rng { let mut z = seed ^ stream.wrapping_mul(0x9e37_79b9_7f4a_7c15); z = (z ^ (z >> 30)).wrapping_mul(0xbf58_476d_1ce4_e5b9); z = (z ^ (z >> 27)).wrapping_mul(0x94d0_49bb_1331_11eb); Rng::new(z ^ (z >> 31))}A target is a function of bytes. Each fuzz target decodes bytes into an input for one parser or device model, runs the real code against test doubles (chapter 04's VecMemory RAM, a fake interrupt line), and reports a verdict. It also knows how to build a well-formed input and how to damage one:
/// `Ok` if every invariant held, else a description of the first violation.pub type Verdict = Result<(), String>;/// One fuzz target.pub struct Target { /// The name on the command line (`cargo run -p fuzz -- <name>`). pub name: &'static str, /// Run one input and check the invariants. pub run: fn(&[u8]) -> Verdict, /// A random *well-formed* input: the starting point the mutators corrupt. pub seed: fn(&mut rng::Rng) -> Vec<u8>, /// Target-specific structural mutation (descriptor shapes, MMIO op fields, ...). pub mutate: fn(&mut rng::Rng, &mut Vec<u8>), /// Inputs are truncated to this length. pub max_len: usize,}No Hypervisor.framework: the virtqueue target drives the device worker's own Queue::pop, into_validated and add_used on the host.
Invariants, not only panics. The invariants are the test oracle, the part that decides pass or fail: properties that must hold after every input. The virtqueue target checks five:
- No panic, and a ring error marks the queue broken.
- Bounded work: at most
2N + 1descriptor reads per pop, for a queue ofNentries. The hop budget allowsNreads in the main table and restarts for one indirect table of at mostNentries; the+ 1is one read of slack. - Each descriptor of a validated chain was read once; a second read is a double fetch.
- Every validated buffer lies inside one RAM region, and each direction's total is within the cap.
- The device writes only into the chain's writable buffers and the used ring.
Messages carry the tag of a row of the reference's threat model: invariant 2 reports as VQ-5, 3 as MEM-7, 4 as VQ-4 and 5 as VQ-9. Here are invariants 3 and 4. Invariant 4 adds address and length in 128-bit arithmetic, so the check itself cannot overflow:
/// Invariant 3: no address appears twice.pub fn read_once(reads: &[u64]) -> Result<(), String> { let mut seen = reads.to_vec(); seen.sort_unstable(); match seen.windows(2).find(|w| w.first() == w.get(1)) { Some(w) => Err(format!( "descriptor at {:#x} read twice in one pop (double fetch, MEM-7)", w.first().copied().unwrap_or(0) )), None => Ok(()), }}/// True if `[addr, addr + len)` lies inside a single region, computed in `u128` so that the/// check itself cannot overflow (the reference model the code under test is compared with).pub fn in_one_region(addr: u64, len: u64) -> bool { let (a, l) = (u128::from(addr), u128::from(len)); REGIONS.iter().any(|&(b, s)| { let (b, s) = (u128::from(b), u128::from(s)); l > 0 && a >= b && a + l <= b + s })}The fuzz RAM has two regions and a hole on purpose: "inside one region" can only fail, and so be tested, when there are two. We write a buffer as address+length, so 0x40008000+16 means 16 bytes starting at 0x40008000:
0x4000_0000 region A, 256 KiB: descriptor table 0x4000_1000, avail ring 0x4000_2000, used ring 0x4000_3000, indirect table 0x4000_4000, buffers from 0x4000_80000x4004_0000 the hole, 256 KiB of not-RAM0x4008_0000 region B, 64 KiB: more buffers0x4009_0000 end of RAMHow do bytes become a ring? The input has fixed offsets, so the mutations below know where each descriptor sits:
//! **Input** (fixed offsets, so the structural mutators know where descriptors are)://!//! | Bytes | Field |//! |---|---|//! | 0 | queue size: `1 << (b % 9)`, 1..=256 |//! | 1 | bit 0 `INDIRECT_DESC` negotiated, bit 1 rings packed at the end of region B, bit 2 `avail.flags = NO_INTERRUPT` |//! | 2..4 | avail entries published per round (more than the size is an index jump, which must reset the queue) |//! | 4 | `max_total` (the per-direction byte cap): 64 KiB, 4 KiB, 1 MiB or 4 GiB |//! | 5 | rounds: the driver republishes `1 + b % 4` times, so `used.idx` wraps the ring |//! | 8..520 | the 256 avail-ring entries |//! | 520.. | the descriptor table (256 × 16 bytes), then a 64-entry indirect table |Byte 0 picks the queue size, byte 1 the options, bytes 8 onwards are the avail-ring entries (the heads of the chains the driver offers), and from byte 520 come 16-byte descriptors, each laid out as chapter 16's descriptor (address, length, flags, next). When you design your own target, choose your own layout or copy this one. The target writes those bytes into the fuzz RAM as rings, then runs them:
/// Run one ring (module docs for the input and the invariants).pub fn run(data: &[u8]) -> crate::Verdict { let spec = Spec::decode(data); let mem = ram()?; write_rings(&spec, data, &mem)?; let mut q = spec.queue(); // Invariant 2: the hop budget is N per table, and an indirect table has at most N entries. let max_reads = 2 * usize::from(spec.size) + 1; let mut completed: u16 = 0; for round in 0..spec.rounds { let idx = spec.per_round.wrapping_mul(round.wrapping_add(1)); mem.write_u16(GuestAddress(spec.avail + 2), idx) .map_err(|e| format!("avail.idx: {e:?}"))?; for _ in 0..=spec.size { mem.enable_log(); // the access log of this one pop let chain = match q.pop(&*mem) { Ok(None) => break, Ok(Some(c)) => c, Err(_) if q.is_broken() && q.pop(&*mem).is_err() => return Ok(()), // latched: stays broken until reset Err(_) => return Err("a ring error did not latch the queue as broken".into()), }; let validated = chain.into_validated(spec.max_total); let reads = descriptor_reads(&mem.log()); if reads.len() > max_reads { return Err(format!( "{} descriptor reads for one pop of a size-{} queue (VQ-5 hop budget)", reads.len(), spec.size )); } let Ok(v) = validated else { return Ok(()); // the device would set NEEDS_RESET here }; read_once(&reads)?; // invariant 3: each descriptor read once chain_in_ram(&v, spec.max_total)?; // invariant 4: in RAM, under the cap match complete(&spec, &mem, &mut q, &v, completed)? { Some(c) => completed = c, None => return Ok(()), } } } Ok(())}Mutation that knows the shape. Random bit flips mostly give chains that die at the first check (next out of range). The structure-aware mutation knows where the 16-byte descriptors are and damages them as an attacker would: next pointing back, or a length that ends a few bytes into a region, often the other one. rec is the byte offset of descriptor i; ADDR, LEN, FLAGS and NEXT are field offsets, and F_NEXT is the NEXT flag:
1 => { // A back edge: next = some j <= i, with NEXT set. let j = rng.index(i + 1); put_le(buf, rec + NEXT, 2, j as u64); let flags = get_le(buf, rec + FLAGS, 2) | F_NEXT; put_le(buf, rec + FLAGS, 2, flags);}2 => { let addr = get_le(buf, rec + ADDR, 8); let len = match rng.below(4) { 0 => 0, 1 => u64::from(u32::MAX), 2 => 0x8000_0000, // End a few bytes into another region (crossing the hole between them). _ => { let target = ram .regions .get(rng.index(ram.regions.len())) .map_or(0, |&(b, s)| b.wrapping_add(rng.below(s.clamp(1, 64)))); target.wrapping_sub(addr).wrapping_add(1) & 0xffff_ffff } }; put_le(buf, rec + LEN, 4, len);}Another move aims the address at the edges, the "specials": the last bytes of a region, the hole, a device window, the rings themselves:
3 => { let addr = match rng.below(4) { // The last few bytes of a region. 0 => ram .regions .get(rng.index(ram.regions.len())) .map_or(0, |&(b, s)| { b.wrapping_add(s).wrapping_sub(1 + rng.below(32)) }), // Just past a region's end (the hole, or beyond RAM). 1 => ram .regions .get(rng.index(ram.regions.len())) .map_or(0, |&(b, s)| b.wrapping_add(s).wrapping_add(rng.below(16))), 2 => ram .specials .get(rng.index(ram.specials.len())) .copied() .unwrap_or(0), _ => rng.pick(&INTERESTING_U64).unwrap_or(0), }; put_le(buf, rec + ADDR, 8, addr);}An input generator instead of a stored corpus. Fuzzers usually damage a corpus, a set of good inputs. Ours draws a fresh well-formed ring each iteration (one to four buffers per chain, readable before writable, some indirect; the target's seed function, not the PRNG's seed), then damages it up to eight times, each step, by coin toss, a structure-aware move or a byte-level mutation (a bit flip, a random byte, a boundary integer such as 0xffff_ffff):
/// Fuzz one target; returns the number of failures (0 or 1: the run stops at the first).fn fuzz(t: &'static Target, o: &Opts, watch: &Watch, epoch: Instant) -> u64 { let deadline = Instant::now() + Duration::from_secs(o.seconds); if let Ok(mut n) = watch.name.lock() { *n = t.name; } let mut iters = 0u64; while iters < o.iters && Instant::now() < deadline { let mut rng = Rng::derive(o.seed, iters); let mut input = (t.seed)(&mut rng); let rounds = rng.below(9); for _ in 0..rounds { if rng.coin() { (t.mutate)(&mut rng, &mut input); } else { fuzz::mutate::bytes(&mut rng, &mut input, t.max_len); } } input.truncate(t.max_len); if let Ok(mut w) = watch.input.lock() { w.clone_from(&input); } watch.iter.store(iters, Ordering::SeqCst); watch.started_ms.store(now_ms(epoch), Ordering::SeqCst); let r = run_one(t, &input); watch.started_ms.store(u64::MAX, Ordering::SeqCst); iters += 1; if let Err(e) = r { let saved = save(t.name, o.seed, iters - 1, &input); say(&format!( "fuzz {}: FAILURE at iteration {} (seed {}): {e}", t.name, iters - 1, o.seed )); say(&format!( "fuzz {}: input saved to {} (replay: cargo run -p fuzz --release -- {} --replay FILE)", t.name, saved.map_or("<not saved>".into(), |p| p.display().to_string()), t.name )); say(&format!("fuzz {}: {iters} iterations, 1 failures", t.name)); return 1; } } say(&format!("fuzz {}: {iters} iterations, 0 failures", t.name)); 0}A failing input is saved (mode 0600, never overwriting) and becomes a regression test. Safe Rust cannot interrupt a hang, so a watchdog thread saves any input that runs over two seconds and exits with HANG.
Aside
Our fuzzer is blind: it never learns which inputs reached new code. A coverage-guided fuzzer does, and keeps mutating those. cargo fuzz drives one, libFuzzer (the Rust Fuzz Book); it needs a nightly compiler, so it stays optional here, and every target is exported as fuzz_<target>(&[u8]) for it.
The lab brings the fuzzer to your browser:
Hostile-ring fuzzer
Patch one of chapter 25's planted bugs into chapter 16's queue code, let a seeded fuzzer invent hostile descriptor rings, and see which invariant catches the first failing input.
Runs in browserOpen full page: Hostile-ring fuzzerLoading the lab. If nothing appears, your browser may have JavaScript turned off or the lab failed to load.
If it does not load, nothing is lost: it mutates chains for chapter 16's queue model and stops at the first input that breaks an invariant.
Ten seconds, or never?
The plants are patches in crates/fuzz/planted/, written against the reference's chain.rs and queue.rs, so they will not apply to your own walker. To run one, copy the reference, patch the copy, and fuzz it. Use one fresh copy per plant, and never patch a copy twice: a second patch either fails or stacks two bugs. From the repository root:
P=02-chain-no-hop-budgetrsync -a --exclude /target --exclude /.cache --exclude /.git --exclude /learner ./ "$TMPDIR/$P/"cd "$TMPDIR/$P" && patch -p1 < "crates/fuzz/planted/$P.patch"cargo run -q --release -p fuzz -- virtqueue --seconds 600cd -The leading / makes each --exclude skip only the top-level directory of that name; without it, rsync also drops the course tooling's own learner module, and the copy does not build. The first run in a copy builds the workspace in release mode before fuzzing, so judge the fuzzer by its iteration count, not your stopwatch. cd - returns you to the repository root.
This plant deletes the hop-budget decrement. With the default seed, 1, you should see our iteration numbers on any Mac; the seconds depend on the machine, and --seed 2 gives other numbers. (Most of our runs used --seconds 590 so they fit our recording tool's ten-minute limit; use 600. /usr/bin/time -p adds the real/user/sys lines.) Check your Predict entry, then our run:
/usr/bin/time -p cargo run -q --release -p fuzz -- virtqueue --seconds 590fuzz virtqueue: FAILURE at iteration 7 (seed 1): 2838 descriptor reads for one pop of a size-2 queue (VQ-5 hop budget)fuzz virtqueue: input saved to <tree>/crates/fuzz/../../target/fuzz/crashes/virtqueue-seed1-iter7-0.bin (replay: cargo run -p fuzz --release -- virtqueue --replay FILE)fuzz virtqueue: 8 iterations, 1 failuresreal 0.30user 0.02sys 0.02Iteration 7, under a second, and not a hang. The saved input is a two-entry queue whose second descriptor points at itself. The walk went round it until the chain's total passed its 64 KiB cap and the walker gave up by itself; only invariant 2 noticed that 2,838 reads for a two-entry queue is a loop. One check (the byte cap) covering for a missing one (the hop budget) is defence in depth, and here it hid the bug from everything except the invariant.
The second plant, 05-chain-verdict-cache.patch, adds a "verdict cache": a buffer at the same address as the buffer two hops earlier skips the RAM check, whatever its length:
/usr/bin/time -p cargo run -q --release -p fuzz -- virtqueue --seconds 590fuzz virtqueue: FAILURE at iteration 23338941 (seed 1): validated buffer 0x40003000+0x80000000 is not inside one RAM region (VQ-4)fuzz virtqueue: input saved to <tree>/crates/fuzz/../../target/fuzz/crashes/virtqueue-seed1-iter23338941-0.bin (replay: cargo run -p fuzz --release -- virtqueue --replay FILE)fuzz virtqueue: 23338942 iterations, 1 failuresreal 128.07user 67.37sys 58.07Iteration 23,338,941, after 128 seconds. The failing buffer, 0x40003000+0x80000000, starts at the used ring, one of the specials. Two descriptors two hops apart had to receive the same special address; drawn from all 2^64 addresses, they would essentially never match. Structure made the search possible. Would coverage guidance make it shorter? We did not measure that; it is worth asking which new code path a coverage-guided fuzzer would see first. Write our two times in your journal; you add your own fuzzer's times in Your turn.
The saved input replays, as it must:
cargo run -q --release -p fuzz -- virtqueue --replay target/fuzz/crashes/virtqueue-seed1-iter23338941-0.binfuzz virtqueue: replay FAILED: validated buffer 0x40003000+0x80000000 is not inside one RAM region (VQ-4)It is 5,640 bytes, of which 162 are not zero (wc -c, before and after deleting the zero bytes with tr -d '\000'), and most of those are unrelated to the bug. Minimising a reproducer means finding the smallest input that still fails, so a human can read the cause: repeatedly zero or delete a chunk (halves, then quarters, down to single bytes), keep each change after which the replay still fails, and stop when none does.
You write the minimiser in Your turn; the reference has none yet. So we built by hand what one aims for, from the input layout above: one chain of three buffers, readable 0x40008000+16, writable 0x40009000+16, writable 0x40008000+0x40000, which runs off the end of region A. It ships as crates/fuzz/planted/05-three-buffers.bin: 568 bytes (the header, the avail entries and three descriptors), 17 of them not zero. It fails against the planted copy, and passes against the unmodified reference:
cargo run -q --release -p fuzz -- virtqueue --replay crates/fuzz/planted/05-three-buffers.binfuzz virtqueue: replay FAILED: validated buffer 0x40008000+0x40000 is not inside one RAM region (VQ-4)cargo run -q --release -p fuzz -- virtqueue --replay crates/fuzz/planted/05-three-buffers.binfuzz virtqueue: replay OKBreaking it on purpose
The other plants are the chapter's mandatory breaks. Run each in its own fresh copy, with the recipe above and P set to the plant's name.
Deliberate breakage 1: drop the checked_add. 01-chain-range-no-checked-add.patch checks a buffer's first and last byte separately, computed with wrapping arithmetic, instead of the span. Predict: which invariant fires, and does any single byte of the buffer lie outside RAM?
cargo run -q --release -p fuzz -- virtqueue --seconds 600fuzz virtqueue: FAILURE at iteration 250 (seed 1): validated buffer 0x4002e6e9+0x5193a is not inside one RAM region (VQ-4)fuzz virtqueue: input saved to <tree>/crates/fuzz/../../target/fuzz/crashes/virtqueue-seed1-iter250-0.bin (replay: cargo run -p fuzz --release -- virtqueue --replay FILE)fuzz virtqueue: 251 iterations, 1 failures0x4002e6e9+0x5193a ends at 0x40080023: first byte in region A, last in region B, the hole between them not RAM. Each endpoint passed; the span did not. The plant removes two checks, the checked_add and the span check, and the fuzzer hit the second. In this machine it can only ever hit the second. A length is 32 bits and all RAM lies below 0x4009_0000, so a sum that wraps past 2^64 must start above 2^64 − 2^32. No RAM is there, and the first-byte check refuses it. Predict, then check it in your patched copy: a descriptor at 0xffff_ffff_ffff_fff0 with length 0x40000020 wraps to 0x40000010, inside RAM, yet it is refused at its first byte. The checked_add earns its place when RAM sits near the top of the address space, or when a length is 64 bits wide. The misconception: "checking both ends checks the range". The tool: invariant 4, computed independently in wider arithmetic.
Deliberate breakage 2: an off-by-one in the ring index. 03-used-idx-off-by-one.patch computes the used-ring slot as next_used % (N + 1) instead of % N. Predict: what does the device write, and where?
cargo run -q --release -p fuzz -- virtqueue --seconds 590fuzz virtqueue: FAILURE at iteration 22 (seed 1): device wrote 0x40003014+8 outside the writable buffers and the used ring (used ring 0x40003000+0x16; VQ-9)fuzz virtqueue: input saved to <tree>/crates/fuzz/../../target/fuzz/crashes/virtqueue-seed1-iter22-0.bin (replay: cargo run -p fuzz --release -- virtqueue --replay FILE)fuzz virtqueue: 23 iterations, 1 failuresA two-entry used ring at 0x40003000 is 0x16 bytes: flags, index, 8-byte elements at +4 and +12, and the 2-byte avail_event at +0x14 (chapter 16). Slot 2 lands at +0x14: over avail_event and six bytes past the ring's end. The misconception: "an index bug only corrupts the guest's own ring". The tool: invariant 5, the audit of every device write.
Try it
04-desc-len-double-fetch.patch re-reads a descriptor after validating it and keeps the second len. The plain target catches it from the access log (invariant 3). The hidden virtqueue_race_only variant has no log, only a second thread rewriting lengths during the walk, so it finds the bug only by winning the race. Run it twice with the same seed: ours failed once at iteration 87,420 and once, in the self-test below, at 2,025. A race does not replay from a seed.
The reference's self-test, scripts/bughunt-selftest.sh, runs plants 1 to 4, each in a private copy, and requires each to be found within the time limit (ten minutes by default; two in this run). It counts the double fetch too, so it ends with 4/4:
scripts/bughunt-selftest.sh --minutes 2 --allow-concurrent-editsbughunt-selftest: bug 1 (01-chain-range-no-checked-add.patch): building the fuzzer against the planted copybughunt-selftest: bug 1: fuzzing 'virtqueue' for up to 2 min (seed 1)bughunt-selftest: bug 1 FOUND by virtqueue after 0s: fuzz virtqueue: FAILURE at iteration 250 (seed 1): validated buffer 0x4002e6e9+0x5193a is not inside one RAM region (VQ-4)bughunt-selftest: bug 2 (02-chain-no-hop-budget.patch): building the fuzzer against the planted copybughunt-selftest: bug 2: fuzzing 'virtqueue' for up to 2 min (seed 1)bughunt-selftest: bug 2 FOUND by virtqueue after 0s: fuzz virtqueue: FAILURE at iteration 7 (seed 1): 2838 descriptor reads for one pop of a size-2 queue (VQ-5 hop budget)bughunt-selftest: bug 3 (03-used-idx-off-by-one.patch): building the fuzzer against the planted copybughunt-selftest: bug 3: fuzzing 'virtqueue' for up to 2 min (seed 1)bughunt-selftest: bug 3 FOUND by virtqueue after 0s: fuzz virtqueue: FAILURE at iteration 22 (seed 1): device wrote 0x40003014+8 outside the writable buffers and the used ring (used ring 0x40003000+0x16; VQ-9)bughunt-selftest: bug 4 (04-desc-len-double-fetch.patch): building the fuzzer against the planted copybughunt-selftest: bug 4: fuzzing 'virtqueue' for up to 2 min (seed 1)bughunt-selftest: bug 4 FOUND by virtqueue after 0s: fuzz virtqueue: FAILURE at iteration 4 (seed 1): descriptor at 0x4008ff80 read twice in one pop (double fetch, MEM-7)bughunt-selftest: bug 4: fuzzing 'virtqueue_race_only' for up to 2 min (seed 1)bughunt-selftest: bug 4 FOUND by virtqueue_race_only after 0s: fuzz virtqueue_race_only: FAILURE at iteration 2025 (seed 1): validated buffer 0x400095e0+0xffffffff is not inside one RAM region (VQ-4)bughunt-selftest: working tree unchanged (git status --porcelain identical)bughunt: 4/4 planted bugs foundDescriptor chains are one hostile input; the reference has 21 more targets: the MMIO register files, the Image, ELF and initramfs loaders, the blk device and the output filter among them (scripts/fuzz.sh all --seconds 2 runs each for a two-second smoke test; all 22 passed on our Mac). The virtio-mmio target decodes its bytes as a sequence of guest register accesses, 11 bytes each, and checks after every write that no queue register changed while the queue was ready:
let mut input = Input::new(data);let mut steps = 0;while !input.is_empty() && steps < 256 { steps += 1; let kind = input.u8(); let offset = u64::from(input.u16()) % 0x200; let value = input.u64(); let size = size_of(kind); let before = [snapshot(&t, 0), snapshot(&t, 1)]; if kind & 1 == 1 { t.write(offset, size, value); for (i, b) in before.iter().enumerate() { if let (Some(b), Some(a)) = (b, snapshot(&t, i)) && *b != a { return Err(format!( "queue {i} changed while ready ({b:?} -> {a:?}) by a write of {value:#x} \ at {offset:#x} (VQ-14)" )); } } } else { let _ = t.read(offset, size); }Before you stop, do Your turn items 1 to 4 (the crate, the virtqueue target, the minimiser, the plants), and check that cargo run -q --release -p fuzz -- virtqueue --seconds 20 --seed 1 exits 0 from inside learner/.
Good place to stop. Sitting B needs your Mac and about 2.5 hours.
The hostile guest
Since chapter 00, "a hostile guest" has meant any guest that misbehaves on purpose, the malicious guest above. Here it is also a program you run. The hostile guest suite attacks the real VMM from inside a virtual machine: bare-metal guests in guests/hostile-*, each a phase with an exit code the VMM must end with. A VMM survives by turning every misdeed into a guest-visible answer (an exception, -1 in x0, DEVICE_NEEDS_RESET) or a defined stop; exit code 1, a VMM error, caused by a guest is always a bug.
| Phase (guest) | The attack | Expected outcome |
|---|---|---|
MMIO sweep (hostile-mmio) | every device window, width and byte offset, then 20,000 random accesses | exit 0 with --unhandled-mmio log; unknown registers read as zero |
ISV=0 garbage (hostile-isv0) | load and store pairs across a device boundary, SIMD (single instruction, multiple data: vector-register) stores | exit 0; an abort injected each time |
system registers (hostile-sysreg) | all 16,384 S3_* encodings read; each whose read was UNDEF is then written (the Generic Interrupt Controller (GIC) CPU-interface block is skipped) | exit 0; a value or an UNDEF each time |
SMCCC garbage (hostile-smp, 4 vCPUs) | 12,000 random calls, then a CPU_ON storm | exit 0; -1 for every unknown call |
virtqueues (hostile-vq, hostile-smp) | loops, rings at the end of RAM, index jumps, a second vCPU rewriting descriptors | exit 0; DEVICE_NEEDS_RESET, then recovery |
terminal strings (hostile-tty) | 22 attack strings: title, clipboard, queries | exit 0; no escape sequence reaches stdout |
reset storm (hostile-reset) | SYSTEM_RESET on every boot | exit 3 (guest fatal) within 10 s |
output flood (hostile-flood) | 4 MiB into --serial file:F,max=1M, a file capped at 1 MiB | exit 0; the file holds exactly 1 MiB |
The phases exercise chapters 17 (virtio-rng), 18 (a read-only virtio-blk disk), 20 (several vCPUs) and 21 (accesses with ISV=0); if your VMM lacks one, that phase cannot pass. As a reminder: an UNDEF is an undefined-instruction exception, CPU_ON starts another vCPU, and the abort (a synchronous external abort) is what a real bus gives for an access the VMM will not decode: errors the guest can handle.
Run the phases from inside learner/, so cargo run builds your VMM, with G set as in chapter 09. Our captures ran from the repository root, so their paths start at target/; from learner/, prefix them with ../. Each phase is one guest run, and each capture shows its flags:
G=../target/guests/aarch64-unknown-none/releasecargo run -q -p macvmm -- run --mem 64M --testdev --kernel $G/hostile-isv0 --timeout 10cargo run -q -p macvmm -- run --mem 64M --testdev --kernel target/guests/aarch64-unknown-none/release/hostile-isv0 --timeout 10hostile-isv0: 15/15 external abortshostile-isv0: device state intacthostile-isv0: phase 2 okmacvmm: warn: [vcpu0] guest: vcpu0: ISV=0 write at 0xb000ff8 pc 0x400811c8 not emulated (pair is not inside one device window (first 0xb000000, second none)): injecting a synchronous external abortmacvmm: warn: [vcpu0] guest: vcpu0: ISV=0 read at 0xb000ff8 pc 0x4008128c not emulated (pair is not inside one device window (first 0xb000000, second none)): injecting a synchronous external abortmacvmm: warn: [vcpu0] guest: vcpu0: ISV=0 write at 0xb000ffc pc 0x40081364 not emulated (pair is not inside one device window (first 0xb000000, second none)): injecting a synchronous external abortmacvmm: warn: [vcpu0] guest: vcpu0: ISV=0 write at 0xa0001f8 pc 0x400813fc not emulated (pair is not inside one device window (first 0xa000000, second 0xa000200)): injecting a synchronous external abortmacvmm: warn: [vcpu0] guest: vcpu0: ISV=0 read at 0xa0001f8 pc 0x40081498 not emulated (pair is not inside one device window (first 0xa000000, second 0xa000200)): injecting a synchronous external abortmacvmm: warn: [vcpu0] guest: vcpu0: ISV=0 write at 0xa0001fc pc 0x40081568 not emulated (pair is not inside one device window (first 0xa000000, second 0xa000200)): injecting a synchronous external abortmacvmm: warn: [vcpu0] guest: vcpu0: ISV=0 write at 0xb000ff8 pc 0x4008160c not emulated (second element at 0x9000000, expected 0xb001000): injecting a synchronous external abortmacvmm: warn: [vcpu0] guest: vcpu0: ISV=0 read at 0xb000ff8 pc 0x400816a0 not emulated (second element at 0x9000000, expected 0xb001000): injecting a synchronous external abortmacvmm: warn: [vcpu0] guest: vcpu0: ISV=0 write at 0xb000fe0 pc 0x40081770 not emulated (unsupported: simd-fp): injecting a synchronous external abortmacvmm: warn: [vcpu0] guest: vcpu0: ISV=0 write at 0xb000fe8 pc 0x40081808 not emulated (unsupported: simd-fp): injecting a synchronous external abortAll 15 attempts came back as aborts, and the device kept its state. The MMIO sweep needs --unhandled-mmio log, because it probes addresses where no device lives; under the default policy, fatal, the first such access ends the run with exit 3. The stray characters are bytes written into the data register of the UART (the universal asynchronous receiver-transmitter, our PL011):
cargo run -q -p macvmm -- run --mem 64M --testdev --unhandled-mmio log --kernel target/guests/aarch64-unknown-none/release/hostile-mmio --timeout 60lOhostile-mmio: swept pl011 (0x1000 bytes)hostile-mmio: swept pl031 (0x1000 bytes)hostile-mmio: swept virtio-mmio (0x4000 bytes)hostile-mmio: swept testdev (0x1000 bytes)hostile-mmio: swept gicr-unused (0x1000 bytes)hostile-mmio: swept probe-hole (0x100 bytes)��hostile-mmio: 284192 accesses, 150926 alignment faults, 0 other data abortshostile-mmio: survivedmacvmm: warn: [vcpu0] guest: pl011: 8-byte read at offset 0x0 names no register (read as zero)macvmm: warn: [vcpu0] guest: pl011: 8-byte write at offset 0x0 names no register (ignored)macvmm: warn: [vcpu0] guest: pl011: 1-byte read at offset 0x1 names no register (read as zero)macvmm: warn: [vcpu0] guest: pl011: 1-byte write at offset 0x1 names no register (ignored)macvmm: warn: [vcpu0] guest: pl011: 1-byte read at offset 0x2 names no register (read as zero)macvmm: warn: [vcpu0] guest: pl011: 1-byte write at offset 0x2 names no register (ignored)macvmm: warn: [vcpu0] guest: pl011: 2-byte read at offset 0x2 names no register (read as zero)macvmm: warn: [vcpu0] guest: pl011: 2-byte write at offset 0x2 names no register (ignored)macvmm: warn: [vcpu0] guest: pl011: 1-byte read at offset 0x3 names no register (read as zero)macvmm: warn: [vcpu0] guest: pl011: 1-byte write at offset 0x3 names no register (ignored)macvmm: warn: [vcpu0] guest: pl011: 1-byte read at offset 0x5 names no register (read as zero)macvmm: warn: [vcpu0] guest: pl011: 1-byte write at offset 0x5 names no register (ignored)macvmm: warn: [vcpu0] guest: pl011: 1-byte read at offset 0x6 names no register (read as zero)macvmm: warn: [vcpu0] guest: pl011: 1-byte write at offset 0x6 names no register (ignored)macvmm: warn: [vcpu0] guest: pl011: 2-byte read at offset 0x6 names no register (read as zero)macvmm: warn: [vcpu0] guest: pl011: 2-byte write at offset 0x6 names no register (ignored)macvmm: warn: [vcpu0] guest: pl011: 1-byte read at offset 0x7 names no register (read as zero)macvmm: warn: [vcpu0] guest: pl011: 1-byte write at offset 0x7 names no register (ignored)macvmm: warn: [vcpu0] guest: pl011: 1-byte read at offset 0x8 names no register (read as zero)macvmm: warn: [vcpu0] guest: pl011: 1-byte write at offset 0x8 names no register (ignored)macvmm: warn: [vcpu0] guest: pl011: 2-byte read at offset 0x22a names no register (read as zero) (989 similar messages suppressed)macvmm: warn: [vcpu0] guest: pl011: 2-byte write at offset 0x22a names no register (ignored) (989 similar messages suppressed)macvmm: warn: [vcpu0] guest: pl011: 2-byte read at offset 0x440 names no register (read as zero) (999 similar messages suppressed)macvmm: warn: [vcpu0] guest: pl011: 2-byte write at offset 0x440 names no register (ignored) (999 similar messages suppressed)macvmm: warn: [vcpu0] guest: pl011: 1-byte read at offset 0x655 names no register (read as zero) (999 similar messages suppressed)macvmm: warn: [vcpu0] guest: pl011: 1-byte write at offset 0x655 names no register (ignored) (999 similar messages suppressed)macvmm: warn: [vcpu0] guest: pl011: 2-byte read at offset 0x86a names no register (read as zero) (999 similar messages suppressed)macvmm: warn: [vcpu0] guest: pl011: 2-byte write at offset 0x86a names no register (ignored) (999 similar messages suppressed)macvmm: warn: [vcpu0] guest: pl011: 2-byte read at offset 0xa80 names no register (read as zero) (999 similar messages suppressed)macvmm: warn: [vcpu0] guest: pl011: 2-byte write at offset 0xa80 names no register (ignored) (999 similar messages suppressed)macvmm: warn: [vcpu0] guest: pl011: 1-byte read at offset 0xc95 names no register (read as zero) (999 similar messages suppressed)macvmm: warn: [vcpu0] guest: pl011: 1-byte write at offset 0xc95 names no register (ignored) (999 similar messages suppressed)macvmm: warn: [vcpu0] guest: pl011: 2-byte read at offset 0xeaa names no register (read as zero) (999 similar messages suppressed)macvmm: warn: [vcpu0] guest: pl011: 2-byte write at offset 0xeaa names no register (ignored) (999 similar messages suppressed)macvmm: warn: [vcpu0] guest: pl031: 8-byte read at offset 0x0 names no register (read as zero)macvmm: warn: [vcpu0] guest: pl031: 8-byte write at offset 0x0 names no register (ignored)macvmm: warn: [vcpu0] guest: pl031: 1-byte read at offset 0x1 names no register (read as zero)macvmm: warn: [vcpu0] guest: pl031: 1-byte write at offset 0x1 names no register (ignored)macvmm: warn: [vcpu0] guest: pl031: 1-byte read at offset 0x2 names no register (read as zero)macvmm: warn: [vcpu0] guest: pl031: 1-byte write at offset 0x2 names no register (ignored)macvmm: warn: [vcpu0] guest: pl031: 2-byte read at offset 0x2 names no register (read as zero)macvmm: warn: [vcpu0] guest: pl031: 2-byte write at offset 0x2 names no register (ignored)macvmm: warn: [vcpu0] guest: pl031: 1-byte read at offset 0x3 names no register (read as zero)macvmm: warn: [vcpu0] guest: pl031: 1-byte write at offset 0x3 names no register (ignored)macvmm: warn: [vcpu0] guest: pl031: 1-byte read at offset 0x5 names no register (read as zero)macvmm: warn: [vcpu0] guest: pl031: 1-byte write at offset 0x5 names no register (ignored)macvmm: warn: [vcpu0] guest: pl031: 1-byte read at offset 0x6 names no register (read as zero)macvmm: warn: [vcpu0] guest: pl031: 1-byte write at offset 0x6 names no register (ignored)macvmm: warn: [vcpu0] guest: pl031: 2-byte read at offset 0x6 names no register (read as zero)macvmm: warn: [vcpu0] guest: pl031: 2-byte write at offset 0x6 names no register (ignored)macvmm: warn: [vcpu0] guest: pl031: 1-byte read at offset 0x7 names no register (read as zero)macvmm: warn: [vcpu0] guest: pl031: 1-byte write at offset 0x7 names no register (ignored)macvmm: warn: [vcpu0] guest: pl031: 8-byte read at offset 0x8 names no register (read as zero)macvmm: warn: [vcpu0] guest: pl031: 8-byte write at offset 0x8 names no register (ignored)macvmm: warn: [vcpu0] guest: pl031: 8-byte read at offset 0x220 names no register (read as zero) (989 similar messages suppressed)macvmm: warn: [vcpu0] guest: pl031: 8-byte write at offset 0x220 names no register (ignored) (989 similar messages suppressed)macvmm: warn: [vcpu0] guest: pl031: 2-byte read at offset 0x436 names no register (read as zero) (999 similar messages suppressed)macvmm: warn: [vcpu0] guest: pl031: 2-byte write at offset 0x436 names no register (ignored) (999 similar messages suppressed)macvmm: warn: [vcpu0] guest: pl031: 1-byte read at offset 0x64c names no register (read as zero) (999 similar messages suppressed)macvmm: warn: [vcpu0] guest: pl031: 1-byte write at offset 0x64c names no register (ignored) (999 similar messages suppressed)macvmm: warn: [vcpu0] guest: pl031: 8-byte read at offset 0x860 names no register (read as zero) (999 similar messages suppressed)macvmm: warn: [vcpu0] guest: pl031: 8-byte write at offset 0x860 names no register (ignored) (999 similar messages suppressed)macvmm: warn: [vcpu0] guest: pl031: 2-byte read at offset 0xa76 names no register (read as zero) (999 similar messages suppressed)macvmm: warn: [vcpu0] guest: pl031: 2-byte write at offset 0xa76 names no register (ignored) (999 similar messages suppressed)macvmm: warn: [vcpu0] guest: pl031: 1-byte read at offset 0xc8c names no register (read as zero) (999 similar messages suppressed)macvmm: warn: [vcpu0] guest: pl031: 1-byte write at offset 0xc8c names no register (ignored) (999 similar messages suppressed)macvmm: warn: [vcpu0] guest: pl031: 8-byte read at offset 0xea0 names no register (read as zero) (999 similar messages suppressed)macvmm: warn: [vcpu0] guest: pl031: 8-byte write at offset 0xea0 names no register (ignored) (999 similar messages suppressed)macvmm: warn: [vcpu0] guest: virtio-mmio: 1-byte read at 0x0 is not an aligned 32-bit access (RAZ)macvmm: warn: [vcpu0] guest: virtio-mmio: 1-byte write at 0x0 is not an aligned 32-bit access (WI)macvmm: warn: [vcpu0] guest: virtio-mmio: 2-byte read at 0x0 is not an aligned 32-bit access (RAZ)macvmm: warn: [vcpu0] guest: virtio-mmio: 2-byte write at 0x0 is not an aligned 32-bit access (WI)macvmm: warn: [vcpu0] guest: virtio-mmio: 8-byte read at 0x0 is not an aligned 32-bit access (RAZ)macvmm: warn: [vcpu0] guest: virtio-mmio: 8-byte write at 0x0 is not an aligned 32-bit access (WI)macvmm: warn: [vcpu0] guest: virtio-mmio: 1-byte read at 0x1 is not an aligned 32-bit access (RAZ)macvmm: warn: [vcpu0] guest: virtio-mmio: 1-byte write at 0x1 is not an aligned 32-bit access (WI)macvmm: warn: [vcpu0] guest: virtio-mmio: 1-byte read at 0x2 is not an aligned 32-bit access (RAZ)macvmm: warn: [vcpu0] guest: virtio-mmio: 1-byte write at 0x2 is not an aligned 32-bit access (WI)macvmm: warn: [vcpu0] guest: virtio-mmio: 2-byte read at 0x2 is not an aligned 32-bit access (RAZ)macvmm: warn: [vcpu0] guest: virtio-mmio: 2-byte write at 0x2 is not an aligned 32-bit access (WI)macvmm: warn: [vcpu0] guest: virtio-mmio: 1-byte read at 0x3 is not an aligned 32-bit access (RAZ)macvmm: warn: [vcpu0] guest: virtio-mmio: 1-byte write at 0x3 is not an aligned 32-bit access (WI)macvmm: warn: [vcpu0] guest: virtio-mmio: 1-byte read at 0x4 is not an aligned 32-bit access (RAZ)macvmm: warn: [vcpu0] guest: virtio-mmio: 1-byte write at 0x4 is not an aligned 32-bit access (WI)macvmm: warn: [vcpu0] guest: virtio-mmio: 2-byte read at 0x4 is not an aligned 32-bit access (RAZ)macvmm: warn: [vcpu0] guest: virtio-mmio: 2-byte write at 0x4 is not an aligned 32-bit access (WI)macvmm: warn: [vcpu0] guest: virtio-mmio: 1-byte read at 0x5 is not an aligned 32-bit access (RAZ)macvmm: warn: [vcpu0] guest: virtio-mmio: 1-byte write at 0x5 is not an aligned 32-bit access (WI)macvmm: warn: [vcpu0] guest: virtio-mmio: config access of 1 bytes at 0x0 outside the 0-byte config space (RAZ/WI)macvmm: warn: [vcpu0] guest: virtio-mmio: config access of 1 bytes at 0x0 outside the 0-byte config space (RAZ/WI)macvmm: warn: [vcpu0] guest: virtio-mmio: config access of 2 bytes at 0x0 outside the 0-byte config space (RAZ/WI)macvmm: warn: [vcpu0] guest: virtio-mmio: config access of 2 bytes at 0x0 outside the 0-byte config space (RAZ/WI)macvmm: warn: [vcpu0] guest: virtio-mmio: config access of 4 bytes at 0x0 outside the 0-byte config space (RAZ/WI)macvmm: warn: [vcpu0] guest: virtio-mmio: config access of 4 bytes at 0x0 outside the 0-byte config space (RAZ/WI)macvmm: warn: [vcpu0] guest: virtio-mmio: config access of 8 bytes at 0x0 outside the 0-byte config space (RAZ/WI)macvmm: warn: [vcpu0] guest: virtio-mmio: config access of 8 bytes at 0x0 outside the 0-byte config space (RAZ/WI)macvmm: warn: [vcpu0] guest: virtio-mmio: config access of 1 bytes at 0x1 outside the 0-byte config space (RAZ/WI)macvmm: warn: [vcpu0] guest: virtio-mmio: config access of 1 bytes at 0x1 outside the 0-byte config space (RAZ/WI)macvmm: warn: [vcpu0] guest: virtio-mmio: config access of 1 bytes at 0x9 outside the 0-byte config space (RAZ/WI) (989 similar messages suppressed)macvmm: warn: [vcpu0] guest: virtio-mmio: 2-byte read at 0x66 is not an aligned 32-bit access (RAZ) (989 similar messages suppressed)macvmm: warn: [vcpu0] guest: virtio-mmio: 2-byte write at 0x66 is not an aligned 32-bit access (WI) (989 similar messages suppressed)macvmm: warn: [vcpu0] guest: virtio-mmio: config access of 2 bytes at 0x14 outside the 0-byte config space (RAZ/WI) (999 similar messages suppressed)macvmm: warn: [vcpu0] guest: virtio-mmio: config access of 1 bytes at 0x1f outside the 0-byte config space (RAZ/WI) (999 similar messages suppressed)macvmm: warn: [vcpu0] guest: virtio-mmio: 1-byte read at 0xce is not an aligned 32-bit access (RAZ) (999 similar messages suppressed)macvmm: warn: [vcpu0] guest: virtio-mmio: 1-byte write at 0xce is not an aligned 32-bit access (WI) (999 similar messages suppressed)macvmm: warn: [vcpu0] guest: virtio-mmio: config access of 1 bytes at 0x29 outside the 0-byte config space (RAZ/WI) (999 similar messages suppressed)macvmm: warn: [vcpu0] guest: virtio-mmio: config access of 2 bytes at 0x34 outside the 0-byte config space (RAZ/WI) (999 similar messages suppressed)macvmm: warn: [vcpu0] guest: virtio-mmio: config access of 1 bytes at 0x3f outside the 0-byte config space (RAZ/WI) (999 similar messages suppressed)macvmm: warn: [vcpu0] guest: virtio-mmio: 1-byte read at 0x35 is not an aligned 32-bit access (RAZ) (999 similar messages suppressed)macvmm: warn: [vcpu0] guest: virtio-mmio: 1-byte write at 0x35 is not an aligned 32-bit access (WI) (999 similar messages suppressed)macvmm: warn: [vcpu0] guest: virtio-mmio: config access of 1 bytes at 0x49 outside the 0-byte config space (RAZ/WI) (999 similar messages suppressed)macvmm: warn: [vcpu0] guest: virtio-mmio: config access of 2 bytes at 0x54 outside the 0-byte config space (RAZ/WI) (999 similar messages suppressed)macvmm: warn: [vcpu0] guest: virtio-mmio: 2-byte read at 0x9c is not an aligned 32-bit access (RAZ) (999 similar messages suppressed)macvmm: warn: [vcpu0] guest: virtio-mmio: 2-byte write at 0x9c is not an aligned 32-bit access (WI) (999 similar messages suppressed)macvmm: warn: [vcpu0] guest: virtio-mmio: config access of 1 bytes at 0x5f outside the 0-byte config space (RAZ/WI) (999 similar messages suppressed)macvmm: warn: [vcpu0] guest: virtio-mmio: config access of 1 bytes at 0x69 outside the 0-byte config space (RAZ/WI) (999 similar messages suppressed)macvmm: warn: [vcpu0] guest: virtio-mmio: config access of 2 bytes at 0x74 outside the 0-byte config space (RAZ/WI) (999 similar messages suppressed)macvmm: warn: [vcpu0] guest: virtio-mmio: 1-byte read at 0x4 is not an aligned 32-bit access (RAZ) (999 similar messages suppressed)macvmm: warn: [vcpu0] guest: virtio-mmio: 1-byte write at 0x4 is not an aligned 32-bit access (WI) (999 similar messages suppressed)macvmm: warn: [vcpu0] guest: virtio-mmio: config access of 1 bytes at 0x7f outside the 0-byte config space (RAZ/WI) (999 similar messages suppressed)macvmm: warn: [vcpu0] guest: virtio-mmio: config access of 1 bytes at 0x89 outside the 0-byte config space (RAZ/WI) (999 similar messages suppressed)macvmm: warn: [vcpu0] guest: virtio-mmio: 1-byte read at 0x6b is not an aligned 32-bit access (RAZ) (999 similar messages suppressed)macvmm: warn: [vcpu0] guest: virtio-mmio: 1-byte write at 0x6b is not an aligned 32-bit access (WI) (999 similar messages suppressed)macvmm: warn: [vcpu0] guest: virtio-mmio: config access of 2 bytes at 0x94 outside the 0-byte config space (RAZ/WI) (999 similar messages suppressed)macvmm: warn: [vcpu0] guest: virtio-mmio: config access of 1 bytes at 0x9f outside the 0-byte config space (RAZ/WI) (999 similar messages suppressed)macvmm: warn: [vcpu0] guest: virtio-mmio: 2-byte read at 0xd2 is not an aligned 32-bit access (RAZ) (999 similar messages suppressed)macvmm: warn: [vcpu0] guest: virtio-mmio: 2-byte write at 0xd2 is not an aligned 32-bit access (WI) (999 similar messages suppressed)macvmm: warn: [vcpu0] guest: virtio-mmio: config access of 1 bytes at 0xa9 outside the 0-byte config space (RAZ/WI) (999 similar messages suppressed)macvmm: warn: [vcpu0] guest: virtio-mmio: config access of 2 bytes at 0xb4 outside the 0-byte config space (RAZ/WI) (999 similar messages suppressed)macvmm: warn: [vcpu0] guest: virtio-mmio: config access of 1 bytes at 0xbf outside the 0-byte config space (RAZ/WI) (999 similar messages suppressed)macvmm: warn: [vcpu0] guest: virtio-mmio: 1-byte read at 0x3a is not an aligned 32-bit access (RAZ) (999 similar messages suppressed)macvmm: warn: [vcpu0] guest: virtio-mmio: 1-byte write at 0x3a is not an aligned 32-bit access (WI) (999 similar messages suppressed)macvmm: warn: [vcpu0] guest: virtio-mmio: config access of 1 bytes at 0xc9 outside the 0-byte config space (RAZ/WI) (999 similar messages suppressed)macvmm: warn: [vcpu0] guest: virtio-mmio: config access of 2 bytes at 0xd4 outside the 0-byte config space (RAZ/WI) (999 similar messages suppressed)macvmm: warn: [vcpu0] guest: virtio-mmio: 1-byte read at 0xa1 is not an aligned 32-bit access (RAZ) (999 similar messages suppressed)macvmm: warn: [vcpu0] guest: virtio-mmio: 1-byte write at 0xa1 is not an aligned 32-bit access (WI) (999 similar messages suppressed)macvmm: warn: [vcpu0] guest: virtio-mmio: config access of 1 bytes at 0xdf outside the 0-byte config space (RAZ/WI) (999 similar messages suppressed)macvmm: warn: [vcpu0] guest: virtio-mmio: config access of 1 bytes at 0xe9 outside the 0-byte config space (RAZ/WI) (999 similar messages suppressed)macvmm: warn: [vcpu0] guest: virtio-mmio: config access of 2 bytes at 0xf4 outside the 0-byte config space (RAZ/WI) (999 similar messages suppressed)macvmm: warn: [vcpu0] guest: virtio-mmio: 8-byte read at 0x8 is not an aligned 32-bit access (RAZ) (999 similar messages suppressed)macvmm: warn: [vcpu0] guest: virtio-mmio: 8-byte write at 0x8 is not an aligned 32-bit access (WI) (999 similar messages suppressed)macvmm: warn: [vcpu0] guest: virtio-mmio: config access of 1 bytes at 0xff outside the 0-byte config space (RAZ/WI) (999 similar messages suppressed)macvmm: warn: [vcpu0] guest: virtio-mmio: 2-byte read at 0x70 is not an aligned 32-bit access (RAZ) (999 similar messages suppressed)macvmm: warn: [vcpu0] guest: virtio-mmio: 2-byte write at 0x70 is not an aligned 32-bit access (WI) (999 similar messages suppressed)macvmm: warn: [vcpu0] guest: virtio-mmio: config access of 1 bytes at 0x9 outside the 0-byte config space (RAZ/WI) (999 similar messages suppressed)macvmm: warn: [vcpu0] guest: virtio-mmio: config access of 2 bytes at 0x14 outside the 0-byte config space (RAZ/WI) (999 similar messages suppressed)macvmm: warn: [vcpu0] guest: virtio-mmio: 1-byte read at 0xd8 is not an aligned 32-bit access (RAZ) (999 similar messages suppressed)macvmm: warn: [vcpu0] guest: virtio-mmio: 1-byte write at 0xd8 is not an aligned 32-bit access (WI) (999 similar messages suppressed)macvmm: warn: [vcpu0] guest: virtio-mmio: config access of 1 bytes at 0x1f outside the 0-byte config space (RAZ/WI) (999 similar messages suppressed)macvmm: warn: [vcpu0] guest: virtio-mmio: config access of 1 bytes at 0x29 outside the 0-byte config space (RAZ/WI) (999 similar messages suppressed)macvmm: warn: [vcpu0] guest: virtio-mmio: config access of 2 bytes at 0x34 outside the 0-byte config space (RAZ/WI) (999 similar messages suppressed)macvmm: warn: [vcpu0] guest: virtio-mmio: 1-byte read at 0x3f is not an aligned 32-bit access (RAZ) (999 similar messages suppressed)macvmm: warn: [vcpu0] guest: virtio-mmio: 1-byte write at 0x3f is not an aligned 32-bit access (WI) (999 similar messages suppressed)macvmm: warn: [vcpu0] guest: virtio-mmio: config access of 1 bytes at 0x3f outside the 0-byte config space (RAZ/WI) (999 similar messages suppressed)macvmm: warn: [vcpu0] guest: unhandled MMIO read at 0xc000000 size 1 pc 0x40081120 (ignored: --unhandled-mmio log)macvmm: warn: [vcpu0] guest: unhandled MMIO write at 0xc000000 size 1 pc 0x40081068 (ignored: --unhandled-mmio log)macvmm: warn: [vcpu0] guest: unhandled MMIO read at 0xc000000 size 2 pc 0x40081118 (ignored: --unhandled-mmio log)macvmm: warn: [vcpu0] guest: unhandled MMIO write at 0xc000000 size 2 pc 0x40081060 (ignored: --unhandled-mmio log)macvmm: warn: [vcpu0] guest: unhandled MMIO read at 0xc000000 size 4 pc 0x40081110 (ignored: --unhandled-mmio log)macvmm: warn: [vcpu0] guest: unhandled MMIO write at 0xc000000 size 4 pc 0x40081058 (ignored: --unhandled-mmio log)macvmm: warn: [vcpu0] guest: unhandled MMIO read at 0xc000000 size 8 pc 0x40081128 (ignored: --unhandled-mmio log)macvmm: warn: [vcpu0] guest: unhandled MMIO write at 0xc000000 size 8 pc 0x40081070 (ignored: --unhandled-mmio log)macvmm: warn: [vcpu0] guest: unhandled MMIO read at 0xc000001 size 1 pc 0x40081120 (ignored: --unhandled-mmio log)macvmm: warn: [vcpu0] guest: unhandled MMIO write at 0xc000001 size 1 pc 0x40081068 (ignored: --unhandled-mmio log)macvmm: warn: [vcpu0] guest: unhandled MMIO read at 0xc00001a size 1 pc 0x4008125c (ignored: --unhandled-mmio log) (989 similar messages suppressed)macvmm: warn: [vcpu0] guest: virtio-mmio: config access of 1 bytes at 0x73 outside the 0-byte config space (RAZ/WI) (999 similar messages suppressed)macvmm: warn: [vcpu0] guest: pl031: 1-byte write at offset 0x945 names no register (ignored) (999 similar messages suppressed)macvmm: warn: [vcpu0] guest: pl031: 1-byte read at offset 0x4da names no register (read as zero) (999 similar messages suppressed)macvmm: warn: [vcpu0] guest: pl011: 4-byte read at offset 0xc48 names no register (read as zero) (999 similar messages suppressed)macvmm: warn: [vcpu0] guest: pl011: 1-byte write at offset 0x450 names no register (ignored) (999 similar messages suppressed)macvmm: warn: [vcpu0] guest: unhandled MMIO write at 0xc0000c8 size 4 pc 0x40081058 (ignored: --unhandled-mmio log) (999 similar messages suppressed)The 150,926 alignment faults are the guest's own. It runs with its memory management unit (MMU) off, so every access is to Device memory, where an unaligned access faults inside the guest (chapter 06) before it could reach us; the guest counts them and moves on. What matters is 0 other data aborts and exit 0.
The live TOCTOU phase is the one Rust cannot help with. vCPU 1 scribbles over the descriptor table while vCPU 0 rings the doorbell. Before and after, the guest hashes 16 MiB of its own RAM that no descriptor names, a canary region. The VMM's device writes land in guest RAM, so a stray write would change the hash, and the guest would see it. It needs chapter 18's test disk, opened read-only. As in chapter 18, the disk tool runs at the repository root; make it once:
cargo xtask mkdisk --size 64M --seed 1 --out learner/disk.imgThen, back in learner/, the run uses --disk disk.img,ro; our capture, from the root, names learner/disk.img:
cargo run -q -p macvmm -- run --cpus 2 --mem 64M --rng --disk learner/disk.img,ro --stats --kernel target/guests/aarch64-unknown-none/release/hostile-smp --timeout 60 && shasum -a 256 learner/disk.imghostile-smp: 2 cpus, 2 virtio devices, RAM ends at 0x44000000hostile-smp: canary 0x42e00000+0x1000000 hash 0x6300ec9a4c71f456hostile-smp: live toctou blk slot 0: notifies=121736 served=4672 resets=83758 scribbles=365302878 recoveredhostile-smp: canary intact after blkhostile-smp: live toctou rng slot 1: notifies=114425 served=5895 resets=103139 scribbles=377087318 recoveredhostile-smp: canary intact after rnghostile-smp: survived4ae50b0ecaa3f91bdcfe84f5a2e20706045ea6f3387c6c45238200cf50ea7859 learner/disk.imgmacvmm: warn: [virtio-blk-0] guest: virtio: queue 0 failed, device needs reset: virtqueue: HeadOutOfRange { head: 16, size: 16 }macvmm: warn: [vcpu0] guest: virtio-mmio: QueueNotify 0 ignored in status 79macvmm: warn: [virtio-blk-0] guest: virtio: queue 0 failed, device needs reset: virtqueue: IndirectNotNegotiatedmacvmm: warn: [virtio-blk-0] guest: virtio: queue 0 failed, device needs reset: virtqueue: HeadOutOfRange { head: 19, size: 16 }macvmm: warn: [virtio-blk-0] guest: virtio: queue 0 failed, device needs reset: virtqueue: HeadOutOfRange { head: 17, size: 16 }macvmm: warn: [virtio-blk-0] guest: virtio: queue 0 failed, device needs reset: virtqueue: IndirectNotNegotiatedmacvmm: warn: [virtio-blk-0] guest: virtio: queue 0 failed, device needs reset: virtqueue: HeadOutOfRange { head: 19, size: 16 }macvmm: warn: [virtio-blk-0] guest: virtio: queue 0 failed, device needs reset: virtqueue: HeadOutOfRange { head: 16, size: 16 }macvmm: warn: [virtio-blk-0] guest: virtio: queue 0 failed, device needs reset: virtqueue: Overflow { addr: 18446744073709551608, len: 65537 }macvmm: warn: [virtio-blk-0] guest: virtio: queue 0 failed, device needs reset: virtqueue: IndirectNotNegotiatedmacvmm: warn: [virtio-blk-0] guest: virtio: queue 0 failed, device needs reset: virtqueue: IndirectNotNegotiatedmacvmm: warn: [vcpu0] guest: virtio-mmio: QueueNotify 0 ignored in status 79macvmm: warn: [vcpu0] guest: virtio-mmio: QueueNotify 0 ignored in status 79macvmm: warn: [vcpu0] guest: virtio-mmio: QueueNotify 0 ignored in status 79macvmm: warn: [vcpu0] guest: virtio-mmio: QueueNotify 0 ignored in status 79macvmm: warn: [virtio-blk-0] guest: virtio: queue 0 failed, device needs reset: virtqueue: BufferOutOfRam { addr: 1140850688, len: 1 } (989 similar messages suppressed)macvmm: warn: [vcpu0] guest: virtio-mmio: QueueNotify 0 ignored in status 79macvmm: warn: [vcpu0] guest: virtio-mmio: QueueNotify 0 ignored in status 79macvmm: warn: [vcpu0] guest: virtio-mmio: QueueNotify 0 ignored in status 79macvmm: warn: [vcpu0] guest: virtio-mmio: QueueNotify 0 ignored in status 79macvmm: warn: [virtio-blk-0] guest: virtio: queue 0 failed, device needs reset: device: blk request without a writable status byte (999 similar messages suppressed)macvmm: warn: [vcpu0] guest: virtio-mmio: QueueNotify 0 ignored in status 79macvmm: warn: [virtio-blk-0] guest: virtio: queue 0 failed, device needs reset: virtqueue: NextOutOfRange { next: 16, table_len: 16 } (999 similar messages suppressed)macvmm: warn: [virtio-blk-0] guest: virtio: queue 0 failed, device needs reset: virtqueue: IndirectNotNegotiated (999 similar messages suppressed)macvmm: warn: [virtio-blk-0] guest: virtio: queue 0 failed, device needs reset: device: blk request without a writable status byte (999 similar messages suppressed)macvmm: warn: [virtio-blk-0] guest: virtio: queue 0 failed, device needs reset: virtqueue: IndirectNotNegotiated (999 similar messages suppressed)macvmm: warn: [virtio-blk-0] guest: virtio: queue 0 failed, device needs reset: virtqueue: HeadOutOfRange { head: 17, size: 16 } (999 similar messages suppressed)macvmm: warn: [virtio-blk-0] guest: virtio: queue 0 failed, device needs reset: virtqueue: HeadOutOfRange { head: 19, size: 16 } (999 similar messages suppressed)macvmm: warn: [virtio-blk-0] guest: virtio: queue 0 failed, device needs reset: virtqueue: HeadOutOfRange { head: 19, size: 16 } (999 similar messages suppressed)macvmm: warn: [virtio-blk-0] guest: virtio: queue 0 failed, device needs reset: virtqueue: Overflow { addr: 18446744073709551608, len: 65537 } (999 similar messages suppressed)macvmm: warn: [virtio-blk-0] guest: virtio: queue 0 failed, device needs reset: virtqueue: BufferOutOfRam { addr: 134217728, len: 44704 } (999 similar messages suppressed)macvmm: warn: [virtio-blk-0] guest: virtio: queue 0 failed, device needs reset: virtqueue: BufferOutOfRam { addr: 134217728, len: 281445 } (999 similar messages suppressed)macvmm: warn: [virtio-blk-0] guest: virtio: queue 0 failed, device needs reset: virtqueue: IndirectNotNegotiated (999 similar messages suppressed)macvmm: warn: [virtio-blk-0] guest: virtio: queue 0 failed, device needs reset: device: blk request without a writable status byte (999 similar messages suppressed)macvmm: warn: [virtio-blk-0] guest: virtio: queue 0 failed, device needs reset: virtqueue: IndirectNotNegotiated (999 similar messages suppressed)macvmm: warn: [virtio-blk-0] guest: virtio: queue 0 failed, device needs reset: virtqueue: IndirectNotNegotiated (999 similar messages suppressed)macvmm: warn: [virtio-blk-0] guest: virtio: queue 0 failed, device needs reset: virtqueue: ZeroLength { index: 7 } (999 similar messages suppressed)macvmm: warn: [virtio-blk-0] guest: virtio: queue 0 failed, device needs reset: virtqueue: HeadOutOfRange { head: 19, size: 16 } (999 similar messages suppressed)macvmm: warn: [virtio-blk-0] guest: virtio: queue 0 failed, device needs reset: virtqueue: IndirectNotNegotiated (999 similar messages suppressed)macvmm: warn: [virtio-blk-0] guest: virtio: queue 0 failed, device needs reset: virtqueue: IndirectNotNegotiated (999 similar messages suppressed)macvmm: warn: [virtio-blk-0] guest: virtio: queue 0 failed, device needs reset: virtqueue: HeadOutOfRange { head: 16, size: 16 } (999 similar messages suppressed)macvmm: warn: [virtio-blk-0] guest: virtio: queue 0 failed, device needs reset: virtqueue: BufferOutOfRam { addr: 1140850688, len: 1 } (999 similar messages suppressed)macvmm: warn: [virtio-blk-0] guest: virtio: queue 0 failed, device needs reset: virtqueue: HeadOutOfRange { head: 17, size: 16 } (999 similar messages suppressed)macvmm: warn: [virtio-blk-0] guest: virtio: queue 0 failed, device needs reset: virtqueue: Overflow { addr: 18446744073709551608, len: 1085292 } (999 similar messages suppressed)macvmm: warn: [virtio-blk-0] guest: virtio: queue 0 failed, device needs reset: virtqueue: HeadOutOfRange { head: 17, size: 16 } (999 similar messages suppressed)macvmm: warn: [virtio-blk-0] guest: virtio: queue 0 failed, device needs reset: virtqueue: IndirectNotNegotiated (999 similar messages suppressed)macvmm: warn: [virtio-blk-0] guest: virtio: queue 0 failed, device needs reset: virtqueue: BufferOutOfRam { addr: 1140850688, len: 4096 } (999 similar messages suppressed)macvmm: warn: [virtio-blk-0] guest: virtio: queue 0 failed, device needs reset: virtqueue: BufferOutOfRam { addr: 1140850688, len: 65537 } (999 similar messages suppressed)macvmm: warn: [virtio-blk-0] guest: virtio: queue 0 failed, device needs reset: virtqueue: IndirectNotNegotiated (999 similar messages suppressed)macvmm: warn: [virtio-blk-0] guest: virtio: queue 0 failed, device needs reset: virtqueue: IndirectNotNegotiated (999 similar messages suppressed)macvmm: warn: [virtio-blk-0] guest: virtio: queue 0 failed, device needs reset: virtqueue: BufferOutOfRam { addr: 1140850688, len: 512 } (999 similar messages suppressed)macvmm: warn: [virtio-blk-0] guest: virtio: queue 0 failed, device needs reset: virtqueue: IndirectNotNegotiated (999 similar messages suppressed)macvmm: warn: [virtio-blk-0] guest: virtio: queue 0 failed, device needs reset: virtqueue: Overflow { addr: 18446744073709551608, len: 65537 } (999 similar messages suppressed)macvmm: warn: [virtio-blk-0] guest: virtio: queue 0 failed, device needs reset: virtqueue: BufferOutOfRam { addr: 1140850688, len: 4096 } (999 similar messages suppressed)macvmm: warn: [virtio-blk-0] guest: virtio: queue 0 failed, device needs reset: virtqueue: IndirectNotNegotiated (999 similar messages suppressed)macvmm: warn: [virtio-blk-0] guest: virtio: queue 0 failed, device needs reset: virtqueue: IndirectNotNegotiated (999 similar messages suppressed)macvmm: warn: [virtio-blk-0] guest: virtio: queue 0 failed, device needs reset: virtqueue: IndirectNotNegotiated (999 similar messages suppressed)macvmm: warn: [virtio-blk-0] guest: virtio: queue 0 failed, device needs reset: virtqueue: Overflow { addr: 18446744073709551608, len: 512 } (999 similar messages suppressed)macvmm: warn: [virtio-blk-0] guest: virtio: queue 0 failed, device needs reset: virtqueue: HeadOutOfRange { head: 16, size: 16 } (999 similar messages suppressed)macvmm: warn: [virtio-blk-0] guest: virtio: queue 0 failed, device needs reset: virtqueue: BufferOutOfRam { addr: 134217728, len: 65537 } (999 similar messages suppressed)macvmm: warn: [virtio-blk-0] guest: virtio: queue 0 failed, device needs reset: device: blk request without a writable status byte (999 similar messages suppressed)macvmm: warn: [virtio-blk-0] guest: virtio: queue 0 failed, device needs reset: virtqueue: IndirectNotNegotiated (999 similar messages suppressed)macvmm: warn: [virtio-blk-0] guest: virtio: queue 0 failed, device needs reset: virtqueue: IndirectNotNegotiated (999 similar messages suppressed)macvmm: warn: [virtio-blk-0] guest: virtio: queue 0 failed, device needs reset: virtqueue: IndirectNotNegotiated (999 similar messages suppressed)macvmm: warn: [virtio-blk-0] guest: virtio: queue 0 failed, device needs reset: virtqueue: HeadOutOfRange { head: 18, size: 16 } (999 similar messages suppressed)macvmm: warn: [virtio-blk-0] guest: virtio: queue 0 failed, device needs reset: virtqueue: HeadOutOfRange { head: 16, size: 16 } (999 similar messages suppressed)macvmm: warn: [virtio-blk-0] guest: virtio: queue 0 failed, device needs reset: virtqueue: IndirectNotNegotiated (999 similar messages suppressed)macvmm: warn: [virtio-blk-0] guest: virtio: queue 0 failed, device needs reset: virtqueue: IndirectNotNegotiated (999 similar messages suppressed)macvmm: warn: [virtio-blk-0] guest: virtio: queue 0 failed, device needs reset: virtqueue: IndirectNotNegotiated (999 similar messages suppressed)macvmm: warn: [virtio-blk-0] guest: virtio: queue 0 failed, device needs reset: virtqueue: IndirectNotNegotiated (999 similar messages suppressed)macvmm: warn: [virtio-blk-0] guest: virtio: queue 0 failed, device needs reset: virtqueue: IndirectNotNegotiated (999 similar messages suppressed)macvmm: warn: [virtio-blk-0] guest: virtio: queue 0 failed, device needs reset: virtqueue: IndirectNotNegotiated (999 similar messages suppressed)macvmm: warn: [virtio-blk-0] guest: virtio: queue 0 failed, device needs reset: device: blk request without a writable status byte (999 similar messages suppressed)macvmm: warn: [virtio-blk-0] guest: virtio: queue 0 failed, device needs reset: device: blk request without a writable status byte (999 similar messages suppressed)macvmm: warn: [virtio-blk-0] guest: virtio: queue 0 failed, device needs reset: virtqueue: IndirectNotNegotiated (999 similar messages suppressed)macvmm: warn: [virtio-blk-0] guest: virtio: queue 0 failed, device needs reset: virtqueue: NextOutOfRange { next: 17, table_len: 16 } (999 similar messages suppressed)macvmm: warn: [virtio-blk-0] guest: virtio: queue 0 failed, device needs reset: virtqueue: IndirectNotNegotiated (999 similar messages suppressed)macvmm: warn: [virtio-blk-0] guest: virtio: queue 0 failed, device needs reset: virtqueue: IndirectNotNegotiated (999 similar messages suppressed)macvmm: warn: [virtio-blk-0] guest: virtio: queue 0 failed, device needs reset: device: blk request without a writable status byte (999 similar messages suppressed)macvmm: warn: [virtio-blk-0] guest: virtio: queue 0 failed, device needs reset: virtqueue: IndirectNotNegotiated (999 similar messages suppressed)macvmm: warn: [virtio-blk-0] guest: virtio: queue 0 failed, device needs reset: virtqueue: ZeroLength { index: 11 } (999 similar messages suppressed)macvmm: warn: [virtio-blk-0] guest: virtio: queue 0 failed, device needs reset: virtqueue: IndirectNotNegotiated (999 similar messages suppressed)macvmm: warn: [virtio-blk-0] guest: virtio: queue 0 failed, device needs reset: virtqueue: HeadOutOfRange { head: 16, size: 16 } (999 similar messages suppressed)macvmm: warn: [virtio-blk-0] guest: virtio: queue 0 failed, device needs reset: device: blk request without a writable status byte (999 similar messages suppressed)macvmm: warn: [virtio-blk-0] guest: virtio: queue 0 failed, device needs reset: virtqueue: IndirectNotNegotiated (999 similar messages suppressed)macvmm: warn: [virtio-blk-0] guest: virtio: queue 0 failed, device needs reset: virtqueue: Overflow { addr: 18446744073709551608, len: 920728 } (999 similar messages suppressed)macvmm: warn: [virtio-blk-0] guest: virtio: queue 0 failed, device needs reset: virtqueue: IndirectNotNegotiated (999 similar messages suppressed)macvmm: warn: [virtio-blk-0] guest: virtio: queue 0 failed, device needs reset: virtqueue: IndirectNotNegotiated (999 similar messages suppressed)macvmm: warn: [virtio-blk-0] guest: virtio: queue 0 failed, device needs reset: virtqueue: IndirectNotNegotiated (999 similar messages suppressed)macvmm: warn: [virtio-blk-0] guest: virtio: queue 0 failed, device needs reset: virtqueue: IndirectNotNegotiated (999 similar messages suppressed)macvmm: warn: [virtio-blk-0] guest: virtio: queue 0 failed, device needs reset: virtqueue: BufferOutOfRam { addr: 134217728, len: 512 } (999 similar messages suppressed)macvmm: warn: [virtio-blk-0] guest: virtio: queue 0 failed, device needs reset: virtqueue: IndirectNotNegotiated (999 similar messages suppressed)macvmm: warn: [virtio-blk-0] guest: virtio: queue 0 failed, device needs reset: virtqueue: IndirectNotNegotiated (999 similar messages suppressed)macvmm: warn: [virtio-blk-0] guest: virtio: queue 0 failed, device needs reset: virtqueue: IndirectNotNegotiated (999 similar messages suppressed)macvmm: warn: [virtio-blk-0] guest: virtio: queue 0 failed, device needs reset: virtqueue: IndirectNotNegotiated (999 similar messages suppressed)macvmm: warn: [virtio-blk-0] guest: virtio: queue 0 failed, device needs reset: virtqueue: HeadOutOfRange { head: 17, size: 16 } (999 similar messages suppressed)macvmm: warn: [virtio-blk-0] guest: virtio: queue 0 failed, device needs reset: virtqueue: HeadOutOfRange { head: 16, size: 16 } (999 similar messages suppressed)macvmm: warn: [virtio-blk-0] guest: virtio: queue 0 failed, device needs reset: device: blk request without a writable status byte (999 similar messages suppressed)macvmm: warn: [virtio-blk-0] guest: virtio: queue 0 failed, device needs reset: virtqueue: NextOutOfRange { next: 16, table_len: 16 } (999 similar messages suppressed)macvmm: warn: [virtio-blk-0] guest: virtio: queue 0 failed, device needs reset: virtqueue: ZeroLength { index: 5 } (999 similar messages suppressed)macvmm: warn: [virtio-blk-0] guest: virtio: queue 0 failed, device needs reset: virtqueue: IndirectNotNegotiated (999 similar messages suppressed)macvmm: warn: [virtio-blk-0] guest: virtio: queue 0 failed, device needs reset: virtqueue: IndirectNotNegotiated (999 similar messages suppressed)macvmm: warn: [virtio-blk-0] guest: virtio: queue 0 failed, device needs reset: virtqueue: ZeroLength { index: 0 } (999 similar messages suppressed)macvmm: warn: [virtio-rng-1] guest: virtio: queue 0 failed, device needs reset: virtqueue: IndirectNotNegotiated (999 similar messages suppressed)macvmm: warn: [virtio-rng-1] guest: virtio: queue 0 failed, device needs reset: virtqueue: IndirectNotNegotiated (999 similar messages suppressed)macvmm: warn: [virtio-rng-1] guest: virtio: queue 0 failed, device needs reset: virtqueue: IndirectNotNegotiated (999 similar messages suppressed)macvmm: warn: [virtio-rng-1] guest: virtio: queue 0 failed, device needs reset: virtqueue: BufferOutOfRam { addr: 134217728, len: 753987 } (999 similar messages suppressed)macvmm: warn: [virtio-rng-1] guest: virtio: queue 0 failed, device needs reset: virtqueue: NextOutOfRange { next: 17, table_len: 16 } (999 similar messages suppressed)macvmm: warn: [virtio-rng-1] guest: virtio: queue 0 failed, device needs reset: virtqueue: HeadOutOfRange { head: 19, size: 16 } (999 similar messages suppressed)macvmm: warn: [virtio-rng-1] guest: virtio: queue 0 failed, device needs reset: virtqueue: HeadOutOfRange { head: 19, size: 16 } (999 similar messages suppressed)macvmm: warn: [virtio-rng-1] guest: virtio: queue 0 failed, device needs reset: virtqueue: IndirectNotNegotiated (999 similar messages suppressed)macvmm: warn: [virtio-rng-1] guest: virtio: queue 0 failed, device needs reset: virtqueue: BufferOutOfRam { addr: 1138773032, len: 4294967295 } (999 similar messages suppressed)macvmm: warn: [virtio-rng-1] guest: virtio: queue 0 failed, device needs reset: virtqueue: BufferOutOfRam { addr: 134217728, len: 4294967295 } (999 similar messages suppressed)macvmm: warn: [virtio-rng-1] guest: virtio: queue 0 failed, device needs reset: virtqueue: IndirectNotNegotiated (999 similar messages suppressed)macvmm: warn: [virtio-rng-1] guest: virtio: queue 0 failed, device needs reset: virtqueue: IndirectNotNegotiated (999 similar messages suppressed)macvmm: warn: [virtio-rng-1] guest: virtio: queue 0 failed, device needs reset: virtqueue: IndirectNotNegotiated (999 similar messages suppressed)macvmm: warn: [virtio-rng-1] guest: virtio: queue 0 failed, device needs reset: virtqueue: IndirectNotNegotiated (999 similar messages suppressed)macvmm: warn: [virtio-rng-1] guest: virtio: queue 0 failed, device needs reset: virtqueue: IndirectNotNegotiated (999 similar messages suppressed)macvmm: warn: [virtio-rng-1] guest: virtio: queue 0 failed, device needs reset: virtqueue: IndirectNotNegotiated (999 similar messages suppressed)macvmm: warn: [virtio-rng-1] guest: virtio: queue 0 failed, device needs reset: virtqueue: IndirectNotNegotiated (999 similar messages suppressed)macvmm: warn: [virtio-rng-1] guest: virtio: queue 0 failed, device needs reset: virtqueue: IndirectNotNegotiated (999 similar messages suppressed)macvmm: warn: [virtio-rng-1] guest: virtio: queue 0 failed, device needs reset: virtqueue: ZeroLength { index: 4 } (999 similar messages suppressed)macvmm: warn: [virtio-rng-1] guest: virtio: queue 0 failed, device needs reset: virtqueue: HeadOutOfRange { head: 16, size: 16 } (999 similar messages suppressed)macvmm: warn: [virtio-rng-1] guest: virtio: queue 0 failed, device needs reset: virtqueue: BufferOutOfRam { addr: 134217728, len: 657212 } (999 similar messages suppressed)macvmm: warn: [virtio-rng-1] guest: virtio: queue 0 failed, device needs reset: virtqueue: IndirectNotNegotiated (999 similar messages suppressed)macvmm: warn: [virtio-rng-1] guest: virtio: queue 0 failed, device needs reset: virtqueue: HeadOutOfRange { head: 17, size: 16 } (999 similar messages suppressed)macvmm: warn: [virtio-rng-1] guest: virtio: queue 0 failed, device needs reset: virtqueue: BufferOutOfRam { addr: 150994944, len: 4096 } (999 similar messages suppressed)macvmm: warn: [virtio-rng-1] guest: virtio: queue 0 failed, device needs reset: virtqueue: IndirectNotNegotiated (999 similar messages suppressed)macvmm: warn: [virtio-rng-1] guest: virtio: queue 0 failed, device needs reset: virtqueue: IndirectNotNegotiated (999 similar messages suppressed)macvmm: warn: [virtio-rng-1] guest: virtio: queue 0 failed, device needs reset: virtqueue: BufferOutOfRam { addr: 134217728, len: 4096 } (999 similar messages suppressed)macvmm: warn: [virtio-rng-1] guest: virtio: queue 0 failed, device needs reset: virtqueue: ZeroLength { index: 8 } (999 similar messages suppressed)macvmm: warn: [virtio-rng-1] guest: virtio: queue 0 failed, device needs reset: virtqueue: IndirectNotNegotiated (999 similar messages suppressed)macvmm: warn: [virtio-rng-1] guest: virtio: queue 0 failed, device needs reset: virtqueue: HeadOutOfRange { head: 18, size: 16 } (999 similar messages suppressed)macvmm: warn: [virtio-rng-1] guest: virtio: queue 0 failed, device needs reset: virtqueue: HeadOutOfRange { head: 18, size: 16 } (999 similar messages suppressed)macvmm: warn: [virtio-rng-1] guest: virtio: queue 0 failed, device needs reset: virtqueue: NextOutOfRange { next: 17, table_len: 16 } (999 similar messages suppressed)macvmm: warn: [virtio-rng-1] guest: virtio: queue 0 failed, device needs reset: virtqueue: NextOutOfRange { next: 19, table_len: 16 } (999 similar messages suppressed)macvmm: warn: [virtio-rng-1] guest: virtio: queue 0 failed, device needs reset: virtqueue: IndirectNotNegotiated (999 similar messages suppressed)macvmm: warn: [virtio-rng-1] guest: virtio: queue 0 failed, device needs reset: virtqueue: IndirectNotNegotiated (999 similar messages suppressed)macvmm: warn: [virtio-rng-1] guest: virtio: queue 0 failed, device needs reset: virtqueue: IndirectNotNegotiated (999 similar messages suppressed)macvmm: warn: [virtio-rng-1] guest: virtio: queue 0 failed, device needs reset: virtqueue: TooLarge { total: 1445678, max: 65536 } (999 similar messages suppressed)macvmm: warn: [virtio-rng-1] guest: virtio: queue 0 failed, device needs reset: virtqueue: IndirectNotNegotiated (999 similar messages suppressed)macvmm: warn: [virtio-rng-1] guest: virtio: queue 0 failed, device needs reset: virtqueue: BufferOutOfRam { addr: 1139845984, len: 2059959 } (999 similar messages suppressed)macvmm: warn: [virtio-rng-1] guest: virtio: queue 0 failed, device needs reset: virtqueue: IndirectNotNegotiated (999 similar messages suppressed)macvmm: warn: [virtio-rng-1] guest: virtio: queue 0 failed, device needs reset: virtqueue: IndirectNotNegotiated (999 similar messages suppressed)macvmm: warn: [virtio-rng-1] guest: virtio: queue 0 failed, device needs reset: virtqueue: IndirectNotNegotiated (999 similar messages suppressed)macvmm: warn: [virtio-rng-1] guest: virtio: queue 0 failed, device needs reset: virtqueue: HeadOutOfRange { head: 19, size: 16 } (999 similar messages suppressed)macvmm: warn: [virtio-rng-1] guest: virtio: queue 0 failed, device needs reset: virtqueue: IndirectNotNegotiated (999 similar messages suppressed)macvmm: warn: [virtio-rng-1] guest: virtio: queue 0 failed, device needs reset: virtqueue: HeadOutOfRange { head: 18, size: 16 } (999 similar messages suppressed)macvmm: warn: [virtio-rng-1] guest: virtio: queue 0 failed, device needs reset: virtqueue: IndirectNotNegotiated (999 similar messages suppressed)macvmm: warn: [virtio-rng-1] guest: virtio: queue 0 failed, device needs reset: virtqueue: ReadableAfterWritable (999 similar messages suppressed)macvmm: warn: [virtio-rng-1] guest: virtio: queue 0 failed, device needs reset: virtqueue: BufferOutOfRam { addr: 134217728, len: 4294967295 } (999 similar messages suppressed)macvmm: warn: [virtio-rng-1] guest: virtio: queue 0 failed, device needs reset: virtqueue: ZeroLength { index: 14 } (999 similar messages suppressed)macvmm: warn: [virtio-rng-1] guest: virtio: queue 0 failed, device needs reset: virtqueue: TooLarge { total: 687923, max: 65536 } (999 similar messages suppressed)macvmm: warn: [virtio-rng-1] guest: virtio: queue 0 failed, device needs reset: virtqueue: BufferOutOfRam { addr: 134217728, len: 1 } (999 similar messages suppressed)macvmm: warn: [virtio-rng-1] guest: virtio: queue 0 failed, device needs reset: virtqueue: IndirectNotNegotiated (999 similar messages suppressed)macvmm: warn: [virtio-rng-1] guest: virtio: queue 0 failed, device needs reset: virtqueue: NextOutOfRange { next: 17, table_len: 16 } (999 similar messages suppressed)macvmm: warn: [virtio-rng-1] guest: virtio: queue 0 failed, device needs reset: virtqueue: BufferOutOfRam { addr: 1140850688, len: 4294967295 } (999 similar messages suppressed)macvmm: warn: [virtio-rng-1] guest: virtio: queue 0 failed, device needs reset: virtqueue: IndirectNotNegotiated (999 similar messages suppressed)macvmm: warn: [virtio-rng-1] guest: virtio: queue 0 failed, device needs reset: virtqueue: IndirectNotNegotiated (999 similar messages suppressed)macvmm: warn: [virtio-rng-1] guest: virtio: queue 0 failed, device needs reset: virtqueue: NextOutOfRange { next: 17, table_len: 16 } (999 similar messages suppressed)macvmm: warn: [virtio-rng-1] guest: virtio: queue 0 failed, device needs reset: virtqueue: IndirectNotNegotiated (999 similar messages suppressed)macvmm: warn: [virtio-rng-1] guest: virtio: queue 0 failed, device needs reset: virtqueue: IndirectNotNegotiated (999 similar messages suppressed)macvmm: warn: [virtio-rng-1] guest: virtio: queue 0 failed, device needs reset: virtqueue: HeadOutOfRange { head: 18, size: 16 } (999 similar messages suppressed)macvmm: warn: [virtio-rng-1] guest: virtio: queue 0 failed, device needs reset: virtqueue: ZeroLength { index: 9 } (999 similar messages suppressed)macvmm: warn: [virtio-rng-1] guest: virtio: queue 0 failed, device needs reset: virtqueue: IndirectNotNegotiated (999 similar messages suppressed)macvmm: warn: [virtio-rng-1] guest: virtio: queue 0 failed, device needs reset: virtqueue: IndirectNotNegotiated (999 similar messages suppressed)macvmm: warn: [virtio-rng-1] guest: virtio: queue 0 failed, device needs reset: virtqueue: ZeroLength { index: 7 } (999 similar messages suppressed)macvmm: warn: [virtio-rng-1] guest: virtio: queue 0 failed, device needs reset: virtqueue: IndirectNotNegotiated (999 similar messages suppressed)macvmm: warn: [virtio-rng-1] guest: virtio: queue 0 failed, device needs reset: virtqueue: HeadOutOfRange { head: 17, size: 16 } (999 similar messages suppressed)macvmm: warn: [virtio-rng-1] guest: virtio: queue 0 failed, device needs reset: virtqueue: TooLarge { total: 1092291, max: 65536 } (999 similar messages suppressed)macvmm: warn: [virtio-rng-1] guest: virtio: queue 0 failed, device needs reset: virtqueue: HeadOutOfRange { head: 18, size: 16 } (999 similar messages suppressed)macvmm: warn: [virtio-rng-1] guest: virtio: queue 0 failed, device needs reset: virtqueue: HeadOutOfRange { head: 19, size: 16 } (999 similar messages suppressed)macvmm: warn: [virtio-rng-1] guest: virtio: queue 0 failed, device needs reset: virtqueue: BufferOutOfRam { addr: 1140850688, len: 771100 } (999 similar messages suppressed)macvmm: warn: [virtio-rng-1] guest: virtio: queue 0 failed, device needs reset: virtqueue: TooLarge { total: 65537, max: 65536 } (999 similar messages suppressed)macvmm: warn: [virtio-rng-1] guest: virtio: queue 0 failed, device needs reset: virtqueue: IndirectNotNegotiated (999 similar messages suppressed)macvmm: warn: [virtio-rng-1] guest: virtio: queue 0 failed, device needs reset: virtqueue: BufferOutOfRam { addr: 1140850688, len: 218071 } (999 similar messages suppressed)macvmm: warn: [virtio-rng-1] guest: virtio: queue 0 failed, device needs reset: virtqueue: BufferOutOfRam { addr: 1140850688, len: 1 } (999 similar messages suppressed)macvmm: warn: [virtio-rng-1] guest: virtio: queue 0 failed, device needs reset: virtqueue: IndirectNotNegotiated (999 similar messages suppressed)macvmm: warn: [virtio-rng-1] guest: virtio: queue 0 failed, device needs reset: virtqueue: IndirectNotNegotiated (999 similar messages suppressed)macvmm: warn: [virtio-rng-1] guest: virtio: queue 0 failed, device needs reset: virtqueue: IndirectNotNegotiated (999 similar messages suppressed)macvmm: warn: [virtio-rng-1] guest: virtio: queue 0 failed, device needs reset: virtqueue: IndirectNotNegotiated (999 similar messages suppressed)macvmm: warn: [virtio-rng-1] guest: virtio: queue 0 failed, device needs reset: virtqueue: IndirectNotNegotiated (999 similar messages suppressed)macvmm: warn: [virtio-rng-1] guest: virtio: queue 0 failed, device needs reset: virtqueue: IndirectNotNegotiated (999 similar messages suppressed)macvmm: warn: [virtio-rng-1] guest: virtio: queue 0 failed, device needs reset: virtqueue: BufferOutOfRam { addr: 134217728, len: 1807325 } (999 similar messages suppressed)macvmm: warn: [virtio-rng-1] guest: virtio: queue 0 failed, device needs reset: virtqueue: IndirectNotNegotiated (999 similar messages suppressed)macvmm: warn: [virtio-rng-1] guest: virtio: queue 0 failed, device needs reset: virtqueue: IndirectNotNegotiated (999 similar messages suppressed)macvmm: warn: [virtio-rng-1] guest: virtio: queue 0 failed, device needs reset: virtqueue: IndirectNotNegotiated (999 similar messages suppressed)macvmm: warn: [virtio-rng-1] guest: virtio: queue 0 failed, device needs reset: virtqueue: ZeroLength { index: 10 } (999 similar messages suppressed)macvmm: warn: [virtio-rng-1] guest: virtio: queue 0 failed, device needs reset: virtqueue: IndirectNotNegotiated (999 similar messages suppressed)macvmm: warn: [virtio-rng-1] guest: virtio: queue 0 failed, device needs reset: virtqueue: IndirectNotNegotiated (999 similar messages suppressed)macvmm: warn: [virtio-rng-1] guest: virtio: queue 0 failed, device needs reset: virtqueue: IndirectNotNegotiated (999 similar messages suppressed)macvmm: warn: [virtio-rng-1] guest: virtio: queue 0 failed, device needs reset: virtqueue: HeadOutOfRange { head: 18, size: 16 } (999 similar messages suppressed)macvmm: warn: [virtio-rng-1] guest: virtio: queue 0 failed, device needs reset: virtqueue: ZeroLength { index: 13 } (999 similar messages suppressed)macvmm: warn: [virtio-rng-1] guest: virtio: queue 0 failed, device needs reset: virtqueue: HeadOutOfRange { head: 16, size: 16 } (999 similar messages suppressed)macvmm: warn: [virtio-rng-1] guest: virtio: queue 0 failed, device needs reset: virtqueue: HeadOutOfRange { head: 18, size: 16 } (999 similar messages suppressed)macvmm: warn: [virtio-rng-1] guest: virtio: queue 0 failed, device needs reset: virtqueue: BufferOutOfRam { addr: 1140618464, len: 4294967295 } (999 similar messages suppressed)macvmm: warn: [virtio-rng-1] guest: virtio: queue 0 failed, device needs reset: virtqueue: IndirectNotNegotiated (999 similar messages suppressed)macvmm: warn: [virtio-rng-1] guest: virtio: queue 0 failed, device needs reset: virtqueue: AvailIdxJump { avail_idx: 24, next_avail: 0, size: 16 } (999 similar messages suppressed)macvmm: warn: [virtio-rng-1] guest: virtio: queue 0 failed, device needs reset: virtqueue: HeadOutOfRange { head: 16, size: 16 } (999 similar messages suppressed)macvmm: warn: [virtio-rng-1] guest: virtio: queue 0 failed, device needs reset: virtqueue: IndirectNotNegotiated (999 similar messages suppressed)macvmm: warn: [virtio-rng-1] guest: virtio: queue 0 failed, device needs reset: virtqueue: Overflow { addr: 18446744073709551608, len: 4096 } (999 similar messages suppressed)macvmm: warn: [virtio-rng-1] guest: virtio: queue 0 failed, device needs reset: virtqueue: IndirectNotNegotiated (999 similar messages suppressed)macvmm: warn: [virtio-rng-1] guest: virtio: queue 0 failed, device needs reset: virtqueue: BufferOutOfRam { addr: 150994944, len: 669149 } (999 similar messages suppressed)macvmm: warn: [virtio-rng-1] guest: virtio: queue 0 failed, device needs reset: virtqueue: NextOutOfRange { next: 16, table_len: 16 } (999 similar messages suppressed)macvmm: warn: [virtio-rng-1] guest: virtio: queue 0 failed, device needs reset: virtqueue: HeadOutOfRange { head: 16, size: 16 } (999 similar messages suppressed)macvmm: warn: [virtio-rng-1] guest: virtio: queue 0 failed, device needs reset: virtqueue: HeadOutOfRange { head: 18, size: 16 } (999 similar messages suppressed)macvmm: stats: serial_input_dropped=0 serial_input_queued=0 serial_written=440 serial_sink_dropped=0 serial_capped=0 serial_lost=0 serial_filtered=0macvmm: stats: vcpu0 exits: vtimer 0, wfx 0, total 4397722: hvc 445, data abort 4397277macvmm: stats: vcpu0 time: exec 13.414 s, wfi 0.000 smacvmm: stats: vcpu1 exits: vtimer 0, wfx 0, total 1: canceled 1macvmm: stats: vcpu1 time: exec 19.796 s, wfi 0.000 smacvmm: stats: host cpu 41.020 s over 20.246 s wall (203%)macvmm: stats: rlimit core=0 nofile=1048576About 10,600 requests served, about 187,000 attacks ended in a device reset, the canary intact, the image unchanged. Each refusal is the walker's own copy of a descriptor failing a check, whatever vCPU 1 wrote afterwards.
The terminal phase writes the forbidden list to the UART:
cargo run -q -p macvmm -- run --mem 64M --stats --kernel target/guests/aarch64-unknown-none/release/hostile-tty --timeout 10hostile-tty: beginlink6n52;c;AAAA\x076nhostile-tty: 22 attack strings senthostile-tty: endmacvmm: stats: serial_input_dropped=0 serial_input_queued=0 serial_written=91 serial_sink_dropped=0 serial_capped=0 serial_lost=0 serial_filtered=160macvmm: stats: vcpu0 exits: vtimer 0, wfx 0, total 610: hvc 1, data abort 609macvmm: stats: vcpu0 time: exec 0.000 s, wfi 0.000 smacvmm: stats: host cpu 0.001 s over 0.001 s wall (115%)macvmm: stats: rlimit core=0 nofile=1048576The odd middle line is all that is left of 22 attack strings: link is a hyperlink's text. 6n and 52;c;AAAA are the tails of a status query and a clipboard write sent with a one-byte introducer (0x9B, 0x9D): the filter drops that byte, so the rest is inert text. (0x9D is the one-byte form of ESC ], which starts an operating system command, OSC.) \x07 is how the capture shows one BEL (bell) byte, 0x07, allowed at most once a second. The final 6n is the same status query again, its introducer encoded as UTF-8 (U+009B, bytes C2 9B), dropped the same way. Nothing left can make a terminal act. The reset storm is the one phase whose correct ending is a fatal stop:
cargo run -q -p macvmm -- run --mem 64M --kernel target/guests/aarch64-unknown-none/release/hostile-reset --timeout 30hostile-reset: boot 0hostile-reset: boot 1hostile-reset: boot 2hostile-reset: boot 3hostile-reset: boot 4hostile-reset: boot 5hostile-reset: boot 6hostile-reset: boot 7hostile-reset: boot 8hostile-reset: boot 9hostile-reset: boot 10macvmm: guest fatal: reset storm: more than 10 resets within 10 sTying our own hands: the sandbox
Suppose a bug survives all that and a guest runs code inside macvmm. Our one entitlement is a permission, not a fence (the codesign-entitlements primer): the process can still read ~/.ssh, open sockets and start a shell. Chapter 19 named what we want instead, containment. The fence is a sandbox, rules the kernel enforces on a process: sandbox_init (the macos-sandbox primer), applied once, irrevocably, with a profile. macvmm's base profile is (deny default) with almost nothing allowed:
/// The lockdown profile (module docs). SBPL, the Scheme dialect of macOS's Seatbelt./// Rules are matched last-to-first with `deny default` as the fallback; the explicit denials/// restate the policy for the reader (and keep it if a later edit adds a broad `allow`).pub const PROFILE: &str = r#"(version 1)(deny default)(allow sysctl-read)(allow file-ioctl (ioctl-command TIOCSETA) (ioctl-command TIOCSETAW) (ioctl-command TIOCSETAF) (ioctl-command TIOCFLUSH))(deny file-read* file-write* file-write-create)(deny network*)(deny process-exec* process-fork)"#;Four ioctls (device commands, here to the terminal) are allowed so the exit path can restore your terminal settings; TIOCSTI, which fakes typed input, stays denied. There is no mach-lookup and no iokit-open: Hypervisor.framework needs neither to create, run, destroy and re-create a virtual machine (VM). One thing is added per run: for each --net ...,peer=PATH (chapter 19), profile_for appends an allow network-outbound rule for exactly that Unix socket, plus metadata reads of the symbolic links on its path. --net ...,learn is refused while the sandbox is on, because its peer is not known when the profile is written: it is a usage error (exit code 2) that tells you to use peer=PATH or --no-sandbox. Three tests checked this on a real Mac: four vCPUs created after the lockdown, an in-process reboot that builds a new VM under it, and the limits line:
cargo test -p macvmm --features hvf-tests --test e2e_sandbox -- sandbox_smp sandbox_reboot rlimit_stats --test-threads=1running 3 teststest rlimit_stats ... oktest sandbox_reboot ... oktest sandbox_smp ... oktest result: ok. 3 passed; 0 failed; 0 ignored; 0 measured; 10 filtered out; finished in 1.84s Compiling libc v0.2.191 Compiling hvf v0.1.0 (<tree>/crates/hvf) Compiling xtask v0.1.0 (<tree>/crates/xtask) Compiling vmm v0.1.0 (<tree>/crates/vmm) Compiling fuzz v0.1.0 (<tree>/crates/fuzz) Compiling macvmm v0.1.0 (<tree>/crates/macvmm) Finished `test` profile [unoptimized + debuginfo] target(s) in 2.63s Running tests/e2e_sandbox.rs (target/debug/deps/e2e_sandbox-de903fff9661cc90)When matters as much as what. The sandbox checks a resource when it is acquired, so run first opens every file and starts every host thread (the terminal, the signal thread, the stdin thread):
let interactive = host.stdin != StdinBinding::Unbound;let mut terminal = term::Terminal::setup(interactive);if terminal.is_raw() { err("macvmm: console attached; Ctrl-A x quits, Ctrl-A h lists the escapes");}if let Err(e) = signals::spawn(Arc::clone(&host)) { err(&format!("macvmm: cannot install the signal handlers: {e}")); return ExitCode::from(1);}if interactive && let Err(e) = term::spawn_stdin(Arc::clone(&host)) { err(&format!("macvmm: cannot start the stdin thread: {e}")); return ExitCode::from(1);}and only then locks down, before the first guest instruction:
if let Err(line) = confine(sandbox, &cfg) { // Fail closed: only `--no-sandbox` runs unconfined, never a failed lockdown. Nothing ran // yet; undo the terminal and stop. host.close_sinks(&[]); terminal.restore(); err(&line); return ExitCode::from(1);}let result = vmm::run(&cfg, &host);This runs on every macvmm run: the sandbox is on by default. A protection you have to remember to ask for protects nobody on the day you forget, and the list of what it costs is short: everything a VM does after the lockdown works under it (the e2e suites all pass with it on), and only ,learn needs it off. --no-sandbox turns it off, for debugging; --sandbox is still accepted and changes nothing, so older scripts keep working; giving both is a usage error (exit code 2), because one of them must be a mistake. confine, above it, fails closed: if the lockdown fails, macvmm exits 1 and names --no-sandbox; only --sandbox=best-effort warns and runs without it. The lockdown first drops the file-descriptor limit (RLIMIT_NOFILE, nofile= in --stats) to one past the highest descriptor in use, plus 16. The profile still lets the process create descriptors that need no path, so the cap bounds how many a compromised macvmm could hoard; the 16 spare cover what later work opens without a path, such as vCPU threads and the new VM of a reboot:
/// Lower `RLIMIT_NOFILE`, then apply the profile (module docs: timing)./// Irrevocable. `Err` is the reason; the caller decides between exit 1 and a warning.pub fn lockdown(cfg: &VmConfig) -> Result<Lockdown, String> { let profile = profile_for(cfg)?; let (soft, _) = hvf::host::get_rlimit(hvf::host::RLIMIT_NOFILE) .map_err(|e| format!("getrlimit(RLIMIT_NOFILE): {e}"))?; let scan = i32::try_from(soft.min(1 << 16)).unwrap_or(1 << 16); let highest = hvf::host::highest_open_fd(scan).unwrap_or(2); let nofile = u64::try_from(highest) .unwrap_or(2) .saturating_add(1) .saturating_add(NOFILE_SLACK) .min(soft); hvf::host::set_rlimit(hvf::host::RLIMIT_NOFILE, nofile) .map_err(|e| format!("setrlimit(RLIMIT_NOFILE, {nofile}): {e}"))?; hvf::host::sandbox_init_profile(&profile).map_err(|e| format!("sandbox_init: {e}"))?; Ok(Lockdown { nofile })}The sandbox_init call is one of the few unsafe blocks, in the hvf crate. Its header declares it deprecated, and passing profile text rather than a built-in profile name is undocumented. Deprecated means Apple may stop honouring it in a future macOS. If the call ever started failing, a silent fallback would run the guest unconfined while you believed otherwise, so the sandbox treats any failure as fatal:
unsafe extern "C" { fn sandbox_init( profile: *const libc::c_char, flags: u64, errorbuf: *mut *mut libc::c_char, ) -> libc::c_int; fn sandbox_free_error(errorbuf: *mut libc::c_char);}/// Apply the SBPL `profile` to this process, irrevocably (`sandbox_init(profile, 0, &err)`)./// `Err` carries libsandbox's message (for example a profile syntax error, or "already in a/// sandbox"). Threads that exist keep running under the new profile.pub fn sandbox_init_profile(profile: &str) -> Result<(), String> { let c = std::ffi::CString::new(profile).map_err(|_| "the profile contains a NUL byte")?; let mut err: *mut libc::c_char = core::ptr::null_mut(); // SAFETY: `c` is a NUL-terminated string that outlives the call; `err` is a live, writable // `char *` slot that `sandbox_init` sets to NULL or to a string it allocated. let rc = unsafe { sandbox_init(c.as_ptr(), 0, &mut err) }; let msg = if err.is_null() { None } else { // SAFETY: on error `sandbox_init` stored a NUL-terminated string it owns in `err`; we // copy it before freeing it below. let m = unsafe { std::ffi::CStr::from_ptr(err) } .to_string_lossy() .into_owned(); // SAFETY: `err` came from `sandbox_init` and is freed exactly once, as `sandbox.h` // requires; it is not used afterwards. unsafe { sandbox_free_error(err) }; Some(m) }; match (rc, msg) { (0, _) => Ok(()), (_, Some(m)) => Err(m), (rc, None) => Err(format!("sandbox_init returned {rc}")), }}Two smaller defences run first in main, sandbox or not. RLIMIT_CORE goes to 0, soft and hard: no core dumps (a core would be a file full of guest RAM). That one is a one-way door, since an unprivileged process cannot raise its hard limit again. The umask of 077 is only a default, which any code in the process could change, but it makes sure that only you can read what macvmm creates during set-up:
fn harden_process() -> std::io::Result<()> { hvf::host::set_umask(0o077); hvf::host::set_rlimit(hvf::host::RLIMIT_CORE, 0)}The hidden --sandbox-selftest flag tries three things after the lockdown and requires each to be refused:
pub fn selftest() -> Result<String, String> { let mut bad = Vec::new(); if let Err(e) = denied("open", hvf::host::probe_open("/etc/hosts"), &[]) { bad.push(e); } match hvf::host::probe_connect_loopback() { Err(e) if e.raw_os_error() == Some(ECONNREFUSED) => { bad.push("socket connect ALLOWED (ECONNREFUSED: it reached the network stack)".into()) } r => { if let Err(e) = denied("socket connect", r, &[]) { bad.push(e); } } } if let Err(e) = denied("spawn", hvf::host::probe_spawn("/usr/bin/true"), &[]) { bad.push(e); } if bad.is_empty() { Ok("sandbox: open denied, socket denied, spawn denied".into()) } else { Err(format!("sandbox: self-test FAILED: {}", bad.join(", "))) }}cargo run -q -p macvmm -- run --mem 64M --sandbox-selftest --stats --kernel target/guests/aarch64-unknown-none/release/hello --timeout 10cargo run -q -p macvmm -- run --mem 64M --sandbox-selftest --stats --kernel target/guests/aarch64-unknown-none/release/hello --timeout 10hello from guest, x0=0x40000000guest donemacvmm: sandbox: open denied, socket denied, spawn deniedmacvmm: stats: serial_input_dropped=0 serial_input_queued=0 serial_written=43 serial_sink_dropped=0 serial_capped=0 serial_lost=0 serial_filtered=0macvmm: stats: vcpu0 exits: vtimer 0, wfx 0, total 44: hvc 44macvmm: stats: vcpu0 time: exec 0.000 s, wfi 0.000 smacvmm: stats: host cpu 0.000 s over 0.000 s wall (116%)macvmm: stats: rlimit core=0 nofile=21No sandbox flag was needed: the default run locked down, and the guest ran to completion under the profile. With --no-sandbox:
cargo run -q -p macvmm -- run --mem 64M --no-sandbox --stats --kernel target/guests/aarch64-unknown-none/release/hello --timeout 10hello from guest, x0=0x40000000guest donemacvmm: stats: serial_input_dropped=0 serial_input_queued=0 serial_written=43 serial_sink_dropped=0 serial_capped=0 serial_lost=0 serial_filtered=0macvmm: stats: vcpu0 exits: vtimer 0, wfx 0, total 44: hvc 44macvmm: stats: vcpu0 time: exec 0.000 s, wfi 0.000 smacvmm: stats: host cpu 0.000 s over 0.000 s wall (119%)macvmm: stats: rlimit core=0 nofile=1048576core=0 in both, and the file-descriptor limit is 21 under the sandbox against 1,048,576 without it (the unsandboxed number is inherited from your shell). The kernel also reports each denial to the unified log, as the primer showed. --last 10s only covers the last ten seconds, so run log show within ten seconds of the self-test, or widen it to --last 1m:
log show --last 10s --style compact --predicate 'eventMessage BEGINSWITH "Sandbox: macvmm"'Timestamp Ty Process[PID:TID]2026-11-20 01:14:37.977 E kernel[0:73ca05c] (Sandbox) Sandbox: macvmm(84685) deny(1) file-read-metadata /etc2026-11-20 01:14:37.977 E kernel[0:73ca05c] (Sandbox) Sandbox: macvmm(84685) deny(1) network-outbound remote:*:12026-11-20 01:14:37.977 E kernel[0:73ca05c] (Sandbox) Sandbox: macvmm(84685) deny(1) process-forkThe open of /etc/hosts died resolving the symbolic link /etc (on macOS, /etc is a link to /private/etc, the macos-sandbox primer), the connect as network-outbound, the spawn at process-fork. The socket itself was created: only its use was refused.
Production note
Inside the sandbox the process keeps what it holds: guest RAM, the opened disks, the hypervisor. Production VMMs such as crosvm also confine each device in its own process.
Security
The fuzzer asks "is there a bug in the parsers?", the hostile guest "does the whole VMM survive a guest that misbehaves on purpose?", the sandbox "if both missed one, what does the attacker get?". Rely on only one and you fail the day it misses.
Your turn
The reference shows the finished harness; yours goes in learner/crates/fuzz/. Items 1 to 4 belong to sitting A, before the stopping point; items 5 to 7 to sitting B.
- Create the crate: package and binary both named
fuzz, a workspace member depending onvmmas{ path = "../vmm", features = ["test-util"] }and on nothing outside the workspace. Writerng.rs, theTargetstruct and the loop. The checkpoint runsfuzz virtqueue --seconds S --seed 1and reads two things: a finding prints a line containingFAILURE(orHANG) and exits 1; a clean run exits 0. Add--replay FILE; check that one seed always gives the same iteration numbers. One trap: the checkpoint builds your fuzzer against the reference'svmm, not yours, so use only the names the reference exports:vmm::virtio::Queue(itspopandadd_used),vmm::virtio::DescriptorChain::into_validated,vmm::virtio::ValidatedChainandDescriptor,vmm::memory::VecMemory(behind thetest-utilfeature) andvmm::memory::prelude::*. If your own walker uses other names, add aliases in yourvmmwith the reference's names. - Write the virtqueue target through those functions (
pop,into_validated,add_used); choose your own input layout, or copy the one above. Start with invariants 2 and 4, then add 3 and 5. - Add
--minimise FILE, the chunk-zeroing loop above, writing the smallest failing input next to the original. Minimise each planted bug's reproducer and note its non-zero byte count. - Plant each bug by hand in a copy of your own tree: delete the hop-budget decrement; check a buffer's first and last byte separately with wrapping addition; take the used slot modulo
N + 1; re-read a descriptor after validating it; and the verdict cache, skipping the RAM check when a buffer's address equals the one two hops earlier. Record how long your fuzzer takes on each, and write its times for the hop budget and the verdict cache under your journal's Predict entry, next to ours. - Optional: write a second target, for the virtio-mmio register file or the Image header, with one invariant each.
- Run each hostile phase in the table on your VMM, from
learner/, with the flags in its capture. Every phase must end with its exit code; fix what does not. - Write
sandbox.rs(the profile,profile_forwith its--netpeers,lockdown, the self-test) and callharden_processfirst inmain. Make the lockdown the default, with--no-sandboxto opt out,--sandboxaccepted as a no-op and--sandbox=best-effort;--sandboxtogether with--no-sandboxis a usage error (exit code 2). Add the hidden--sandbox-selftest, and the--statslinemacvmm: stats: rlimit core=0 nofile=N. Call the lockdown after every file is open and every thread exists, asrundoes above. The self-test must print exactlysandbox: open denied, socket denied, spawn deniedon stderr (after themacvmm:prefix), the line the checkpoint matches. - Finish your threat model, then compare it with the reference's, row by row.
Stuck? scripts/learner hint 25 gives a ladder of hints, from the concept to the reference file to read. Read the matching reference file only after a real attempt.
Checkpoint
Back at the repository root, run:
Checkpoint
Needs a MacRun this from the repository root:
scripts/checkpoint.sh 25You should see, as the last line:
CHECKPOINT 25 PASSThe plants cannot apply to your walker, so the checkpoint brings your fuzzer to them: it copies the reference's crates, puts your crates/fuzz in place of ours, applies one plant, builds, and runs fuzz virtqueue --seed 1. If it reports that the fuzzer "does not build against the reference", your fuzzer uses a name the reference's vmm lacks (Your turn, item 1). It checks:
- a 20-second control on the unplanted reference finds nothing (a fuzzer that reports everything proves nothing);
- plants 1 to 3 (the missing
checked_add, the missing hop budget, the ring-index off-by-one) are each found within ten minutes, build included, each printing a line such asbughunt: plant 2 (missing hop budget) found after 0s; - the sandbox self-test with
hello, with no sandbox flag, prints the three denials and exits 0, and--statsshowsrlimit core=0both then and with--no-sandbox; - each hostile phase on your VMM ends with its exit code and the guest's lines; no forbidden escape sequence in stdout, a flood file of exactly 1 MiB, an unchanged read-only disk, every TOCTOU-phase MMIO access in the virtio window;
- your journal answers every question.
Against a copy of the reference:
scripts/checkpoint.sh 25[INFO] contract tests none for this chapter[PASS] runs on your Mac bughunt-control: 1/1 serial markers, exit 0 in 24.11s[PASS] runs on your Mac bughunt-1: 1/1 serial markers, exit 0 in 3.95s[PASS] runs on your Mac bughunt-2: 1/1 serial markers, exit 0 in 3.71s[PASS] runs on your Mac bughunt-3: 1/1 serial markers, exit 0 in 3.64s[PASS] runs on your Mac sandbox-check: 4/4 serial markers, exit 0 in 0.07s[PASS] runs on your Mac rlimit-check: 3/3 serial markers, exit 0 in 0.01s[PASS] runs on your Mac phase-mmio: 9/9 serial markers, exit 0 in 0.25s[PASS] runs on your Mac phase-isv0: 3/3 serial markers, exit 0 in 0.01s[PASS] runs on your Mac phase-sysreg: 4/4 serial markers, exit 0 in 0.03s[PASS] runs on your Mac phase-smccc: 4/4 serial markers, exit 0 in 0.06s[PASS] runs on your Mac phase-vq-empty: 3/3 serial markers, exit 0 in 0.10s[PASS] runs on your Mac phase-vq-rng: 5/5 serial markers, exit 0 in 0.11s[PASS] runs on your Mac phase-vq-blk: 7/7 serial markers, exit 0 in 0.45s[PASS] runs on your Mac phase-toctou: 10/10 serial markers, exit 0 in 25.35s[PASS] runs on your Mac phase-tty: 4/4 serial markers, exit 0 in 0.03s[PASS] runs on your Mac phase-reset: 3/3 serial markers, exit 3 in 0.02s[PASS] runs on your Mac phase-flood: 1/1 serial markers, exit 0 in 7.57s[INFO] journal not checked (not a learner tree)CHECKPOINT 25 PASSWhat now works:
- a threat model naming the mechanism that guards each asset;
- a dependency-free fuzzer whose invariants find bugs that never panic, with replayable, minimised reproducers;
- a VMM that survives a guest attacking it on purpose;
- a process that, after set-up, can open no file, reach no network except the configured virtio-net peer socket, start no process, and never dumps core.
The next chapter starts from this state (the reference at the end of chapter 25).
What's next
Chapter 26, planned for after the course's first release, freezes a running VM to a file and brings it back in a fresh process. A snapshot is not a memory dump: the Generic Interrupt Controller (GIC), the timers and in-flight disk requests hold state that RAM does not, and the file itself is hostile input the moment it touches disk.
Open question
Your fuzzer is structure-aware: its input generator and mutations encode what you believe a ring looks like. Which input shape does it never generate, and what bug could hide there?
Spec hunt
- virtio 1.2, section 2.7.5.3.1 "Driver Requirements: Indirect Descriptors": which combinations of
INDIRECTandNEXTmay a driver not send, and which of them does your fuzzer's flag-flip mutation produce? man 2 setrlimit, theRLIMIT_COREentry and the paragraph on hard limits: why does macvmm set both the soft and the hard value to 0, and what could a compromised macvmm do if only the soft value were 0?- ECMA-48, section 5.6 "Control strings": which introducers start an operating system command and a device control string, and how does a filter know where such a string ends?