notes

Machine-checked proofs (Kani)

The companion to the verification thesis (DECISIONS §14 (the project's direction)). That decision says why we verify; this note is how, and the record of the experiment that green-lit it. The harness tables, the bounds and each crate's story are in verification/, one appendix per topic.

Tests sample; proofs quantify

The capability tests check the cases we thought to write: READ cannot become WRITE, an empty slot is NoSuchSlot, a derived cap names the same object. Good tests, but they say nothing about the inputs we did not enumerate. A proof harness asks a different question. kani::any() is an unconstrained value, so:

#[kani::proof]
fn derive_never_widens_rights() {
    let src_rights = Rights(kani::any());   // ALL 2^32 patterns at once
    let requested  = Rights(kani::any());
    let mut cs: CapabilityTable<u8> = CapabilityTable::new(2);
    cs.put(0, Cap { object: 0u8, rights: src_rights }).unwrap();
    if cs.derive(0, 1, requested).is_ok() {
        assert!(cs.get(1).unwrap().rights.is_subset_of(src_rights));
        assert!(requested.is_subset_of(src_rights));
    }
}

proves "no reachable state widens rights," not "the states we tried did not." Kani compiles the function to a logical formula and hands it to a SAT solver; SUCCESS means there is no assignment of the symbolic inputs that trips an assertion or panics.

How it actually works

The surprising part is that Kani checks "every input" without running every input. It does not loop over 2^64 values. It reasons about them symbolically.

  1. Symbolic input. kani::any() is not a random value. It is a placeholder standing for all values at once, an unknown the tool carries as algebra.
  2. The program becomes a formula. Kani traces the harness over that unknown, turning each operation and branch into a logical constraint. In index, the (va >> shift) & 0x1ff becomes an expression in the bits of va, not a number, and the assert! becomes a claim about that expression.
  3. A solver hunts for a counterexample. The claim, negated, goes to a SAT/SMT solver whose one job is to answer "is there any assignment of these bits that makes this false?"
    • UNSATISFIABLE = no such assignment exists = the property holds for every input. The proof.
    • SATISFIABLE = here is an exact input that breaks it. A counterexample, printed for you.

That is why page_tables verified in ~12 milliseconds: it is not 2^64 executions, it is one algebra problem about the bits.

What "bounded" means, and the one honest limit

A solver reasons completely about fixed-size things: a 64-bit integer, a four-level walk, a two-slot table. What it cannot swallow whole is an unbounded loop or an arbitrarily large structure, which would build an infinite formula. So Kani bounds: it unrolls loops to a limit and gives structures concrete sizes.

The page_tables and capability harnesses have no unbounded loops (the four levels are literally four), so their proofs are complete, not "up to a bound." But consider a harness that reasons over map_range for a symbolic count, or the Mapper building tables. You either bound it (prove it for count <= N) or reach for a heavier technique (induction, a tool like Verus). "Bounded model checking is automatic but only reasons up to the bound" is the whole trade.

What a green check does and does not mean

A proof is only as good as four things, and each is worth being blunt about:

  1. It proves what you asserted, not what you meant. A wrong assertion verifies happily and means nothing. The harness is the specification, so it must be read as carefully as the code it checks. This is the main failure mode, not solver bugs.

  2. It covers only what the model captures. Kani models Rust's semantics. It does not model the hardware, and unsafe that breaks Rust's assumptions is outside it. That is exactly why we verify the pure-logic crates (capability, page_tables's arithmetic) and not the arch/ assembly: the model is faithful where there is no hardware and no unsafe. It is also why §14 promises a small verified TCB with an unverified layer beneath it, not a proof of the whole machine.

    Concurrency is the sharpest edge of this limit. Every queue and endpoint proof here is single-threaded. The wake-before-switch-out race (notes/intrusive-queues.md) lived precisely in the SMP interleaving those proofs cannot see. Green harnesses and a real race coexisted; the flaky test found it.

    And there is a fourth edge of the same limit that is not about the model at all: the prover compiles for the host, so it sees one architecture (milestone 304 (cargo kani -p kernel only ever compiled one architecture)). kernel/src/arch/mod.rs selects its subtree with #[cfg(target_arch = ...)]. So a Kani run on an aarch64 box compiles arch/aarch64/ and no line of the other two. This is worse than the asm! boundary above rather than milder, because it is silent. An unsupported construct is reported, but a cfg-excluded file produces no diagnostic of any kind, and the suite goes green faster. The kernel row is proved on aarch64, x86_64 and riscv64 for exactly this reason, riscv64 by a patched Kani (milestone 589 (Kani can prove riscv64 from the hosts we already have)). See notes/kernel-proofs.md for what each run reaches.

  3. The harness itself is code, and until milestone 113 (the proofs' own unsafe code) it was code no gate read. cfg(kani) is set by the model checker and by nothing else. So script/lint never compiled a single #[cfg(kani)] mod verification, and clippy::undocumented_unsafe_blocks could not fire in one. The harnesses that set up the queue and endpoint proofs are unsafe, and thirteen of those sites had no SAFETY comment: an unexamined assumption inside the thing that exists to examine assumptions. script/lint now compiles them all against a shim (helpers/kani-lint-shim/), which is a lint pass and not a second proof. See notes/unsafe-obligations.md.

  4. The tool is trusted. Kani, its CBMC backend, and the SAT solver could have bugs. They are small and widely used, and the solver emits a checkable certificate, but it is a trust assumption. seL4 minimizes even its proof checker; we do not, and that is a stated limit.

What is proved today

One row per crate this note covers, with its central property. Each appendix has the full harness table and the reasoning.

Crate Harnesses What it proves Appendix
capability 8 derivation and the inheriting mint never widen rights; a deleted capability stays deleted, and deleting touches only its slot core
memory_regions 2 untyped carving stays within budget; a child region never frees to the allocator (no double-free) core
page_tables (walk) 8 table indices in bounds; distinct pages take distinct paths; the halves are disjoint; descriptors keep address and permissions apart core
page_tables (blocks) 8 a 2 MiB or 1 GiB leaf is aligned, inside the span and the largest that fits; block encodings on three formats blocks (nifeos/nife:notes/verification/paging-blocks.md)
page_tables::domain 6 an IOMMU domain maps exactly the granted pages, in both directions IOMMU
page_frames 5 two allocations are distinct; frames are aligned and in range core
device_tree_blob 4 the big-endian leaf readers are total core
inter_process_communication 6 at most one wait queue is non-empty; rendezvous is exact; a collected sender is forgotten core
generational_table 3 a removed name never resolves again core
intrusive_queue 1 any push/pop interleaving is FIFO and lossless core
address_space_identifier 3 ASID 0 is never allocated; live ASIDs are distinct core
static_elf 4 segment bounds arithmetic is total and yields in-bounds ranges parsers
nifefs 2 the initrd parse's acceptance makes reads in-bounds parsers
memory_region_heap 3 the heap's growth arithmetic stays inside its cap, refuses at the cap, and never overflows core
pci_configuration_space 10 config-space decode is total on any device's answers, and every BAR it returns is a power of two parsers
direct_memory_access_validator 7 no descriptor the device reads escapes the driver's grant DMA
byte_glob 6 the matcher is total on any pattern and name glob

Three things the table cannot say:

Every address that reaches a device through a virtqueue descriptor is provably confined to the driver's grant; addresses that reach a device inside a command payload are confined by the IOMMU alone, that confinement is tested rather than proved, and on a board without an IOMMU it does not exist.

verification/iommu-domain.md has why, and what it means for the VisionFive 2.

Where BMC's cost actually is

The cost of a proof is the shape of the code, not the size of the claim:

When BMC stalls, look at what the harness touches rather than at what it is trying to prove.

Running it

script/verify

It self-installs Kani on first run (its own nightly toolchain and a CBMC backend), then runs cargo kani over every package carrying harnesses. The harness count is generated weekly into notes/project-metrics.md; the harnesses sit across at least 30 packages . Not every host compiles all of them: two in kernel/src/arch/x86_64/interrupt_controller.rs run only on an x86_64 host.

Harnesses within a crate verify in parallel, -j 4 by default (VERIFY_JOBS overrides). In CI the suite runs as three prove shards behind one required check, verify (Kani proofs), which calef ruled on 2026-10-07 to keep the job near 16 minutes. The packer refuses to prove a subset while reporting itself as the suite. script/verify --affected-since <base> reports not-needed when a diff cannot reach a proof, so a kernel-only pull request skips them. verification/ci-timings.md has the measurements, the shard table and the trap a matrix would have set.

Not in script/bootstrap, because the kernel build does not need it; same self-install pattern as script/coverage. A new proof crate goes in that script's list, and a new harness in an existing crate is picked up with no change.

The rules that keep proofs cheap and honest