eBPF-based security platform
Documentation: list the source files no proof reads
Daniel Borkmanncba5413e8f42
diff --git a/.agents/skills/docs/SKILL.md b/.agents/skills/docs/SKILL.mdindex 93f3a5c8..d5c1c650 100644--- a/.agents/skills/docs/SKILL.md+++ b/.agents/skills/docs/SKILL.md@@ -64,6 +64,7 @@ make docs # renders and serves on 127.0.0.1:8000`check-docs.sh` checks the options of console examples, the failurecategories, tamper counters, hooks, tests, proofs and units the pagesname, the whole of each field of a threat's fact box with a hook by its-section name, and that every proof has a row on the proof coverage-page. It cannot check the prose: read each changed paragraph against-the code.+section name, and that every proof has a row on the proof coverage page+and every source file a proof that reads it or a line among the files+without one. It cannot check the prose: read each changed paragraph+against the code.diff --git a/.agents/skills/proofs/SKILL.md b/.agents/skills/proofs/SKILL.mdindex 20dccd9e..5ca969e5 100644--- a/.agents/skills/proofs/SKILL.md+++ b/.agents/skills/proofs/SKILL.md@@ -11,7 +11,10 @@ and what no proof covers yet. A change to code a proof covers adapts theharness or the Lean 4 model in the same commit, where the change movedwhat it states, and runs that proof (`git grep -n '<file>.c\|<function>'testing/proofs/cbmc` finds the harnesses that reach the code); a change to-a proof or to what it covers updates the coverage page too.+a proof or to what it covers updates the coverage page too. A source+file that is new gets a harness or a line under "Files without a proof"+there, and one a harness starts to read leaves that list:+`check-docs.sh` fails on a file that is neither or both.## Rundiff --git a/.agents/skills/security-audit/SKILL.md b/.agents/skills/security-audit/SKILL.mdindex 3bcd344f..500fef8a 100644--- a/.agents/skills/security-audit/SKILL.md+++ b/.agents/skills/security-audit/SKILL.md@@ -320,13 +320,17 @@ beside the model step for step, with every constant, the order, eachbranch and each error path, and every commit to the C since the modellast changed.-Then the gaps. Every parser of outside input, every emitter whose-output is hashed, signed or measured, and every protocol with crash-states has a proof, or stands under "Not covered yet" with what covers-it in its place. A function of a proven file that no harness reaches-and the page does not name is a gap too, and so is the code that joins-proven parts. Where neither a proof nor a fuzz target reaches, hunt-first.+Then the gaps. The coverage page lists the files no harness reads+under "Files without a proof", each with the reason, which+`check-docs.sh` keeps complete, and under "Not covered yet" what the+proofs of the other files leave out. Every parser of outside input,+every emitter whose output is hashed, signed or measured, and every+protocol with crash states has a proof or stands in one of the two.+Read each reason against the file: "calls the kernel" stops being one+for logic that can move out from between the calls. A function of a+proven file that no harness reaches and the page does not name is a+gap too, and so is the code that joins proven parts. Where neither a+proof nor a fuzz target reaches, hunt first.A proof out of sync with the code is a security bug, whichever of thetwo is right: a fact box or a coverage row then claims an assurance thediff --git a/.github/scripts/check-docs.sh b/.github/scripts/check-docs.shindex 7691ab45..99b17afb 100755--- a/.github/scripts/check-docs.sh+++ b/.github/scripts/check-docs.sh@@ -5,8 +5,9 @@# .github/scripts/check-docs.sh -- check Documentation/ against the tree:# every option a console example passes to shirudo exists in a parser,# every failure category the code emits, every tamper counter and every-# proof has its entry in the reference, and every hook, counter, test,-# proof and unit a page names exists.+# proof has its entry in the reference, every hook, counter, test, proof+# and unit a page names exists, and every source file is read by a proof+# or listed as read by none.## .github/scripts/check-docs.sh#@@ -129,6 +130,42 @@ while IFS= read -r page; dodonedone <"$work/pages"+# The tree files a harness includes, through another harness too.+harness_reads() {+ grep -oE '^#include "[^"]+"' "$1" | sed -E 's/^#include "(.*)"$/\1/' |+ while IFS= read -r inc; do+ case $inc in+ ../../../*) printf '%s\n' "${inc#../../../}" ;;+ proof.h) ;;+ *)+ [ ! -e "testing/proofs/cbmc/$inc" ] ||+ harness_reads "testing/proofs/cbmc/$inc"+ ;;+ esac+ done+}++# Every source file is read by a harness or listed on the coverage page+# as read by none, and no file is both.+for harness in testing/proofs/cbmc/*.c; do+ harness_reads "$harness"+done | sort -u >"$work/read"+sed -n '/^Files without a proof$/,/^Not covered yet$/p' "$coverage" |+ grep -oE ':src:`[^`]+\.c`' | sed -E 's/:src:`(.*)`/\1/' |+ sort -u >"$work/unread"+git ls-files 'util/*.c' 'builtin-*.c' shirudo.c 'tools/shirudo-build/*.c' |+ sort >"$work/sources"+while IFS= read -r source; do+ grep -qxF "$source" "$work/read" || grep -qxF "$source" "$work/unread" ||+ report "$coverage" "no proof reads $source and no line says why"+done <"$work/sources"+while IFS= read -r source; do+ grep -qxF "$source" "$work/sources" ||+ report "$coverage" "no source file is named $source"+ ! grep -qxF "$source" "$work/read" ||+ report "$coverage" "a proof reads $source, which the page lists as read by none"+done <"$work/unread"+# Every unit a page names exists under systemd/.while IFS= read -r page; dogrep -oE 'shirudo(-[a-z0-9]+)*\.(service|timer)' "$page" | sort -u |diff --git a/Documentation/contribute/testing/proof-coverage.rst b/Documentation/contribute/testing/proof-coverage.rstindex 200b4a5a..1740846e 100644--- a/Documentation/contribute/testing/proof-coverage.rst+++ b/Documentation/contribute/testing/proof-coverage.rst@@ -10,8 +10,8 @@ Proof coverageThis page lists the CBMC proofs under :src:`testing/proofs/cbmc/` and theLean 4 proofs under :src:`testing/proofs/lean4/`, what each one proves and-for which inputs, and the parsers no proof covers yet. :doc:`proofs`-explains how to run and write them.+for which inputs, the source files no proof reads and the parsers no+proof covers yet. :doc:`proofs` explains how to run and write them.CBMC proofs-----------@@ -735,6 +735,84 @@ the model follows the C.sync writes, ``bpm-tree-recovery-model`` for pending recovery;``tree_parse()`` by review+Files without a proof+---------------------++A harness reads a source file by including it. Every file of+:src:`util/` and :src:`tools/shirudo-build/` that the repository tracks,+every ``builtin-*.c`` and :src:`shirudo.c` is read by a harness or+listed here with the reason,+and ``.github/scripts/check-docs.sh`` fails when a file is neither or+when a harness reads a file this list still names. A file a harness+reads is not proven whole: the tables above say which of its functions+a proof covers.++.. list-table::+ :header-rows: 1+ :widths: 46 54++ * - Files+ - Why no proof reads them+ * - :src:`util/bpm_state.c`, :src:`util/bpm_tree_overlap.c`,+ :src:`util/bpm_tree_state.c`, :src:`util/conditions.c`,+ :src:`util/config_attest.c`, :src:`util/paths.c`,+ :src:`util/serializer.c`, :src:`util/similar.c`+ - No proof is written yet. A harness could carry their logic, in+ whole or in part: the package state and tree state readers, which+ selectors of a tree can meet on one node, the status verdict, the+ config history of an evidence document, the pin and key paths,+ ``serial_chunk_validate()`` and the edit distance+ * - :src:`tools/shirudo-build/bpm-build.c`,+ :src:`tools/shirudo-build/bpm-publish.c`,+ :src:`tools/shirudo-build/package.c`,+ :src:`tools/shirudo-build/vouch.c`+ - No proof is written yet. The operator's Beefile reader and its+ writers of the loader, the ``.upatch`` container, the package,+ the index, the tree publication and the vouch: the proofs cover+ what the target's readers accept, not what these write+ * - :src:`util/harden.c`, :src:`util/identity.c`,+ :src:`util/image_cache.c`, :src:`util/image_config.c`,+ :src:`util/image_guards.c`, :src:`util/image_keys.c`,+ :src:`util/image_runtime.c`, :src:`util/initrd.c`,+ :src:`util/keyring.c`, :src:`util/preflight.c`,+ :src:`util/seal.c`, :src:`util/sysinfo.c`, :src:`util/tamper.c`,+ :src:`util/upatch_maps.c`, :src:`util/upatch_pins.c`,+ :src:`util/upatch_resolve.c`, :src:`util/upatch_verify.c`,+ :src:`util/xdp.c`+ - Mostly calls into the kernel, which CBMC has no body for: files,+ extended attributes, mounts, the device mapper, keyrings,+ ``bpf()``, netlink, ``/proc`` and the process's own limits+ * - :src:`util/crypto_openssl.c`, :src:`util/curl.c`,+ :src:`util/elf_target.c`, :src:`util/kernel_abi.c`,+ :src:`util/keys.c`, :src:`util/nv_writer.c`, :src:`util/sign.c`,+ :src:`util/tls_openssl.c`, :src:`util/tpm.c`,+ :src:`util/upatch_decode.c`+ - Mostly calls into a library a harness would have to model whole:+ OpenSSL, libcurl, libelf, the BTF reader of libbpf, tpm2-tss and+ LuaJIT+ * - :src:`util/format.c`, :src:`util/help.c`, :src:`util/report.c`,+ :src:`util/timefmt.c`, :src:`util/upatch_table.c`+ - Output for people: sizes, durations, help, the load report and+ the table of loaded upatches. ``proof.h`` models neither floating+ point conversions nor ``strftime()``, and the JSON they emit goes+ through the emitters the proofs cover+ * - :src:`util/loader.c`+ - Data only: the embedded BPF objects+ * - :src:`builtin-attest.c`, :src:`builtin-build.c`,+ :src:`builtin-config.c`, :src:`builtin-genkey.c`,+ :src:`builtin-image.c`, :src:`builtin-init.c`,+ :src:`builtin-keys.c`, :src:`builtin-status.c`,+ :src:`builtin-upatch.c`, :src:`builtin-version.c`,+ :src:`shirudo.c`, :src:`tools/shirudo-build/compile.c`,+ :src:`tools/shirudo-build/image.c`,+ :src:`tools/shirudo-build/shirudo-build.c`,+ :src:`tools/shirudo-build/vmlinux.c`+ - Commands: options, the order of calls into :src:`util/` and+ output. ``Shirudo.UpatchLoad`` models the protocols of ``init``,+ ``upatch load`` and ``upatch unload``, by review, and the tree+ sync harnesses read ``builtin-bpm.c``; no proof reads the other+ commands+Not covered yet---------------diff --git a/Documentation/contribute/testing/proofs.rst b/Documentation/contribute/testing/proofs.rstindex a114f905..216fa24a 100644--- a/Documentation/contribute/testing/proofs.rst+++ b/Documentation/contribute/testing/proofs.rst@@ -128,7 +128,8 @@ Write a CBMC proofa loop that reads one byte too many, run it and see it fail, thenrestore the code.-5. Add a row to :doc:`proof-coverage`.+5. Add a row to :doc:`proof-coverage`, and take a file the harness is+ the first to read off that page's list of files without a proof.A function without a body in the proof, a libc one CBMC does not model ora system call, returns any value, and ``run.sh`` fails a proof that callsdiff --git a/Documentation/contribute/testing/test-coverage.rst b/Documentation/contribute/testing/test-coverage.rstindex da5c384b..062b7c9d 100644--- a/Documentation/contribute/testing/test-coverage.rst+++ b/Documentation/contribute/testing/test-coverage.rst@@ -63,7 +63,8 @@ signed config image.binaries when built* - ``t0008-check-docs``- ``check-docs.sh``: the whole of each field of a threat's fact- box, a hook by its section, and the tree itself+ box, a hook by its section, the source files a proof reads or the+ proof coverage page lists as read by none, and the tree itself``build`` (1)~~~~~~~~~~~~~diff --git a/testing/ci-checks/t0008-check-docs.sh b/testing/ci-checks/t0008-check-docs.shindex 0cb0b29a..c097c125 100755--- a/testing/ci-checks/t0008-check-docs.sh+++ b/testing/ci-checks/t0008-check-docs.sh@@ -3,8 +3,9 @@# Copyright (c) 2026 Authors of shirudo## t0008 -- .github/scripts/check-docs.sh: the whole of each field of a-# threat's fact box and a hook by its section, on a throwaway repository,-# and the tree itself.+# threat's fact box, a hook by its section, and the source files a proof+# reads or the coverage page lists as read by none, on a throwaway+# repository, and the tree itself.cd "$(dirname "$0")/..". ./test-lib.sh@@ -26,7 +27,7 @@ put() {}# A tree the check passes: one fact box whose fields continue on a second-# line.+# line, two harnesses, one of which reads its file through a header.good() {rm -rf "$R" && mkdir -p "$R" && git init -q "$R" &&put shirudo.c 'int main(void) { return 0; }' &&@@ -36,12 +37,17 @@ good() {put tools/gen-initrd/gen '#!/bin/sh' &&put util/tamper.c 'static const struct point points[] = {' \' [0] = { "Good", 1 },' '};' &&+ put util/read.c 'int read_one;' &&+ put util/chained.c 'int chained;' &&+ put util/unread.c 'int unread;' &&put bpf/guard.c 'SEC("lsm/file_open")' 'SEC("lsm.s/inode_setattr")' &&put bpf/lib/guard.h 'struct guard;' &&put testing/functional/build/t1001-one.sh '#!/bin/sh' &&put testing/proofs/cbmc/proofs.list 'first --unwind 1' 'second --unwind 1' &&- put testing/proofs/cbmc/first.c '#include "proof.h"' &&- put testing/proofs/cbmc/second.c '#include "proof.h"' &&+ put testing/proofs/cbmc/first.c '#include "proof.h"' \+ '#include "../../../util/read.c"' &&+ put testing/proofs/cbmc/model.h '#include "../../../util/chained.c"' &&+ put testing/proofs/cbmc/second.c '#include "proof.h"' '#include "model.h"' &&put testing/proofs/lean4/Shirudo/Model.lean 'theorem model : True := trivial' &&put Documentation/security/tamper-counters.rst '``Good``' &&put "$TM" ':Enforced at: ``lsm/file_open``,' \@@ -52,7 +58,12 @@ good() {':Proofs: ``first``,' \' ``second``' &&put "$COV" ' * - ``first``' ' * - ``second``' \- ' * - ``Shirudo.Model``'+ ' * - ``Shirudo.Model``' '' \+ 'Files without a proof' '---------------------' '' \+ ' * - :src:`shirudo.c`, :src:`builtin-upatch.c`,' \+ ' :src:`tools/shirudo-build/build.c`,' \+ ' :src:`util/tamper.c`, :src:`util/unread.c`' '' \+ 'Not covered yet' '---------------'}check() {@@ -82,6 +93,21 @@ test_expect_success 'a counter and a proof on a continuation line are checked' 'refuses "no proof is named secondx"'+test_expect_success 'a source file is read by a proof or listed as read by none' '+ good && put util/new.c "int new_file;" &&+ refuses "no proof reads util/new.c and no line says why" &&+ good && put testing/proofs/cbmc/second.c "#include \"proof.h\"" &&+ refuses "no proof reads util/chained.c and no line says why"+'++test_expect_success 'the list names only source files no proof reads' '+ good && sed -i "s|:src:\`util/unread.c\`|:src:\`util/unread.c\`, :src:\`util/read.c\`|" "$R/$COV" &&+ refuses "a proof reads util/read.c, which the page lists as read by none" &&+ good && sed -i "s|:src:\`util/unread.c\`|:src:\`util/gone.c\`|" "$R/$COV" &&+ refuses "no source file is named util/gone.c" &&+ grep -qF "no proof reads util/unread.c and no line says why" "$W/err"+'+test_expect_success 'the tree itself passes' '(cd "$ROOT" && sh "$S") >"$W/out" 2>"$W/err"'