eBPF-based security platform
Documentation: name every LSM program and counter in a fact box
Daniel Borkmann3f9bfd0e8092
diff --git a/.github/scripts/check-docs.sh b/.github/scripts/check-docs.shindex 99b17afb..562e08f8 100755--- a/.github/scripts/check-docs.sh+++ b/.github/scripts/check-docs.sh@@ -6,8 +6,9 @@# 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, 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.+# and unit a page names exists, every LSM program and tamper counter+# stands in the fact box of a threat, and every source file is read by a+# proof or listed as read by none.## .github/scripts/check-docs.sh#@@ -98,6 +99,24 @@ while IFS= read -r page; dodonedone <"$work/pages"+# Every LSM program and every tamper counter stands in the fact box of+# some threat. A page without one is no error of the loop.+threats=Documentation/security/threat-model.rst+while IFS= read -r page; do+ field 'Enforced at' "$page" | grep -oE '``lsm(\.s)?/[a-z_]+``' || :+done <"$work/pages" | tr -d '`' | sort -u >"$work/named_hooks"+while IFS= read -r hook; do+ grep -qxF "$hook" "$work/named_hooks" ||+ report "$threats" "no threat names the program $hook"+done <"$work/hooks"+while IFS= read -r page; do+ field Counters "$page" | grep -oE '``[A-Za-z]+``' || :+done <"$work/pages" | tr -d '`' | sort -u >"$work/named_counters"+while IFS= read -r counter; do+ grep -qx "$counter" "$work/named_counters" ||+ report "$threats" "no threat names the counter $counter"+done <"$work/counters"+# Every test id a page names exists under testing/.find testing -name 't[0-9][0-9][0-9][0-9]-*' | sed -E 's|.*/(t[0-9]{4}).*|\1|' |sort -u >"$work/tests"diff --git a/Documentation/contribute/documentation/writing-docs.rst b/Documentation/contribute/documentation/writing-docs.rstindex 1ac714b0..c9b3c3e6 100644--- a/Documentation/contribute/documentation/writing-docs.rst+++ b/Documentation/contribute/documentation/writing-docs.rst@@ -87,17 +87,21 @@ the ``facts`` class:.. rst-class:: facts:Adversary: ADV-B, root on the target without the signing key- :Enforced at: ``lsm/bpf``, ``inode_unlink``, ``sb_umount``+ :Enforced at: ``lsm/bpf``, ``lsm/inode_unlink``, ``lsm/sb_umount``:Refusal: ``EACCES`` from the denied system call:Counters: ``BpfCommand``, ``PinUnlink``, ``BpffsUmount``:Tests: ``t6106``, ``t6107``, ``t6120``:Proofs: ``upatch-header``, ``Shirudo.Chain``:Residual: R3-Name only hooks, counters, tests and proofs that exist, a proof by its-name in :src:`testing/proofs/cbmc/proofs.list` or its Lean 4 module, and-add ``:Proofs:`` only where a proof covers the check the threat rests-on. ``make -C Documentation check`` verifies them against the tree.+Name only hooks, counters, tests and proofs that exist, a hook by the+section of its program, ``lsm/`` or ``lsm.s/``, a proof by its name in+:src:`testing/proofs/cbmc/proofs.list` or its Lean 4 module, and add+``:Proofs:`` only where a proof covers the check the threat rests on.+Every LSM program of :src:`bpf/` stands in the ``:Enforced at:`` field+of some threat, one that refuses nothing after the others with what it+does, and every tamper counter in a ``:Counters:`` field. ``make -C+Documentation check`` verifies all of this against the tree.Page metadata-------------diff --git a/Documentation/security/threat-model.rst b/Documentation/security/threat-model.rstindex 1098e3c3..598b9ccc 100644--- a/Documentation/security/threat-model.rst+++ b/Documentation/security/threat-model.rst@@ -52,7 +52,8 @@ The fields of the box are:- Adversary: who mounts the threat- Enforced at: the BPF LSM programs that refuse it, by their section- name in :src:`bpf/`+ name in :src:`bpf/`, and after them the programs that refuse nothing+ and keep the state the refusals read- Refusal: what the caller sees- Counters: the tamper counters the refusal moves, described in:doc:`tamper-counters`@@ -529,7 +530,8 @@ the keyring.Root cannot assemble a validly signed loader outside shirudo either. Aloader needs its metadata map, and ``BPF_MAP_CREATE`` needs runtime-authority (``MapCreate``), as do the routes to an existing map (T13).+authority (``MapCreate``), as do filling and freezing the map+(``MapWrite``) and the routes to an existing one (T13).The programs a verified loader loads run in kernel context, and bothhooks admit calls whose ``kernel`` argument is set.@@ -550,7 +552,7 @@ any loader the key ever signed passes (R16).as ``ENOKEY``, ``EKEYREJECTED``, or ``EPERM`` for a caller-suppliedkeyring:Counters: ``LoadNotLoader``, ``LoadUnsigned``, ``LoadUnverified``,- ``LoadKeyringKind``, ``MapCreate``+ ``LoadKeyringKind``, ``LoadKeyring``, ``MapCreate``, ``MapWrite``:Tests: ``t6102``, ``t6103``, ``t6104``, ``t6107``, ``t6108``, ``t6138``:Residual: R7, R16, R18@@ -825,7 +827,11 @@ An authorized process is protected against being taken over:``lsm.s/bprm_check_security``, ``lsm.s/bprm_committed_creds``,``lsm/task_alloc``, ``lsm/bprm_check_security``,``lsm/ptrace_access_check``, ``lsm/perf_event_alloc``,- ``lsm/task_prctl``, ``lsm/mmap_file``, ``lsm/file_mprotect``+ ``lsm/task_prctl``, ``lsm/mmap_file``, ``lsm/file_mprotect``; in+ support, ``lsm.s/bprm_creds_for_exec`` and ``lsm/socket_post_create``+ carry the policy bits, ``lsm.s/inode_post_setxattr`` and+ ``lsm.s/inode_post_removexattr`` refresh an inode's mark, and+ ``lsm/task_kill`` counts a signal it lets through:Refusal: ``EACCES`` from the seal and the task hooks; ``EPERM`` from acopy-up, a traced exec in the ``bpf2`` hook and ``PR_SET_MM``;``tampered`` or a foreign-entry warning from shirudo@@ -1268,7 +1274,9 @@ the operator relies on.authority: a writable one as ``MapFdWrite`` and a read-only one as``ObjGet``. ``lsm/bpf`` refuses the routes to a descriptor,``BPF_OBJ_GET`` and ``BPF_MAP_GET_FD_BY_ID`` (``ObjGet``), and-``BPF_PROG_TEST_RUN`` (``ProgRun``). ``lsm/file_open`` refuses opening a+``BPF_PROG_TEST_RUN`` (``ProgRun``), and with ``BPF_MAP_UPDATE_ELEM``+and ``BPF_MAP_FREEZE`` the writing and freezing of a map+(``MapWrite``). ``lsm/file_open`` refuses opening apin as a file, through which bpffs would print a map's contents(``ObjGet``). A writable memory mapping of an arena needs a writabledescriptor. A process whose executable is not on the runtime image@@ -1284,7 +1292,7 @@ given (R2).:Adversary: ADV-B, root on the target without the signing key:Enforced at: ``lsm/bpf``, ``lsm/bpf_map``, ``lsm/file_open``:Refusal: ``EACCES`` from ``bpf()`` and from opening a pin-:Counters: ``ObjGet``, ``MapFdWrite``, ``ProgRun``+:Counters: ``ObjGet``, ``MapFdWrite``, ``MapWrite``, ``ProgRun``:Tests: ``t6107``, ``t6108``, ``t6109``, ``t6110``:Residual: R2, U19diff --git a/testing/ci-checks/t0008-check-docs.sh b/testing/ci-checks/t0008-check-docs.shindex c097c125..c9955821 100755--- a/testing/ci-checks/t0008-check-docs.sh+++ b/testing/ci-checks/t0008-check-docs.sh@@ -3,9 +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, 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.+# threat's fact box, a hook by its section, the programs and counters no+# threat names, 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@@ -93,6 +93,16 @@ test_expect_success 'a counter and a proof on a continuation line are checked' 'refuses "no proof is named secondx"'+test_expect_success 'every program and every counter stands in a fact box' '+ good && put bpf/guard.c "SEC(\"lsm/file_open\")" \+ "SEC(\"lsm.s/inode_setattr\")" "SEC(\"lsm/task_kill\")" &&+ refuses "no threat names the program lsm/task_kill" &&+ good && put util/tamper.c "static const struct point points[] = {" \+ " [0] = { \"Good\", 1 }," " [1] = { \"Other\", 1 }," "};" &&+ put Documentation/security/tamper-counters.rst "\`\`Good\`\`" "\`\`Other\`\`" &&+ refuses "no threat names the counter Other"+'+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" &&