Skip to Content
Viewing feat/v0.5-runtime docs — not the stable branch. Changes vs main · Go to main

Unsafe-Code Audit

Relevant source files

Every first-party Rust unsafe syntax site is an owned review obligation. ledger.toml is the maintained catalog (path rules, owners, invariants); ledger.md is generated from it plus the current source by python3 scripts/verify/unsafe-ledger.py --write. Review and CI run cargo xtask check unsafe; --list prints a per-site TSV (location, construct, owner, invariant, callers, tests, priority, review date).

Snapshot

The branch refreshes the ledger for the managed runtime (662cd4f, “refresh unsafe inventory hash”, and earlier inventory updates). Net change: 42 more sites in 4 more files, mainly managed map updates, the IRQ-masked allocator, firmware MMIO adapters (FIRMWARE-MMIO grows from 1 to 12) and managed execution.

736 sites in 125 files on this branch (694 in 121 on main): 153 attributes, 465 blocks, 25 externs, 69 functions, 23 impls, 1 trait. Counts are syntactic source sites (including tests and fuzz targets, excluding build output and corpora), not expanded macro instances and not a proof of soundness. The inventory is fingerprinted (sha256:be108a3a...) so drift is detected.

Obligations

ObligationSitesPriorityInvariant (abridged)Missing evidence called out
AARCH64-EXCEPTION-CONTEXT89P0Assembly context layouts match repr(C); vectors preserve registersNested exception and SMP interrupt stress
TEST-HARNESS88P3Synthetic pointers confined to test/fuzz binaries(harness is the evidence)
SCHEDULER-TASK61P0One mutable owner of task/CPU state; context pointers pinnedLoom/model tests, forced preemption at mutation points
AARCH64-PLATFORM-MMIO58P1MMIO matches DT/platform map; volatile, width-correct accessRegister-level mocks, concurrent ownership tests
BPF-EXECUTION-JIT49P0Only VerifiedProgram or the private ManagedProgram wrapper reaches execution; managed map-helper extents and local binding leases cover each call; W^X for generated codeJIT differential tests, enforced RW-to-RX lifecycle
USERSPACE-ABI45P1Syscall asm obeys kernel ABI; ring buffers aligned and boundedMiri for parsers, malformed ring/event inputs
KERNEL-BOOT-RUNTIME40P1Bootloader pointers, linker symbols, allocator setup validMalformed boot metadata, backtrace-chain tests
AARCH64-PAGING38P0Aligned, uniquely owned tables; TLB maintenance orderedMap/unmap fault injection, multicore shootdown tests
MEM-ADDRESS-SPACE35P0Page tables live under the address-space lock; user copies validate every pageConcurrency fault injection
BPF-HELPERS30P0Verified helper args still refer to live regions at run timeAdversarial helper provenance, concurrent map lifetime
SYSCALL-PRIMITIVES29P0UserspacePtr proves only numeric range; deref needs UserMemoryTargeted Miri
X86-INTERRUPT-CONTEXT25P0Naked frames match Rust layouts; valid stacks/selectorsNested interrupt, malformed-frame tests
DMA-MMIO-DRIVERS25P1MMIO/DMA mapped for device lifetime; transport serializedIOMMU/DMA fault injection, hot-unplug
MEM-PHYSICAL14P0Frame allocator initialized once, never hands out aliased framesSMP allocator stress, reserved-range fault injection
SCHEDULER-RUN-QUEUE14P1Intrusive links preserve task uniquenessSMP-4 wakeup/IPI integration
FILESYSTEM-INTERIOR13P1Interior raw references do not outlive nodesConcurrent close/read/unmount
BPF-KERNEL-INTEGRATION11P0Registry preserves program, credential, quota, lifetime invariants; managed worker transitions hold no slot/manager locks and retirement tokens retain charges until refundModel-checked reclamation
MEM-KERNEL-RAW7P1Raw allocation uses live mapped memory with exact layoutMiri for host-capable primitives
SYSCALL-BOUNDARY9P0Register values untrusted; memory only via bounded adapterFull syscall fault matrix
BPF-MAPS26P0Map pointers aligned, in-bounds, live; raw updates allow aliased value-region inputs with overlap-safe copies under exclusive leases; Send/Sync premises holdMiri/Loom, unload-during-execution tests
MEM-VIRTUAL3P0Released segments not double-released or overlappingTransactional map/unmap integration tests
GLOBAL-ALLOCATOR-IRQ7P0New: every LockedHeap operation masks local IRQs before taking the heap lock and restores the entry state(new obligation for 4e4f20c)
BPF-MANAGED-ALLOCATION-TEST4P1New, test-only: linked-list heap fixture used to check Box/Arc charges for managed objects(fixture is the evidence)
RISCV-ARCH2P1Trap/context asm matches layouts (experimental demo)Boot/trap integration
SCHEDULER-WAIT-TRANSITION1P0Generation-stamped wait registration, IRQs masked across transition(model + SMP smoke present)
ACTUATION-MMIO1P1RP1 GPIO window mapped for kernel lifetime, singleton ownershipConcurrent ownership, MMIO fault injection
FIRMWARE-MMIO12P1RP2040 peripheral singletons accessed exclusivelyHardware concurrency, timer wraparound

Review policy

  • P0 gates release until the premises are enforced in code and exercised through a fault or concurrency path. P1 needs targeted tests before the subsystem is complete. P2 is platform/ABI glue with documented external premises. P3 is test/tooling only.
  • The path rule is the durable owner; a new path containing unsafe fails --check until classified, and any count drift fails --check.
  • “Boot smoke” is integration evidence, not a substitute for provenance, aliasing, lifetime, mapping, interrupt, DMA or MMIO tests. Rows that say coverage is missing remain open audit debt.
  • Contributor rule: every unsafe block needs a SAFETY: comment.

The BPF-EXECUTION-JIT obligation still exists because JIT code remains in the tree (kernel_bpf/src/execution/jit_aarch64.rs, execution/jit), even though no shipped profile enables it. ADR-0004 calls for removing or relocating it precisely because dead unsafe code adds audit surface.

Last updated on