notes

Proving things about kernel/src

Milestone 193. The companion to verification.md, which is about proving the pure crates; this one is about the 64,818 lines the prover could not see until 2026-08-30, and about the stubs you take on when you point it at them.

Name provisional: notes are an interface and their names are an architect's call (AGENTS.md). kernel-proofs says what the file is about and matches verification.md's neighborhood; expect it to change.

Why this note exists at all

Milestone 191 asked whether any Kani harness in this tree had ever caught a defect after the day it was written. None had. The cause was one line in script/verify's own header, which has always been honest about it.

cargo kani -p <crate> never compiles the kernel, the user programs, or xtask.

So every proof in the tree was aimed at pure logic, and every concurrency, hardware-contract and resource-accounting defect the corpus recorded lived somewhere else. DECISIONS §14 promises a verified core and the core was the part not being verified.

The distance turned out to be four changes.

What it took, exactly

cargo check -p kernel --target aarch64-apple-darwin failed with three errors before this milestone, and cargo kani -p kernel with two more once those were gone. All five, and the fix for each:

what stopped it why the fix
unwinding panics are not supported without std the workspace deliberately does not set panic = "abort" (DECISIONS §7) nothing: Kani passes -C panic=abort itself, so this is a cargo check problem and not a cargo kani one
invalid Mach-O section specifier, twice #[unsafe(link_section = ".interrupt_stacks")] and ".secondary_stacks" are ELF section names, and the dev machine's host target is Mach-O #[cfg_attr(target_os = "none", ...)], because the linker script that gives those sections meaning exists only for the bare-metal build
found duplicate lang item panic_impl Kani links std into the crate it proves, and std already defines the panic handler #[cfg(not(kani))] on kernel/src/panic.rs's handler
Crate kernel contains global ASM, which is not supported by Kani eleven global_asm! blocks: the boot entry, the vector table and the context switch, on all three architectures -Z unstable-options --ignore-global-asm, in script/verify's kernel case

That is the whole list. DECISIONS §4 (kernel shape) rule 1 is why it is this short. Architecture-specific code lives under kernel/src/arch/, so asm! appears outside it at only three sites in two files (cpu.rs once, user.rs twice) and the other ~50,000 lines are ordinary Rust that a host compiler was always going to accept. A tree that had let asm! spread would have had no front door here.

The stub boundary, enumerated

A proof with an unexamined stub is worse than no proof, because it reads as coverage. This is the exhaustive list of what a harness in kernel/src cannot see. The same list is in system_call.rs's mod proofs, where the next harness's author will meet it.

  1. Global assembly is skipped. Boot entry, vectors, context switch, three architectures. No harness reaches it, or could.

  2. asm! is an unsupported construct. Every asm! site in kernel/src/arch/, plus the three above. This is a hard boundary: if a harness ever calls into that code, Kani reports the unsupported construct instead of proving past it.

    The boundary is asm! and MMIO, not the directory arch/: 4,004 of arch/'s 16,225 lines are in files containing no asm! at all, and arch/aarch64/iommu.rs has its proofs in place. The architecture layer is still mostly unverified, and the timer re-arm drift is on the far side of this line.

    A stub can cross it, at a price: kernel-proofs/stubbing-an-instruction.md.

  3. Two thirds of kernel/src/arch/ is not compiled at all, and this is a cfg rather than a construct (milestone 304, 2026-09-16). arch/mod.rs selects its subtree with #[cfg(target_arch = ...)] and Kani compiles for the host, so a run sees exactly one architecture's arch/ and no line of the other two (item 8 is the one exception). Unlike items 1 and 2 it is silent: an asm! site makes Kani report an unsupported construct, and a cfg-excluded file produces no diagnostic of any kind. The kernel row runs on two hosts and, via script/verify-riscv64, a third target; see below.

  4. The panic handler is absent. Nothing proved here says anything about what the kernel does after a panic.

  5. The link sections are absent: every custom-section link_section under kernel/src carries the target_os = "none" gate, because a bare-metal section means nothing to a host compile. Under cfg(kani) the host target is not target_os = "none", so STACKS and SECONDARY_STACKS are ordinary statics rather than statics in their own regions. A harness reasoning about guard-page layout would therefore be reasoning about a fiction. Do not write one; the_secondary_stack_region_is_the_size_the_linker_reserved holds the region-size claim in a real build instead.

  6. MMIO and fixed physical addresses are raw pointers to nothing under a model checker. The same argument applies: stub the boundary, do not pretend.

    Measured 2026-09-20, it is louder than that (the maintainer/verus-versus-kani lane, notes/verus.md). A harness doing read_volatile on 0x0800_0000, QEMU virt's GICv2 distributor, does not quietly reason about a fiction: CBMC has no object at that address and reports dereference failure: pointer NULL, pointer outside object bounds and invalid integer address. So this is a hard boundary like item 2, the good direction. Stub it anyway; the point of the item stands.

  7. script/lint's harness-clippy pass excludes kernel, so clippy lints do not fire inside these harnesses. That pass's own comment carries the two tooling reasons and what still covers them. Keep kernel harnesses free of unsafe.

  8. Where an aarch64 host proves arch/riscv64/iommu.rs, crate::arch is aarch64's: kernel-proofs/riscv64-from-an-aarch64-host.md.

What is proved today

Two properties in kernel/src/system_call.rs are about run_end_virtual_address and the map loops that guard on it. Milestone 193 (put kernel/src within reach of the prover) predicted this code would never become a crate, rightly: system call dispatch is a boundary, not a library.

run_end_virtual_address computes the last virtual address a count-page run starting at va covers.

And three in kernel/src/arch/aarch64/iommu.rs (milestones 255 and 1066)

The SMMUv3 driver, aarch64's IOMMU, has no asm! in it, and it computes which physical addresses a device may touch (design/fatal-risks/README.md risk 7). Five functions beside attach hold its word arithmetic. the_smmu_is_handed_exactly_the_tables_the_kernel_built: each address split across two words reads back exactly, and no address bit lands on a control field. no_stream_can_reach_another_streams_tables: the table places exactly the ids below its width, refuses the rest, and keeps each entry inside its leaf and apart from every other. the_level_one_table_names_exactly_the_leaf: the level-one descriptor and the configuration word. Patches that leave every test green falsify all three. The register constants are unproved, and a property proved of the SMMUv3 is not proved of the other two IOMMUs. The detail is in kernel-proofs/smmu-proofs.md.

And two in kernel/src/arch/x86_64/interrupt_controller.rs (milestone 304)

The first properties this tree has checked on arch/x86_64/, which no Kani job compiled before milestone 304 added an x86_64 runner. no_vector_belongs_to_two_bands is MSI_VECTOR_BASE's claim that the three vector bands are "disjoint by construction rather than by anybody remembering". an_owned_gsi_routes_inside_the_io_apic_band found a defect, which the harness carries as an assumption: a second IO APIC owning GSIs from 200 lets gsi_vector(210) wrap onto vector 2, the NMI. It is not fixed here; see interrupt_controller.rs's module BUGS and design/roadmap/proposals/the-gsi-vector-map-wraps-on-a-second-io-apic.md. Both were falsified by hand and are recorded attested, because the sweep cannot run an x86_64 harness on an aarch64 host. The detail is in kernel-proofs/x86-interrupt-controller-proofs.md.

And four in kernel/src/sched/region_reaping/verification.rs

reap_decision and survey_includes name no architecture, so their four harnesses run on every host. They are claims 6 to 9 of the confinement claims.

Which architecture the prover actually sees

One, and it is the host's (milestone 304). This is stub-list item 3, as a table because it is most often read as more coverage than it is.

host arch/ subtree compiled harnesses that run
aarch64 (dev Mac; ubuntu-26.04-arm runners) arch/aarch64/, and arch/riscv64/iommu.rs 13: two in system_call.rs, four in region_reaping/verification.rs, three in each iommu.rs, one in fp.rs
x86_64 (cordoba; the ubuntu-26.04 runner) arch/x86_64/ 11: the same six, two in interrupt_controller.rs, two in iommu.rs, one in fp.rs
either, via script/verify-riscv64 arch/riscv64/, natively 12: the same six, three in iommu.rs, three in mmu.rs

Eighteen distinct harnesses on the first two hosts, since the six in system_call.rs and region_reaping/verification.rs run on both.

riscv64 needed a target, not a host: milestone 589 (Kani can prove riscv64 from the hosts we already have) patches Kani, since CBMC runs anywhere. See kernel-proofs/riscv64-with-a-patched-kani.md.

One thing had to change before an x86_64 host could compile the kernel at all. core::arch::x86_64::__cpuid is a safe function on the toolchain this tree pins and was an unsafe fn until upstream changed it; Kani bundles its own rustc, kani-0.67.0 pinning nightly-2025-11-21. So four bare __cpuid calls in arch/x86_64/ were four E0133s under the prover and nowhere else. They are wrapped in isa::cpuid and isa::cpuid_count, whose #[allow(unused_unsafe)] is a labeled exception that comes out when Kani's pin catches up.

Why these two and not the timer

Milestone 193's block nominates the milestone 6 timer re-arm drift as the first property worth trying, on the grounds that its property is already proved in crates/timetable's next_after and the timer does not call it. That is still a good future lane, but the re-arm is in kernel/src/arch/aarch64/timer.rs and kernel/src/arch/riscv64/timer.rs, which item 2 above puts out of reach: rearm reads CNTVCT_EL0 and writes CNTV_CVAL_EL0, both asm!. Both are accessors in arch/aarch64/instructions.rs, which a harness can stub. Proving it means first lifting the arithmetic out of the register accesses, and where that seam goes is a design question.

run_end_virtual_address was chosen because it has a real defect on record, the criterion milestone 191 (did the proofs catch the bugs?) put first. In the review of milestone 142 (a text display good enough that people use it), MAJOR 4 found it checking only the addition in `va.checked_add((count -

    • PAGE_SIZE): the multiply wrapped, so a large count` admitted a run spanning the address space.

EXAMPLES

Prove just the kernel's harnesses, with a counterexample trace on failure:

$ cargo kani -p kernel -Z unstable-options --ignore-global-asm
...
Complete - 6 successfully verified harnesses, 0 failures, 6 total.

One harness on its own:

$ cargo kani -p kernel -Z unstable-options --ignore-global-asm \
      --harness the_run_end_is_exact_and_refuses_exactly_what_does_not_fit

The whole suite, kernel included, the way CI runs it:

$ script/verify

Just the kernel row, which is what the x86_64 CI job runs and the only row whose coverage depends on the machine it runs on:

$ script/verify --only kernel

Falsify a new harness before you believe it. This is the tree's standing discipline for proofs (verification.md says the same) and milestone 191 is the reason it is not optional. Re-introduce the historical defect and check that both harnesses go red:

$ # in run_end_virtual_address, replace the checked arithmetic with milestone 142's bug:
$ #   va.checked_add((count - 1).wrapping_mul(page_tables::PAGE_SIZE))
$ cargo kani -p kernel -Z unstable-options --ignore-global-asm --output-format=terse
Verification failed for - system_call::proofs::every_page_between_the_checked_ends_is_itself_a_user_page
Verification failed for - system_call::proofs::the_run_end_is_exact_and_refuses_exactly_what_does_not_fit
Complete - 0 successfully verified harnesses, 2 failures, 2 total.

Both catch it. That run, on 2026-08-30, is why these two harnesses earn their place rather than an assertion.

Adding a harness to kernel/src

  1. Put it beside the code it proves, in a #[cfg(kani)] mod proofs, not in a separate file. The stub list above is the reason: a reader has to meet the caveats where they meet the harness.
  2. Check the call graph against the stub list. If it reaches asm! or MMIO, stop; you are proving nothing, and Kani will say so rather than lie. crate::arch itself is no longer the boundary (milestones 255 and 304 put harnesses inside two of its three subtrees), but ask which architecture you are in. A harness under arch/<isa>/ runs only on an <isa> host, and a riscv64 one only under script/verify-riscv64. That failure is silent, unlike the asm! one.
  3. Falsify it. Break the code under it and watch the harness fail, then put the code back.
  4. kernel is already in script/verify's crate table, so nothing needs adding there. If you add a harness to a crate that is not in that table, script/lint's "every crate with proof harnesses is in the verify table" check will fail; that gate exists because two crates (multicast_dns_protocol, jh7110_entropy) each spent months carrying harnesses nothing ran.

BUGS