Runtime hardening & gaps
The six-layer defense model, the measured cost of user/kernel boundary hardening, the kernel self-protection mechanisms and the honest gaps register β every gap states its closure shape Β· Canonical: docs/architecture/security-design.md, security-posture.md, safety-and-performance.md Β§5
Β§1The six-layer defense model
| Layer | Mechanism | Measured cost | Status here |
|---|---|---|---|
| L1 language isolation | the type system + forbid(unsafe_code) layering | ~0 | present (the layered ledger) |
| L2 syscall boundary | uaccess + entry validation | ~55 ns per AC bracket | present (Β§2 here) |
| L3 privilege model | capabilities, seccomp | one atomic op per check | present (Β§3 here) |
| L4 hardware aids | SMAP/SUM (MPK/MTE as registered directions) | 20β26 cycles (MPK reference) | present (Β§2 here) |
| L5 TCB formal verification | Kani/SPIN/loom/Miri/proptest | offline | present (formal verification) |
| L6 runtime mitigation | an eBPF-class observation/mitigation channel | ~1% CPU (reference) | absent (the gaps register) |
The ordering principle: the type system first, hardware second, verification third, runtime mitigation last β the earlier a check happens, the less remains on the fast path.
Β§2The user/kernel boundary
- SMAP (x86_64, the D-18 evolution): CR4.SMAP enabled from the CPUID-detected bit (a G1-era EDX/EBX bit misread defect was fixed in 763e9f3c with a boot-log assertion against live CR4/CPUID plus a per-boot smap_report); the original pushfq/orq/popfq sequence (~100+ cycles per pair) evolved into SMAP-gated stac/clac β the CPUID SMAP bit implies STAC/CLAC exist, at 2-cycle flag writes; the fixup label also clears AC (a fault mid-copy lands there with AC still set); the documented figure is ~55 ns per bracket. The SMAP-VIOL beacon reads zero across the suite.
- SUM (riscv64): sstatus.SUM deliberately kept 0 β the kernel reaches user memory only via the uaccess exception paths; sret to U-mode with SUM=0 is the ABI; any SUM=1 boot print is a regression.
- Exception tables + fixups: riscv64 records (insn, fixup) in .ex_table; x86_64 uses restartable rep-movsb; every accessor runs access_ok(addr,n); a fault returns short/EFAULT and never panics (the LTP x86-r2 N1 evidence: 37 EFAULT-family tests pass through the fixups); ~150 call sites. Table integrity is script-guarded (scripts/verify_exception_table.py: every entry must point at a memory-access instruction and its fixup at executable code β guarding the label-placement bug class).
- No identity MMIO window (D-17): device addresses go through kernel-side alias windows and the bootstrap identity map is unlinked after boot β a bad user pointer faults instead of returning kernel bytes (the x86_64 suite 1194/1194 including the previously-red EFAULT row).
- Forensic beacons: PF-NOCTX (SMAP on, AC clear, a user-range no_context fault = a raw user-pointer dereference, named before the oops machinery mangles the context).
Β§3The user-space privilege surface
- User W^X: NX mappings, the PT_GNU_STACK semantics, the READ_IMPLIES_EXEC personality β all three were once missing or ignored, fixed to Linux's semantics (1de56837).
- seccomp: a classic-BPF subset interpreter (LD|W|ABS/IMM, JMP|JEQ/JGT/JGE/JSET|K, RET|K; a 4096-instruction cap; out-of-bounds loads and fall-off-end kill), gated from BOTH trap paths before dispatch; STRICT and FILTER modes; kill actions queue SIGKILL; fork inheritance. PR_SET_NO_NEW_PRIVS is one-way, sticky across fork+exec, and gates unprivileged seccomp attach (LTP prctl02 PASS). The registered accepted divergence: a single filter, no TSYNC/TRACE/NOTIF.
- The capability model: 41 CAP_* UAPI constants (CAP_VALID_MASK = 2^41β1); after audit, 23 consulted points + six previously-never-checked capabilities wired by 4e75d849 (NET_RAW/NET_ADMIN/SYS_PACCT/SETFCAP/DAC_READ_SEARCH/PERFMON); ~18 enforcement gate sites (Linux ~120 β the breadth gap is in the gaps register).
- Secure-exec environment scrubbing (D-9): on AT_SECURE transitions the kernel removes every LD_* variable from the envp it installs β defense in depth independent of libc behavior (static binaries with custom loaders are covered too); the registered cost: a secure-exec'd process's /proc/[pid]/environ does not list LD_*.
- OOM scoring semantics: the oom_badness shape (a resident-pages baseline + oom_score_adj), pinned by 10 property tests (immunity, saturation avoidance, symmetry).
Β§4Kernel self-protection
- Kernel-stack guards: a bottom canary (0xCAFE_F00D_DEAD_BEEF, written volatile) verified before the stack returns to the cache (R18-2 β a smashed value is direct evidence the task ran past its stack into the adjacent heap page, printed as STACK-OVERFLOW) + the FREED_STACKS 32-entry ring (names the freer when a faulting rsp sits in a freed stack) + dfx-gated 0xC3 free-painting; the packed kernel-stack slab (D-2) ran 3,445 live tasks with zero canary hits. Compiler stack protection is a registered gap (Β§5).
- Deferred-free quarantine: MmStruct/Task enter a 16,384-entry wall-clock ring (a 1,500 ms drain) β the use-after-free window for unaccounted procfs borrowers is structurally closed.
- Failure discipline: oops/panic in Linux's report shape (CSRs + all GPRs + a 32-frame backtrace + symbolization), the panic_on_oops sysctl, the panic= reboot parameter, the pstore console.
- The observable safety net: the unified tracepoints (69 events/17 groups), the census/heal self-repair (MISS=0, measured and recorded), the spinlock watchdog, kallsyms-symbolized backtraces β defect localization time is itself a security property.
Β§5The honest gaps register
Partial
| Item | Current state | Closure shape |
|---|---|---|
| lockdep-class debugging | keyed nestings are compile facts (D-11) + the preempt-count census MISS=0; a runtime held-lock graph over the whole tree is absent | extend keying to the remaining nestings; a debug-build held-lock bitmap is the drop-in shape |
| refcount hardening | page/frame refcounts are plain atomics β 2 of the taxonomy's 10 safe-class defects are exactly this class | a typed Refcount with decrement-must-hit-zero-to-free as the only free path |
| arithmetic overflow checks | off in the release profile (on in dev) | one config line + the measured boot/perf cost through the merge gate |
| KASAN-style poisoning | task-page paint + header audits + the buddy-metadata shadow (dfx-gated); no redzones on small_alloc | build-flag redzones and poison-on-free in small_alloc/slab |
| the LSM surface | hooks exist; selinuxfs is a label-carrying compat mount, permissive by construction | policy parsing + AVC decisions |
| namespaces | PID/IPC real (1bde7490); net/user/mount are stubs | implement per Linux semantics one by one |
| capability enforcement breadth | 41 constants, ~18 gate sites (Linux ~120) | wire per the consulted-surface list |
Absent
| Item | Current state | Closure shape |
|---|---|---|
| KASLR | the offset field and plumbing exist; no boot entropy wired | RDRAND/seed at entry + a boot print of a varying offset |
| kernel text/rodata W^X | the image is mapped RWX (riscv64) / RW without NX (x86_64); no mark_rodata_ro pass | a post-init RO flip + a dfx page-table-walk tripwire |
| compiler stack protection | none (the stack canary is kernel-side, not compiler-generated) | the rustc stack-protector attribute + a build flag, the cost measured through the gate |
| hardened usercopy | access_ok bounds checks only | a per-object usercopy-region check at the uaccess capsules |
| module signing | no runtime code loading today (a registration surface only), so the topic is dormant | signature verification ships with the real loader |
| a KCSAN-class checker | absent; the residual safe races are protocol-level | a watchpoint checker is a project; the loom/Kani mirrors cover the primitive subset |
| kptr_restrict / kallsyms masking | /proc/kallsyms shows real addresses to every reader | a masking knob + masked default |
| an eBPF-class runtime mitigation channel | absent | project per Linux semantics |
Posture summary (the security-posture.md 21-row basis): 7 rows present, 3 quick, 10 project-grade, 1 accepted.
Β§6Verification-hardening worked instances
- The Ubuntu 24.04 freeze exoneration: a per-event forensic chain proved the one pre-freeze WAKE(val=1, ret=1) was delivered and that no kernel code writes user futex words on the WAIT/WAKE paths β the kernel excluded at the word level and the user side assigned responsibility. A security argument gains credibility from records where the kernel is also exonerated.
- The SMAP-enablement bisection arc: STAC/CLAC take an unconditional #UD under TCG (bisected) β the pushfq bracket (~100+ cycles) β SMAP-gated stac/clac (2 cycles) β the cost curve of a security mechanism was measurement-driven, not a one-time trade.
- The D-19 typed timer wheel: six historical defect classes (mixed clock-domain comparisons, periodic misuse, double cancels, stale ids) became compile errors while the same-test platform A/B showed performance gains (arm-lock 924β697 ns) β an instance of hardening and performance pointing the same way.
Canonical: docs/architecture/security-design.md (the six-layer model + the metrics table), docs/development/security-posture.md (the 21-row posture), docs/architecture/safety-and-performance.md Β§5 (the gaps register), docs/architecture/design-divergences.md (D-9/D-17/D-18). Related: formal verification, defect taxonomy, the layered unsafe ledger.