eBPF-based security platform
ci: check every line of a threat's fact box against the tree
Daniel Borkmanna05eceb4f8e1
diff --git a/.agents/skills/docs/SKILL.md b/.agents/skills/docs/SKILL.mdindex eb6e2ecc..93f3a5c8 100644--- a/.agents/skills/docs/SKILL.md+++ b/.agents/skills/docs/SKILL.md@@ -63,5 +63,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 pages-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.+name, 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.diff --git a/.github/scripts/check-docs.sh b/.github/scripts/check-docs.shindex a11b0808..7691ab45 100755--- a/.github/scripts/check-docs.sh+++ b/.github/scripts/check-docs.sh@@ -71,17 +71,26 @@ while IFS= read -r counter; doreport "$counters" "no entry for the counter $counter"done <"$work/counters"-# The hooks, counters and tests a threat fact box names exist.+# A field of a fact box, with the lines that continue it, as one line.+field() {+ awk -v name=":$1:" '+ index($0, name) == 1 { on = 1; printf "%s", $0; next }+ on && /^[ \t]+[^ \t]/ { printf " %s", $0; next }+ on { print ""; on = 0 }+ END { if (on) print "" }' "$2"+}++# The hooks and counters a threat fact box names exist. A hook is named+# by its section, which says whether the program is sleepable.grep -ohE 'SEC\("lsm(\.s)?/[a-z_]+"\)' bpf/*.c bpf/lib/*.h |- sed -E 's/SEC\("lsm(\.s)?\/([a-z_]+)"\)/\2/' | sort -u >"$work/hooks"+ sed -E 's/SEC\("(.*)"\)/\1/' | sort -u >"$work/hooks"while IFS= read -r page; do- grep -E '^:(Enforced at|Counters|Tests):' "$page" >"$work/facts" || continue- grep '^:Enforced at:' "$work/facts" | grep -oE '``(lsm/)?[a-z_]+``' |- tr -d '`' | sed 's|^lsm/||' | sort -u | while IFS= read -r hook; do- grep -qx "$hook" "$work/hooks" ||- report "$page" "no BPF program attaches to $hook"+ field 'Enforced at' "$page" | grep -oE '``lsm(\.s)?/[a-z_]+``' |+ tr -d '`' | sort -u | while IFS= read -r hook; do+ grep -qxF "$hook" "$work/hooks" ||+ report "$page" "no BPF program has the section $hook"done- grep '^:Counters:' "$work/facts" | grep -oE '``[A-Za-z]+``' |+ field Counters "$page" | grep -oE '``[A-Za-z]+``' |tr -d '`' | sort -u | while IFS= read -r counter; dogrep -qx "$counter" "$work/counters" ||report "$page" "no tamper counter is named $counter"@@ -113,7 +122,7 @@ while IFS= read -r proof; doreport "$coverage" "no row for the proof $proof"done <"$work/proofs"while IFS= read -r page; do- grep '^:Proofs:' "$page" | grep -oE '``[A-Za-z0-9.-]+``' | tr -d '`' |+ field Proofs "$page" | grep -oE '``[A-Za-z0-9.-]+``' | tr -d '`' |sort -u | while IFS= read -r proof; dogrep -qx "$proof" "$work/proofs" ||report "$page" "no proof is named $proof"diff --git a/Documentation/contribute/testing/test-coverage.rst b/Documentation/contribute/testing/test-coverage.rstindex 509d145b..da5c384b 100644--- a/Documentation/contribute/testing/test-coverage.rst+++ b/Documentation/contribute/testing/test-coverage.rst@@ -61,6 +61,9 @@ signed config image.may link and its own interpreter, another loader, a libraryoutside the list or named like one on it, and the operatorbinaries 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``build`` (1)~~~~~~~~~~~~~@@ -734,7 +737,7 @@ Coverage by area- ``t0005``, ``t0007``, ``t1003``, ``t1004``, ``t1005``,``t1008``, ``t7004``, ``t8003``* - CI scripts- - ``t0001`` to ``t0007``+ - ``t0001`` to ``t0008``* - Parsers- ``t3001``, ``t3011``, ``t5002``, ``t5006``, ``t5008``. Unit:``hex``, ``json``, ``string``. Every fuzz targetdiff --git a/testing/ci-checks/t0008-check-docs.sh b/testing/ci-checks/t0008-check-docs.shnew file mode 100755index 00000000..0cb0b29a--- /dev/null+++ b/testing/ci-checks/t0008-check-docs.sh@@ -0,0 +1,89 @@+#!/bin/sh+# SPDX-License-Identifier: BSD-2-Clause+# 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.++cd "$(dirname "$0")/.."+. ./test-lib.sh+command -v git >/dev/null 2>&1 || test_skip_all "git not installed"+ROOT=$(cd .. && pwd)+S=$ROOT/.github/scripts/check-docs.sh+W=$(mktemp -d)+trap 'rm -rf "$W"' EXIT+R=$W/repo+TM=Documentation/security/threat-model.rst+COV=Documentation/contribute/testing/proof-coverage.rst++# A file with the given lines, each argument one line.+put() {+ f=$R/$1+ shift+ mkdir -p "$(dirname "$f")"+ printf '%s\n' "$@" >"$f"+}++# A tree the check passes: one fact box whose fields continue on a second+# line.+good() {+ rm -rf "$R" && mkdir -p "$R" && git init -q "$R" &&+ put shirudo.c 'int main(void) { return 0; }' &&+ put builtin-upatch.c 'int upatch;' &&+ put tools/shirudo-build/build.c 'int build;' &&+ put tools/gen-image/gen '#!/bin/sh' &&+ put tools/gen-initrd/gen '#!/bin/sh' &&+ put util/tamper.c 'static const struct point points[] = {' \+ ' [0] = { "Good", 1 },' '};' &&+ 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/lean4/Shirudo/Model.lean 'theorem model : True := trivial' &&+ put Documentation/security/tamper-counters.rst '``Good``' &&+ put "$TM" ':Enforced at: ``lsm/file_open``,' \+ ' ``lsm.s/inode_setattr``' \+ ':Counters: none for a first attempt,' \+ ' ``Good``' \+ ':Tests: ``t1001``' \+ ':Proofs: ``first``,' \+ ' ``second``' &&+ put "$COV" ' * - ``first``' ' * - ``second``' \+ ' * - ``Shirudo.Model``'+}++check() {+ (cd "$R" && git add -A && sh "$S") >"$W/out" 2>"$W/err"+}++# The check fails and says so.+refuses() {+ ! check && grep -qF "$1" "$W/err"+}++test_expect_success 'a tree whose fields continue on a second line passes' '+ good && check+'++test_expect_success 'a hook on a continuation line is checked, by its section' '+ good && sed -i "s|lsm.s/inode_setattr|lsm.s/inode_setattrx|" "$R/$TM" &&+ refuses "no BPF program has the section lsm.s/inode_setattrx" &&+ good && sed -i "s|lsm.s/inode_setattr|lsm/inode_setattr|" "$R/$TM" &&+ refuses "no BPF program has the section lsm/inode_setattr"+'++test_expect_success 'a counter and a proof on a continuation line are checked' '+ good && sed -i "s|\`\`Good\`\`|\`\`Goodx\`\`|" "$R/$TM" &&+ refuses "no tamper counter is named Goodx" &&+ good && sed -i "s|\`\`second\`\`|\`\`secondx\`\`|" "$R/$TM" &&+ refuses "no proof is named secondx"+'++test_expect_success 'the tree itself passes' '+ (cd "$ROOT" && sh "$S") >"$W/out" 2>"$W/err"+'++test_done