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.
-
Global assembly is skipped. Boot entry, vectors, context switch, three architectures. No harness reaches it, or could.
-
asm!is an unsupported construct. Everyasm!site inkernel/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 directoryarch/: 4,004 ofarch/'s 16,225 lines are in files containing noasm!at all, andarch/aarch64/iommu.rshas 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.
-
Two thirds of
kernel/src/arch/is not compiled at all, and this is acfgrather than a construct (milestone 304, 2026-09-16).arch/mod.rsselects its subtree with#[cfg(target_arch = ...)]and Kani compiles for the host, so a run sees exactly one architecture'sarch/and no line of the other two (item 8 is the one exception). Unlike items 1 and 2 it is silent: anasm!site makes Kani report an unsupported construct, and acfg-excluded file produces no diagnostic of any kind. Thekernelrow runs on two hosts and, via script/verify-riscv64, a third target; see below. -
The panic handler is absent. Nothing proved here says anything about what the kernel does after a panic.
-
The link sections are absent: every custom-section
link_sectionunderkernel/srccarries thetarget_os = "none"gate, because a bare-metal section means nothing to a host compile. Undercfg(kani)the host target is nottarget_os = "none", soSTACKSandSECONDARY_STACKSare 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_reservedholds the region-size claim in a real build instead. -
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-kanilane,notes/verus.md). A harness doingread_volatileon0x0800_0000, QEMUvirt's GICv2 distributor, does not quietly reason about a fiction: CBMC has no object at that address and reportsdereference failure: pointer NULL,pointer outside object boundsandinvalid integer address. So this is a hard boundary like item 2, the good direction. Stub it anyway; the point of the item stands. -
script/lint's harness-clippy pass excludeskernel, 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 ofunsafe. -
Where an aarch64 host proves
arch/riscv64/iommu.rs,crate::archis 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.
the_run_end_is_exact_and_refuses_exactly_what_does_not_fit. For everyvaand everycount >= 1: aSome(last)is exactlyva + (count - 1) * PAGE_SIZEcomputed without wrapping, and aNoneis exactly a run that does not fit in au64. The claim is stated inu128, so the harness does not echo the implementation's expression.every_page_between_the_checked_ends_is_itself_a_user_page. Both mapping paths checkvaand the run's last address and then walkva + k * PAGE_SIZEforkin0..countwith nothing re-checking the pages between. Given the two endpoints passis_user_page_virtual_address, every page in the run does too, and no page is computed past the checked end.kis symbolic rather than iterated, so this covers every page of every run with no unwind bound.
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 largecount` admitted a run spanning the address space.
- PAGE_SIZE)
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
- 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. - 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::architself 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 underarch/<isa>/runs only on an<isa>host, and ariscv64one only under script/verify-riscv64. That failure is silent, unlike theasm!one. - Falsify it. Break the code under it and watch the harness fail, then put the code back.
kernelis already inscript/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
kernel/src/arch/is very nearly unproved, and the part that is proved is two files. Milestone 255 put two harnesses intoarch/aarch64/iommu.rsand milestone 304 two intoarch/x86_64/interrupt_controller.rs; that is 1,279 of 16,225 lines. The corpus's own timer re-arm drift is still on the far side of theasm!boundary and nothing here touches it. (The VisionFive 2 wake once paired with it is retracted, innotes/visionfive2.md.)- Only one architecture's
arch/is compiled per run. Milestone 304 (cargo kani -p kernelonly ever compiled one architecture) added an x86_64 runner to the aarch64 one, and milestone 589 a riscv64 job, so every subtree is compiled by some job. Since milestone 587 (most CI jobs do not need an arm64 host) theproveshards are the x86_64 half andprove the kernel on aarch64is the other. No single run sees more than one.x86_64/machine.rsis the work this unblocked and did not do: 836 lines of ACPI parsing over lengths, checksums and counts that firmware supplied, now reachable for the first time and still carrying no harness. Its parsing half already lives incrates/machine_discovery, which has no harnesses and no verify row; the half inmachine.rsreads raw pointers into the direct map, which stub-list item 6 says to stub rather than pretend. Finding that seam is a lane of its own. - Eight harnesses is not coverage of an 85,940-line crate, and the number to watch is not the count but whether the properties are ones a defect would violate. The two here were chosen because a defect did violate them.
--ignore-global-asmis a global switch, not a per-item one. A futureglobal_asm!block that a harness genuinely needs would be skipped silently rather than refused. The reason it is acceptable today is that Kani'sasm!restriction makes any such harness fail for a second, louder reason. "Nothing detects that" was too strong (measured 2026-09-20 by themaintainer/verus-versus-kanilane). Every run printswarning: Ignoring global ASM in crate kernel. Verification results may be impacted.That is per-run rather than per-item, so it cannot say which block was skipped or whether anyone cared, which is the substance of the entry. But the run is not silent about having done it.user/andxtaskare still out of reach, for exactly the reason the kernel was.user/holds real parsers over untrusted input and has at least as good a claim on the prover as the kernel does. Not attempted here.- The
kernelrow's 5 seconds inscript/verify's table is a dev-Mac number, likejh7110_entropy's, and the wrong machine for that column. Replace it from the first CI log that carries it. Almost all of it is the crate's own compile rather than solver time, so it will grow with the harnesses and not with the kernel. - The
kernelrow is proved on two hosts and means something different on each, which no single number inscript/verify's table can say. Its seconds column is one figure for two jobs, and the harness count a reader would infer from "the kernel row passed" is the host's rather than the tree's. The tree has six kernel harnesses; neither host runs more than four. - The
kernelrow needed an aarch64 host, and nothing enforced that.kernel/Cargo.tomldepends onaarch64-cpuunconditionally, andcrate::arch::mmu::Formatresolves by the host'starget_archunder Kani, socargo kani -p kernelon an x86_64 box would fail to build and would be proving a differentFormatif it did. It works today because every job in.github/workflows/verify.ymlruns onubuntu-24.04-arm, which is aarch64 Linux, and because the dev machine is Apple Silicon. Milestone 193's block predicted the opposite ("CI is x86_64 Linux and it very likely will not [compile]"); the check proved it false:script/lintfails a custom-sectionlink_sectionunderkernel/srcwithout thetarget_os = "none"gate. If that runner label ever changes, this row breaks, and the fix is puttingaarch64-cpubehind a targetcfg. - The macOS host compile lacks confirmation since the gate landed (2026-10-29 UTC). The custom section names are ELF, and rustc validates them against the object format, so a Mach-O host refuses an ungated one. No CI runner compiles the kernel on Mach-O, so nothing exercises the fix; a script/verify on a macOS machine on this head owes it.
- This note does not price the rest of the work. What was measured is that the front door opens.