eBPF-based security platform
bpf2: count the kernel's integrity refusals apart from tamper
Daniel Borkmann64692cd4a908
diff --git a/.agents/skills/docs/SKILL.md b/.agents/skills/docs/SKILL.mdindex d5c1c650..cc247d71 100644--- a/.agents/skills/docs/SKILL.md+++ b/.agents/skills/docs/SKILL.md@@ -1,6 +1,6 @@---name: docs-description: Keep Documentation/ in step with a change to shirudo. Covers which pages describe a command, option, message, failure category, tamper counter, LSM hook, file, unit, environment variable, setting, format, Beefile key, test, kernel patch or threat, how to write the change in the voice of its page, and how to check the result. Use whenever code changes behavior a page describes, when a test is added or removed, and when writing or reviewing a page.+description: Keep Documentation/ in step with a change to shirudo. Covers which pages describe a command, option, message, failure category, tamper or integrity counter, LSM hook, file, unit, environment variable, setting, format, Beefile key, test, kernel patch or threat, how to write the change in the voice of its page, and how to check the result. Use whenever code changes behavior a page describes, when a test is added or removed, and when writing or reviewing a page.---# Documentation@@ -26,6 +26,7 @@ Then go through the pages each kind of change has:| Command, option, usage | `reference/cli/<command>.rst`, the command's help text, `completion/shirudo.bash`, `reference/cheat-sheet.rst`, the guides that run it || Error message, exit status, failure category | `reference/failure-categories.rst` || Tamper counter | `security/tamper-counters.rst` |+| Integrity counter | `security/integrity-counters.rst` || LSM hook | `internals/enforcement.rst`, the fact boxes of `security/threat-model.rst` || File or directory | `reference/files.rst` || systemd unit | `reference/systemd-units.rst` |@@ -62,9 +63,9 @@ make docs # renders and serves on 127.0.0.1:8000````check-docs.sh` checks the options of console examples, the failure-categories, tamper counters, hooks, tests, proofs and units the pages-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-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+categories, tamper and integrity counters, hooks, tests, proofs and+units the pages 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 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 paragraphagainst the code.diff --git a/.github/scripts/check-docs.sh b/.github/scripts/check-docs.shindex 562e08f8..b502fcfe 100755--- a/.github/scripts/check-docs.sh+++ b/.github/scripts/check-docs.sh@@ -4,11 +4,11 @@## .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, every hook, counter, test, proof-# 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.+# every failure category the code emits, every tamper and integrity+# counter and every proof has its entry in the reference, every hook,+# counter, test, proof and unit a page names exists, every LSM program+# and 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#@@ -64,14 +64,22 @@ while IFS= read -r category; doreport "$categories" "no entry for the emitted category $category"done <"$work/categories"-# Every tamper counter has an entry, and a page names no other.-counters=Documentation/security/tamper-counters.rst-grep -oE '= \{ "[A-Za-z]+",' util/tamper.c | sed -E 's/.*"([A-Za-z]+)".*/\1/' |- sort -u >"$work/counters"-while IFS= read -r counter; do- grep -qF "\`\`$counter\`\`" "$counters" ||- report "$counters" "no entry for the counter $counter"-done <"$work/counters"+# Every tamper and integrity counter has an entry on its page, and a+# page names no other.+counter_names() {+ grep -oE '= \{ "[A-Za-z]+",' "$1" | sed -E 's/.*"([A-Za-z]+)".*/\1/' |+ sort -u+}+counter_names util/tamper.c >"$work/tamper_counters"+counter_names util/integrity.c >"$work/integrity_counters"+sort -u "$work/tamper_counters" "$work/integrity_counters" >"$work/counters"+for kind in tamper integrity; do+ counters=Documentation/security/$kind-counters.rst+ while IFS= read -r counter; do+ grep -qF "\`\`$counter\`\`" "$counters" ||+ report "$counters" "no entry for the counter $counter"+ done <"$work/${kind}_counters"+done# A field of a fact box, with the lines that continue it, as one line.field() {@@ -95,12 +103,12 @@ while IFS= read -r page; dofield 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"+ report "$page" "no counter is named $counter"donedone <"$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.+# Every LSM program and every counter stands in the fact box of some+# threat. A page without one is no error of the loop.threats=Documentation/security/threat-model.rstwhile IFS= read -r page; dofield 'Enforced at' "$page" | grep -oE '``lsm(\.s)?/[a-z_]+``' || :diff --git a/AGENTS.md b/AGENTS.mdindex 2be6cbfb..7ec1871b 100644--- a/AGENTS.md+++ b/AGENTS.md@@ -227,7 +227,8 @@ one usually still compiles and passes tests.pointer, and the verifier would allow it. `shirudo_bpffs_sb` carriesthe flag for that reason. A map a BPF program writes, even once(`shirudo_mnt_rec`, the task, socket and inode storage maps,- `shirudo_tamper`, `shirudo_devices`, upatch state), does not take it.+ `shirudo_tamper`, `shirudo_integrity`, `shirudo_devices`, upatch+ state), does not take it.A map added later that fits the no-BPF-write criterion takes the flagfrom the commit that adds it; a map that stops fitting it drops theflag in the same commit that adds the write.diff --git a/Documentation/concepts/glossary.rst b/Documentation/concepts/glossary.rstindex 25b77d4a..c89e9889 100644--- a/Documentation/concepts/glossary.rst+++ b/Documentation/concepts/glossary.rst@@ -279,8 +279,8 @@ it.private bpffsThe BPF file system instance that ``init`` mounts at``/run/shirudo/bpffs`` with mode ``0700``. It holds the pins of the- enforcement links, the identity map, the tamper counters and every- upatch's links and maps. BPF LSM hooks refuse unlink, rename and+ enforcement links, the identity map, the tamper and integrity+ counters and every upatch's links and maps. BPF LSM hooks refuse unlink, rename andopening a pin there to tasks without runtime authority, and refuseevery caller the unmount, move or remount of the mount ``init``made. See :doc:`/internals/enforcement`.@@ -391,6 +391,14 @@ it.is the only way BPF from userspace enters the kernel. See:doc:`/internals/signed-loader`.+ integrity counter+ A counter for one way to change or read the running kernel that+ the enforcement programs refuse, such as ``ModuleSignature``,+ ``DevMem`` or ``Kcore``. The counters live in a map pinned at+ ``/run/shirudo/bpffs/integrity``, apart from the tamper counters,+ and ``shirudo status`` reports them. See+ :doc:`/security/integrity-counters`.+tamper counterA counter for one point at which the enforcement programs refuse acaller, such as ``BpfCommand``, ``PinUnlink`` or ``ObjGet``, or,diff --git a/Documentation/concepts/operator-and-target.rst b/Documentation/concepts/operator-and-target.rstindex dfdc3738..e1c03a94 100644--- a/Documentation/concepts/operator-and-target.rst+++ b/Documentation/concepts/operator-and-target.rst@@ -106,8 +106,8 @@ Table 1 lists what it does hold.* - The trusted certificates- The kernel's ``.bpf`` keyring- Sealed by ``init``, and ``lsm/key_permission``- * - Enforcement links, the identity map, the tamper counters, upatch- links and maps+ * - Enforcement links, the identity map, the tamper and integrity+ counters, upatch links and maps- The private bpffs at ``/run/shirudo/bpffs``- BPF LSM hooks on unlink, rename, mount and descriptor access* - Archived upatches, the eventlog, package and tree state, cacheddiff --git a/Documentation/contribute/code/developer-guide.rst b/Documentation/contribute/code/developer-guide.rstindex 6486774d..b459c1be 100644--- a/Documentation/contribute/code/developer-guide.rst+++ b/Documentation/contribute/code/developer-guide.rst@@ -388,7 +388,7 @@ Project layout- The headers more than one BPF program includes: the LSM helpersand verity device records of ``bpf2.c`` and ``seal.c``, and,shared with upatches and userspace, decoders, identity,- serializers, tamper counters and common helpers.+ serializers, tamper and integrity counters and common helpers.* - :src:`include/shirudo/`- Integer types, string and number helpers, the ``.upatch``container layout, TPM types and the enforcement definitionsdiff --git a/Documentation/contribute/testing/proof-coverage.rst b/Documentation/contribute/testing/proof-coverage.rstindex 4a9ee916..5fe9a485 100644--- a/Documentation/contribute/testing/proof-coverage.rst+++ b/Documentation/contribute/testing/proof-coverage.rst@@ -738,9 +738,9 @@ or shorter, and "lengths 0 to 6" every input of each of those lengths.- Three fixed bodies, without a tree, with a tree and nothing elsethat may be null, and with every value; the last of these with alast number of up to 4 digits in a buffer that holds 0 to 3 of- them; rooms of 0, 1 and 208 bytes; a missing string, a bad hash+ them; rooms of 0, 1 and 224 bytes; a missing string, a bad hashand a byte that is not UTF-8- - Each body one JSON object of 22 members by a byte-level+ - Each body one JSON object of 23 members by a byte-levelrecognizer, terminated in the buffer; another last numberchanges only its digits, without a leading zero, or is``-ENOSPC`` exactly when it does not fit; ``-EINVAL`` and@@ -1275,11 +1275,11 @@ a proof covers.: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/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`+ :src:`util/integrity.c`, :src:`util/keyring.c`,+ :src:`util/preflight.c`, :src:`util/seal.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 limitsdiff --git a/Documentation/contribute/testing/test-coverage.rst b/Documentation/contribute/testing/test-coverage.rstindex 540bc47e..d687018e 100644--- a/Documentation/contribute/testing/test-coverage.rst+++ b/Documentation/contribute/testing/test-coverage.rst@@ -63,8 +63,9 @@ 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, the source files a proof reads or the- proof coverage page lists as read by none, and the tree itself+ box, a hook by its section, each tamper and integrity counter's+ entry on its page, the source files a proof reads or the proof+ coverage page lists as read by none, and the tree itself``build`` (1)~~~~~~~~~~~~~@@ -357,7 +358,7 @@ signed config image.* - ``t6002-seal-seccomp``- The seal builds with either seccomp layout in ``vmlinux.h``* - ``t6003-tamper-points``- - Every tamper counter has a name and a meaning+ - Every tamper and integrity counter has a name and a meaning* - ``t6004-conditions``- Status conditions: both keyrings, register, pins, configactivation@@ -510,8 +511,9 @@ signed config image.* - ``t6154-lockdown``- A module without its signature, a PCI config write,``/proc/kcore`` and ``/dev/mem``, where the kernel has them, are- refused, all but the last counted as ``Lockdown``, and a read of- ``/sys/power/state`` counts nothing+ refused, all but the last counted on their integrity counters,+ which ``status``, its JSON and the keepalive report, and a read+ of ``/sys/power/state`` counts nothing* - ``t6155-mountpoint-removal``- From a namespace without ``/run``, an ``rmdir`` and a rename ofthe directory init's ``/run`` covers are refused and counted, and@@ -1045,13 +1047,22 @@ tests assert that a refusal moves its counter:- ``t6152``* - ``XattrHandle``- ``t6153``, on a kernel with XFS- * - ``Lockdown``- - ``t6154``* - ``SealRlimit``- ``t6156``* - ``Kexec``- ``t6126``+Coverage of integrity counters+------------------------------++``t6003`` checks that every integrity counter has a name and a meaning.+``t6154`` asserts that a refusal moves ``ModuleSignature``, ``Kcore``+and ``PciAccess``, the last two where the kernel has them, and that+``status``, its JSON and the keepalive report the counters. No test+moves the others. The test guest boots without UEFI firmware, so it has+no efivarfs for ``HibernateLocation``, and ``KexecSignature`` cannot+move while the ``Kexec`` guard refuses every kexec image first.+Not covered-----------diff --git a/Documentation/internals/enforcement.rst b/Documentation/internals/enforcement.rstindex 948fed75..4e7c6a53 100644--- a/Documentation/internals/enforcement.rst+++ b/Documentation/internals/enforcement.rst@@ -83,6 +83,10 @@ The objects share seven maps, which ``init`` hands from ``bpf2`` to* - ``shirudo_tamper``- ``tamper``- One counter per refusal point, see :doc:`/security/tamper-counters`.+ * - ``shirudo_integrity``+ - ``integrity``+ - One counter per way to change or read the running kernel that+ ``bpf2`` refuses, see :doc:`/security/integrity-counters`.``init`` freezes every one of them against userspace writes except``shirudo_roots``, which an authorized task writes before each config@@ -351,7 +355,7 @@ when the record it needs is missing.when the bootstrap task opens its root. Opening a``HibernateLocation`` EFI variable for writing, to every caller.- ``EACCES``; ``EPERM`` for the EFI variable- - ``ObjGet``; ``Lockdown``+ - ``ObjGet``; ``HibernateLocation``- Closed.* - ``lsm/file_ioctl``, ``lsm/file_ioctl_compat`` (``bpf2``)- ``PERF_EVENT_IOC_SET_BPF`` on any file,@@ -552,7 +556,7 @@ when the record it needs is missing.- Every lockdown reason of integrity mode, an unsigned moduleincluded, and ``LOCKDOWN_KCORE``, to every caller.- ``EPERM``- - ``Lockdown``; hibernation uncounted+ - The integrity counter of the reason; hibernation uncounted- Unconditional; the kernel's lockdown LSM decides first.* - ``lsm.s/file_open`` (``seal``)- A write open of a labeled file to a task without authority. On adiff --git a/Documentation/operate/deploy/boot-integration.rst b/Documentation/operate/deploy/boot-integration.rstindex ddb8d0b1..5ca7d8e3 100644--- a/Documentation/operate/deploy/boot-integration.rst+++ b/Documentation/operate/deploy/boot-integration.rst@@ -463,6 +463,9 @@ Boot and verifySealWrite 1 write open of a sealed fileSealEntry 2 entry into a sealed directory, or a sealed inode linked+ Integrity attempts (this boot):+ none+Loaded upatches (1):NAME LOCATION MAPS STATUS AGEshirudo-test-basic fentry/do_nanosleep 0 success 1sdiff --git a/Documentation/operate/deploy/initialize.rst b/Documentation/operate/deploy/initialize.rstindex 5a633a88..eb130e2b 100644--- a/Documentation/operate/deploy/initialize.rst+++ b/Documentation/operate/deploy/initialize.rst@@ -87,6 +87,9 @@ Check that init workedSealWrite 1 write open of a sealed fileSealEntry 2 entry into a sealed directory, or a sealed inode linked+ Integrity attempts (this boot):+ none+Loaded upatches (1):NAME LOCATION MAPS STATUS AGEshirudo-test-basic fentry/do_nanosleep 0 success 1sdiff --git a/Documentation/operate/integrations/clickhouse.rst b/Documentation/operate/integrations/clickhouse.rstindex 63013b27..e51217b5 100644--- a/Documentation/operate/integrations/clickhouse.rst+++ b/Documentation/operate/integrations/clickhouse.rst@@ -192,7 +192,10 @@ to alert on.``tamper`` lists every counter, so their sum is the number ofrefusals since boot. The counters only grow within a boot and startat zero at the next, so the query compares the keepalives of one boot,- ``boot_id``, and a reboot in the window reports nothing.+ ``boot_id``, and a reboot in the window reports nothing. ``integrity``+ lists the integrity counters the same way; the query with+ ``integrity`` in place of ``tamper`` finds targets that refused a+ change to their running kernel.Next steps----------diff --git a/Documentation/operate/integrations/elasticsearch.rst b/Documentation/operate/integrations/elasticsearch.rstindex 2b8f7bb7..72e39885 100644--- a/Documentation/operate/integrations/elasticsearch.rst+++ b/Documentation/operate/integrations/elasticsearch.rst@@ -183,14 +183,17 @@ what to alert on.FROM logs-generic.otel-default| WHERE event_name == "shirudo.keepalive" AND @timestamp > NOW() - 10 minutes| GROK body.text "\"boot_id\":\"%{DATA:boot_id}\""- | GROK body.text "\"tamper\":%{DATA:tamper},\"tree_id\""+ | GROK body.text "\"tamper\":%{DATA:tamper},\"integrity\""| STATS counts = COUNT_DISTINCT(tamper) BY host.name, boot_id| WHERE counts > 1``tamper`` lists every counter since boot. The counters only growwithin a boot and start at zero at the next, so more than one list inthe keepalives of one ``boot_id`` means a counter rose, and a reboot- in the window reports nothing.+ in the window reports nothing. ``integrity`` lists the integrity+ counters the same way; the query with+ ``"\"integrity\":%{DATA:integrity},\"tree_id\""`` finds targets that+ refused a change to their running kernel.Next steps----------diff --git a/Documentation/operate/integrations/grafana.rst b/Documentation/operate/integrations/grafana.rstindex e06d0beb..579e8fca 100644--- a/Documentation/operate/integrations/grafana.rst+++ b/Documentation/operate/integrations/grafana.rst@@ -176,7 +176,9 @@ on.different lists of counters, ``tamper``, in the keepalives of oneboot in ten minutes. The counters only grow within a boot and startat zero at the next, so more than one list means a counter rose, and- a reboot in the window gives no alert.+ a reboot in the window gives no alert. ``integrity`` lists the+ integrity counters the same way; the rule with ``integrity`` in place+ of ``tamper`` alerts on a refused change to the running kernel.#. Point the ruler at the directory and at your Alertmanager in Loki'sconfiguration:diff --git a/Documentation/operate/integrations/splunk.rst b/Documentation/operate/integrations/splunk.rstindex 96f99e02..da4fc81c 100644--- a/Documentation/operate/integrations/splunk.rst+++ b/Documentation/operate/integrations/splunk.rst@@ -146,7 +146,10 @@ on.``tamper`` lists every counter since boot. The counters only growwithin a boot and start at zero at the next, so more than one list inthe keepalives of one ``boot_id`` means a counter rose, and a reboot- in the window reports nothing.+ in the window reports nothing. ``integrity`` lists the integrity+ counters the same way; the query with ``integrity`` in place of+ ``tamper`` finds targets that refused a change to their running+ kernel.Next steps----------diff --git a/Documentation/operate/plan/hardening.rst b/Documentation/operate/plan/hardening.rstindex 5b32bfc1..ddd7563c 100644--- a/Documentation/operate/plan/hardening.rst+++ b/Documentation/operate/plan/hardening.rst@@ -55,7 +55,7 @@ Kernel configurationkernel does not refuse it first (``CONFIG_MODULE_SIG_FORCE`` or``module.sig_enforce=1``).- partly: from ``init`` on, an unsigned module is refused and- counted as ``Lockdown``+ counted as ``ModuleSignature``* - ``CONFIG_STRICT_DEVMEM`` and ``CONFIG_IO_STRICT_DEVMEM``, or no``/dev/mem`` at all- Limits ``/dev/mem`` before ``init``, after which ``bpf2`` refuses@@ -77,7 +77,7 @@ Kernel configuration- partly: from ``init`` on, hibernating is refused, and so is awrite of the ``HibernateLocation`` EFI variable through whichsystemd's initrd finds an image the UKI does not name, counted- as ``Lockdown``+ as ``HibernateLocation``* - Kexec- A kexec boots a kernel and initrd of root's choosing while theTPM keeps this boot's register and PCRs.diff --git a/Documentation/operate/plan/interoperability.rst b/Documentation/operate/plan/interoperability.rstindex 2ff9786b..5230a11c 100644--- a/Documentation/operate/plan/interoperability.rst+++ b/Documentation/operate/plan/interoperability.rst@@ -287,8 +287,9 @@ Module loading and kernel live patchingother.:Symptom: ``init_module(2)`` and ``finit_module(2)`` of an unsignedmodule fail with ``EPERM`` (``modprobe`` prints ``Operation not- permitted``), and ``Lockdown`` counts it. ``modprobe --force``, which- strips the version checks, makes a signed module count as unsigned.+ permitted``), and the integrity counter ``ModuleSignature`` counts+ it. ``modprobe --force``, which strips the version checks, makes a+ signed module count as unsigned.:What to do: Build the kernel with ``CONFIG_MODULE_SIG``, as:doc:`/operate/plan/hardening` lists, and sign every module thetarget loads, livepatch modules included, with a key the kerneldiff --git a/Documentation/operate/run/read-status.rst b/Documentation/operate/run/read-status.rstindex 78377f4f..f8f23e54 100644--- a/Documentation/operate/run/read-status.rst+++ b/Documentation/operate/run/read-status.rst@@ -58,6 +58,9 @@ Print the reportSealWrite 1 write open of a sealed fileSealEntry 2 entry into a sealed directory, or a sealed inode linked+ Integrity attempts (this boot):+ none+Loaded upatches (1):NAME LOCATION MAPS STATUS AGEshirudo-test-basic fentry/do_nanosleep 0 success 1s@@ -110,6 +113,9 @@ line; a section unfolds on its own when its condition is not ``OK``.SealWrite 1 write open of a sealed fileSealEntry 2 entry into a sealed directory, or a sealed inode linked+ Integrity attempts (this boot):+ none+Loaded upatches (1):NAME LOCATION MAPS STATUS AGEshirudo-test-basic fentry/do_nanosleep 0 success 1s@@ -767,6 +773,14 @@ Read the counters with these rules::doc:`/security/tamper-counters` lists every counter and the guard pointthat raises it.+``Integrity attempts (this boot):`` follows with the same layout for+the refused changes and reads of the running kernel: an unsigned+module, ``/dev/mem``, a PCI configuration write, ``/proc/kcore`` and+the others lockdown in integrity mode names.+:doc:`/security/integrity-counters` lists them. Read them with the same+rules, and count with a baseline here too: a tool that opens a writable+debugfs file to read it moves ``Debugfs``.+Monitor with ``status --json``------------------------------diff --git a/Documentation/operate/run/telemetry.rst b/Documentation/operate/run/telemetry.rstindex d76f6056..a76cfde8 100644--- a/Documentation/operate/run/telemetry.rst+++ b/Documentation/operate/run/telemetry.rst@@ -60,7 +60,8 @@ allow for. See :doc:`/reference/systemd-units`.The keepalive record has the event name ``shirudo.keepalive``. Its bodyis a string, the keepalive body that ``shirudo status --keepalive``prints: one compact JSON object of about a kilobyte with the verdict,-the conditions, the tamper counters, the build, the config and image,+the conditions, the tamper and integrity counters, the build, the+config and image,the tree the target follows and the upatches it has loaded(:doc:`/reference/cli/status`). Its one attribute, ``shirudo.quote``, isthe TPM quote of the SHA-256 of the body by the attestation key of@@ -423,6 +424,10 @@ eventlog, is read with ``shirudo status --json`` on the target.- Something on the target tried an operation the guards refused.The counters start at zero each boot. See:doc:`/security/tamper-counters`.+ * - A counter of ``integrity`` rises+ - Something on the target tried to change or read the running+ kernel, and ``bpf2`` refused it. The counters start at zero each+ boot. See :doc:`/security/integrity-counters`.* - Bit 0 of ``flags``, ``register_rebound``- The register was bound twice in one TPM reset.* - Bit 1 of ``flags``, ``bound_late``diff --git a/Documentation/operate/troubleshoot/incident-tampered.rst b/Documentation/operate/troubleshoot/incident-tampered.rstindex 392d2d0f..0a7f0383 100644--- a/Documentation/operate/troubleshoot/incident-tampered.rst+++ b/Documentation/operate/troubleshoot/incident-tampered.rst@@ -34,9 +34,10 @@ whatever changed it. Do not reboot the target before the evidence issafe: a reboot starts a new register, and the TPM can no longer certifythe state of this boot.-A tamper counter that moved is a different signal: something tried an-operation and the LSM refused it. :doc:`/security/tamper-counters`-explains the counters.+A tamper or integrity counter that moved is a different signal:+something tried an operation and the LSM refused it.+:doc:`/security/tamper-counters` and :doc:`/security/integrity-counters`+explain the counters.Before you begin----------------diff --git a/Documentation/reference/cli/status.rst b/Documentation/reference/cli/status.rstindex 54027a04..eea7226a 100644--- a/Documentation/reference/cli/status.rst+++ b/Documentation/reference/cli/status.rst@@ -69,7 +69,7 @@ The report shows seven conditions, each ``OK``, ``WARN`` or ``ALERT``:- None of the above.The human report follows the verdict with the conditions, the tamper-counters that moved this boot and the loaded upatches. Three sections+and integrity counters that moved this boot and the loaded upatches. Three sectionsare folded unless ``--show-full`` asks for them: the ``.bpf`` and``.dm-verity`` keyrings with the certificates each should hold and thekey that holds each one, the TPM measurement state and the assets under@@ -100,11 +100,11 @@ the full document, not the keepalive body, and ``--include-system`` andWith ``--keepalive``, ``status`` prints the keepalive body, the compactstatus record a node's TPM quotes, as one line on standard output. Itneither quotes nor sends it and needs no TPM, so an operator can see-what a node reports. The body has 22 keys in a fixed order: ``schema``+what a node reports. The body has 23 keys in a fixed order: ``schema``(``shirudo.keepalive/1``), ``boot_id``, ``version_id``, ``config_root``,``kernel_release``, ``image_id``, ``image_version``, ``image_root``,-``verdict``, ``cond``, ``flags``, ``tamper``, ``tree_id``,-``generation``, ``base_seq``, ``last_seq``, ``base_root``,+``verdict``, ``cond``, ``flags``, ``tamper``, ``integrity``,+``tree_id``, ``generation``, ``base_seq``, ``last_seq``, ``base_root``,``projection_root``, ``mask``, ``set_sha256``, ``count`` and ``not_ok``.A key that does not apply is ``null``:@@ -117,7 +117,9 @@ at bits ``2i`` and ``2i+1``, ``LsmAttached`` first and ``XdpCovered``last: ``00`` not evaluated, ``01`` ``OK``, ``10`` ``WARN``, ``11````ALERT``. All seven ``OK`` is ``5461``. ``tamper`` lists every counterof :doc:`/security/tamper-counters`, zeros included, in the order of-that page.+that page, and ``integrity`` every counter of+:doc:`/security/integrity-counters` the same way. A collector reads a+counter by its place: a new one is appended, never put between two.The tree keys report a window of the last 512 operations up to the headof the recorded publication, whatever segments hold them: ``base_seq``@@ -163,6 +165,9 @@ The bits of ``flags``:- ``snapshot_unsettled``- ``state.json`` kept changing while the body was read, which theconfig operation lock leaves to a writer outside it.+ * - 6+ - ``integrity_unavailable``+ - The integrity counters cannot be read; ``integrity`` is ``null``.``status`` holds the config operation lock for its whole run, as everytarget command does, a ``bpm tree sync`` included. It therefore never@@ -255,7 +260,8 @@ reads ``.status`` and the conditions from the JSON document.Files and environment----------------------- Reads ``/run/shirudo/bpffs`` (pins, identity, tamper counters), the+- Reads ``/run/shirudo/bpffs`` (pins, identity, tamper and integrity+ counters), the``.bpf`` and ``.dm-verity`` keyrings, the TPM register,``/var/lib/shirudo/eventlog``, ``/var/lib/shirudo/keys``, the configcertificate the runtime image's bootstrap names and the config@@ -301,6 +307,9 @@ Show the state of a target:SealWrite 1 write open of a sealed fileSealEntry 2 entry into a sealed directory, or a sealed inode linked+ Integrity attempts (this boot):+ none+Loaded upatches (1):NAME LOCATION MAPS STATUS AGEshirudo-test-basic fentry/do_nanosleep 0 success 1s@@ -336,6 +345,9 @@ system as well:SealWrite 1 write open of a sealed fileSealEntry 2 entry into a sealed directory, or a sealed inode linked+ Integrity attempts (this boot):+ none+Loaded upatches (1):NAME LOCATION MAPS STATUS AGEshirudo-test-basic fentry/do_nanosleep 0 success 1s@@ -408,7 +420,7 @@ Print the keepalive body of the same target, which follows no tree:.. code-block:: consoletarget# shirudo status --keepalive- {"schema":"shirudo.keepalive/1","boot_id":"82639935-1127-4dab-91b5-f818eabc7f13","version_id":"d0d7aa800303439023907d1979d917d46a21bec21f816689c138728a28e84af9","config_root":"6d5ed552f448a1c07e3b9d24f5a86c1e0b7d93f2c4e5a6b7180c9d2e3f4a5b6c","kernel_release":"7.3.0-bpf-next+","image_id":null,"image_version":null,"image_root":null,"verdict":"ok","cond":5461,"flags":0,"tamper":[15,0,0,0,0,1,0,0,0,0,0,8,0,0,0,0,0,1,0,0,1,0,0,0,0,0,7,0,0,2,0,0,0,0,0,0,0,0,0,0,0,0,0],"tree_id":null,"generation":null,"base_seq":null,"last_seq":null,"base_root":null,"projection_root":null,"mask":null,"set_sha256":"5f0c2e8b7a1d4c3f9e6b2a0d8c7f1e3b5a9d4c2e6f8b0a1d3c5e7f9b2d4a6c8e","count":1,"not_ok":0}+ {"schema":"shirudo.keepalive/1","boot_id":"82639935-1127-4dab-91b5-f818eabc7f13","version_id":"d0d7aa800303439023907d1979d917d46a21bec21f816689c138728a28e84af9","config_root":"6d5ed552f448a1c07e3b9d24f5a86c1e0b7d93f2c4e5a6b7180c9d2e3f4a5b6c","kernel_release":"7.3.0-bpf-next+","image_id":null,"image_version":null,"image_root":null,"verdict":"ok","cond":5461,"flags":0,"tamper":[15,0,0,0,0,1,0,0,0,0,0,8,0,0,0,0,0,1,0,0,1,0,0,0,0,0,7,0,0,2,0,0,0,0,0,0,0,0,0,0,0,0],"integrity":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"tree_id":null,"generation":null,"base_seq":null,"last_seq":null,"base_root":null,"projection_root":null,"mask":null,"set_sha256":"5f0c2e8b7a1d4c3f9e6b2a0d8c7f1e3b5a9d4c2e6f8b0a1d3c5e7f9b2d4a6c8e","count":1,"not_ok":0}Add this boot's eventlog to the report:diff --git a/Documentation/reference/files.rst b/Documentation/reference/files.rstindex dc7a6404..be3d0240 100644--- a/Documentation/reference/files.rst+++ b/Documentation/reference/files.rst@@ -362,6 +362,9 @@ by ``BPF_OBJ_GET`` (``ObjGet``). Directories stay listable.* - ``tamper``- Map ``shirudo_tamper``: the tamper counters. See:doc:`/security/tamper-counters`.+ * - ``integrity``+ - Map ``shirudo_integrity``: the integrity counters. See+ :doc:`/security/integrity-counters`.* - ``task_authority``, ``config_roots``- Task storage maps of runtime authority and expected config roots.* - ``task_policy``, ``socket_policy``diff --git a/Documentation/reference/formats/status-json.rst b/Documentation/reference/formats/status-json.rstindex 1a5a1e88..1a391cce 100644--- a/Documentation/reference/formats/status-json.rst+++ b/Documentation/reference/formats/status-json.rst@@ -128,6 +128,11 @@ determined, as noted.- Attempts counted this boot, refused except ``SealSignal``, see`tamper_attempts`_. ``null``until ``init`` has pinned the counters.+ * - ``integrity_attempts``+ - object or ``null``+ - Changes or reads of the running kernel refused this boot, see+ `integrity_attempts`_. ``null`` until ``init`` has pinned the+ counters.* - ``config``- object or ``null``- Config image activation, see `config`_. ``null`` on a host@@ -547,6 +552,14 @@ tamper_attemptsThe counters live in a pinned BPF map under ``/run/shirudo/bpffs`` andstart at zero at every boot.+integrity_attempts+------------------++The same two fields as `tamper_attempts`_, ``total`` and ``counters``,+for the integrity counters, which :doc:`/security/integrity-counters`+lists. They live in their own pinned map and start at zero at every+boot.+config------@@ -732,6 +745,13 @@ Fields to alert on* - ``tamper_attempts``- ``null`` on a target- ``init`` has not pinned the counters this boot.+ * - ``integrity_attempts.total``+ - rises+ - The counter that moved names the refused change of the running+ kernel, :doc:`/security/integrity-counters`.+ * - ``integrity_attempts``+ - ``null`` on a target+ - ``init`` has not pinned the counters this boot.* - ``lsm_attached``- ``false``- Enforcement is off.diff --git a/Documentation/reference/versions.rst b/Documentation/reference/versions.rstindex f3c5ac37..a2c33f9a 100644--- a/Documentation/reference/versions.rst+++ b/Documentation/reference/versions.rst@@ -244,10 +244,10 @@ target on builds of the same commit.* - Initrd binary and runtime image binary- Must be the same build (:doc:`/operate/deploy/boot-integration`).Nothing compares their IDs. The runtime binary reads the identity- map and the tamper counters that the initrd's ``init`` pinned and- refuses maps whose layout differs from its own: a different- identity layout stops every command with ``shirudo: image state:- Protocol error``.+ map and the tamper and integrity counters that the initrd's+ ``init`` pinned and refuses maps whose layout differs from its+ own: a different identity layout stops every command with+ ``shirudo: image state: Protocol error``.* - Operator artifacts on a target of another build- Load when a key the target trusts signed them, the container andsection versions match, and the target kernel accepts the signeddiff --git a/Documentation/security/index.rst b/Documentation/security/index.rstindex f8a7b32c..5cd174b9 100644--- a/Documentation/security/index.rst+++ b/Documentation/security/index.rst@@ -9,8 +9,8 @@ What shirudo protects, against whom, by which mechanism, and where eachmechanism stops. Start with the security model for the short version.The threat model states every assumption, threat, residual risk and gapnot closed yet, with the hooks, counters and tests behind each claim.-The cryptography and tamper counter pages are references, and the last-page says how to report a vulnerability.+The cryptography, tamper counter and integrity counter pages are+references, and the last page says how to report a vulnerability... toctree:::titlesonly:@@ -19,4 +19,5 @@ page says how to report a vulnerability.threat-modelcryptographytamper-counters+ integrity-countersreportingdiff --git a/Documentation/security/integrity-counters.rst b/Documentation/security/integrity-counters.rstnew file mode 100644index 00000000..11c22765--- /dev/null+++ b/Documentation/security/integrity-counters.rst@@ -0,0 +1,162 @@+..+ SPDX-License-Identifier: BSD-2-Clause+ Copyright (c) 2026 Authors of shirudo++:page-type: Reference+:audience: Operators, security reviewers++Integrity counters+==================++The tamper counters count attempts on shirudo's own state. The+integrity counters count attempts on the running kernel: each way root+has to change or read it that ``bpf2`` refuses, what lockdown in+integrity mode refuses, ``/proc/kcore`` and the resume location, has a+counter, and the guard adds one to it when it refuses. The counters+live in the array map ``shirudo_integrity``, which ``init`` creates,+freezes and pins at ``/run/shirudo/bpffs/integrity`` at every boot, so+they count this boot's refusals. No task resets them from userspace;+only the hooks add to them. Threat T6 of the :doc:`threat-model` says+what the guards keep, and T10 why they count.++Counters+--------++The name and the meaning are what ``shirudo status`` prints. Each+counter but ``HibernateLocation`` is a lockdown reason the kernel asks+``lsm/locked_down`` about, refused with ``EPERM`` to every caller,+shirudo's own tasks included.++.. list-table::+ :header-rows: 1+ :widths: 22 33 45++ * - Counter+ - Meaning+ - Reason and condition+ * - ``ModuleSignature``+ - module load without a valid signature+ - ``LOCKDOWN_MODULE_SIGNATURE``: a module whose signature is+ missing or the kernel cannot verify, or one loaded with+ ``MODULE_INIT_IGNORE_MODVERSIONS`` or+ ``MODULE_INIT_IGNORE_VERMAGIC``, on a kernel that does not+ refuse it itself+ * - ``DevMem``+ - ``/dev/mem`` or ``/dev/port``+ - ``LOCKDOWN_DEV_MEM``: an open of one of them+ * - ``EfiTest``+ - EFI runtime services through ``efi_test``+ - ``LOCKDOWN_EFI_TEST``: an open of ``/dev/efi_test``+ * - ``KexecSignature``+ - kexec of a kernel without a valid signature+ - ``LOCKDOWN_KEXEC``. ``lsm/kernel_load_data`` and+ ``lsm/kernel_read_file`` refuse every kexec image before the+ kernel asks, counted as the tamper counter ``Kexec``, so this+ counter does not move.+ * - ``PciAccess``+ - PCI configuration write or BAR mapping+ - ``LOCKDOWN_PCI_ACCESS``: a write of a device's ``config`` or a+ map of its ``resource`` files, ``/proc/bus/pci``+ * - ``IoPort``+ - raw I/O port access+ - ``LOCKDOWN_IOPORT``: ``ioperm(2)`` and ``iopl(2)``+ * - ``Msr``+ - model-specific register write+ - ``LOCKDOWN_MSR``: a write of ``/dev/cpu/*/msr``+ * - ``AcpiTables``+ - ACPI table override or custom method+ - ``LOCKDOWN_ACPI_TABLES``+ * - ``DeviceTree``+ - device tree overlay+ - ``LOCKDOWN_DEVICE_TREE``+ * - ``PcmciaCis``+ - PCMCIA CIS override+ - ``LOCKDOWN_PCMCIA_CIS``+ * - ``Tiocsserial``+ - serial port I/O or IRQ reconfiguration+ - ``LOCKDOWN_TIOCSSERIAL``: ``TIOCSSERIAL`` that changes the port,+ as ``setserial`` makes+ * - ``ModuleParameters``+ - module parameter that sets hardware addresses+ - ``LOCKDOWN_MODULE_PARAMETERS``+ * - ``Mmiotrace``+ - MMIO tracing+ - ``LOCKDOWN_MMIOTRACE``+ * - ``Debugfs``+ - debugfs file that writes or maps+ - ``LOCKDOWN_DEBUGFS``: an open of a debugfs file that can be+ written, mapped or given an ioctl, even for reading+ * - ``XmonWrite``+ - xmon write access+ - ``LOCKDOWN_XMON_WR``, powerpc only+ * - ``BpfWriteUser``+ - BPF program that writes user memory+ - ``LOCKDOWN_BPF_WRITE_USER``: a program that calls+ ``bpf_probe_write_user()``, at its load+ * - ``DbgWriteKernel``+ - kernel debugger write+ - ``LOCKDOWN_DBG_WRITE_KERNEL``+ * - ``RtasErrorInjection``+ - RTAS error injection+ - ``LOCKDOWN_RTAS_ERROR_INJECTION``, powerpc only+ * - ``XenUserActions``+ - Xen user action that writes memory+ - ``LOCKDOWN_XEN_USER_ACTIONS``+ * - ``Kcore``+ - ``/proc/kcore``, the kernel's memory+ - ``LOCKDOWN_KCORE``: an open of ``/proc/kcore``, which integrity+ mode leaves readable+ * - ``HibernateLocation``+ - EFI variable naming a resume device+ - ``lsm/file_open``: an open of a ``HibernateLocation`` variable+ on efivarfs for writing, from which the next boot's initrd would+ resume+ * - ``Other``+ - lockdown reason this build does not name+ - A reason of integrity mode that a later kernel adds++The hibernation check, ``LOCKDOWN_HIBERNATION``, is refused without a+count: every read of ``/sys/power/state`` makes it.++Reading the counters+--------------------++``shirudo status``, started from the runtime image as for the tamper+counters, prints the section ``Integrity attempts (this boot):`` after+``Tamper attempts (this boot):``, with one line per counter that is not+zero: its name, its count and its meaning. It prints ``none`` when+every counter is zero, ``none recorded before init`` before ``init``+has pinned the map, and ``unavailable:`` with the error when the map+cannot be read.++``shirudo status --json`` carries every counter under+``integrity_attempts``, with the sum in ``total`` and each counter by+name in ``counters``, ``null`` before ``init`` has pinned the map.++The keepalive, ``shirudo status --otel``, carries every counter in the+``integrity`` list of its body, after ``tamper``, zeros included and in+the order of this page, and the TPM quotes the body. The list is+``null``, and bit 6 of the body's ``flags`` set, when the counters+cannot be read.++What a non-zero counter means+-----------------------------++A counter that moved means that ``bpf2`` refused a change or a read of+the running kernel this boot: the operation did not happen. It does not+mean that the kernel is compromised, nor that root made the attempt:+honest tools move some counters. ``Debugfs`` moves when a tool opens a+writable debugfs file to read it, ``Tiocsserial`` when ``setserial``+reconfigures a port, and ``ModuleSignature`` on ``modprobe --force``,+which makes a signed module count as unsigned.++A counter does not change the verdict of ``shirudo status``, as a tamper+counter does not. To act on one, see+:doc:`/operate/troubleshoot/incident-tampered`.++Related+-------++- :doc:`tamper-counters` for the attempts on shirudo's own state+- :doc:`threat-model`, threats T6 and T10+- :doc:`/internals/enforcement` for the hooksdiff --git a/Documentation/security/tamper-counters.rst b/Documentation/security/tamper-counters.rstindex 546a7b47..978a3916 100644--- a/Documentation/security/tamper-counters.rst+++ b/Documentation/security/tamper-counters.rst@@ -16,6 +16,8 @@ the array map ``shirudo_tamper``, which ``init`` creates, freezes andpins at ``/run/shirudo/bpffs/tamper`` at every boot, so they count thisboot's refusals. No task resets them from userspace; only the hooks addto them. Threat T10 of the :doc:`threat-model` explains their purpose.+Refusals of changes to the running kernel count apart, as+:doc:`integrity-counters`.Counters--------@@ -258,13 +260,6 @@ counter.without authority, which could have the kernel stop it with``SIGXFSZ`` or ``SIGXCPU``- ``EPERM``- * - ``Lockdown``- - change or read of the running kernel that lockdown refuses- - ``lsm/locked_down``: every reason of integrity mode, an unsigned- module included, but hibernation, refused uncounted, and- ``LOCKDOWN_KCORE``, for every caller; ``lsm/file_open``: a write- open of a ``HibernateLocation`` EFI variable, for every caller- - ``EPERM``Unless the row says every caller, a task with runtime authority isnot refused and moves nothing.@@ -393,5 +388,6 @@ evidence. To act on a counter, seeRelated-------+- :doc:`integrity-counters` for the attempts on the running kernel- :doc:`threat-model`, threat T10, for the purpose and the limits- :doc:`/internals/enforcement` for the hooksdiff --git a/Documentation/security/threat-model.rst b/Documentation/security/threat-model.rstindex 85a33bb2..c58e4afc 100644--- a/Documentation/security/threat-model.rst+++ b/Documentation/security/threat-model.rst@@ -182,7 +182,8 @@ without the protection.replace the running kernel that lockdown in integrity moderefuses, ``/dev/mem``, MSR writes, port I/O, PCI BAR access,debugfs writes and ACPI table overrides, and ``/proc/kcore``,- which that mode leaves readable (``Lockdown``, ``t6154``). The+ which that mode leaves readable (``ModuleSignature`` and the+ other integrity counters, ``t6154``). Thekernel's lockdown LSM is not needed for them, and where it runsit decides first. A kernel without ``CONFIG_MODULE_SIG`` asksnothing and loads any module.@@ -233,7 +234,8 @@ without the protection.swap. ``bpf2`` refuses hibernation once ``init`` runs, and thewrite of a ``HibernateLocation`` EFI variable, through whichsystemd's initrd resumes from a device the running system names- (``Lockdown``). What the authenticated UKI names is left.+ (``HibernateLocation``). What the authenticated UKI names is+ left.The behavior of the register across hibernation is not analyzedhere.- No.@@ -343,6 +345,9 @@ Assets* - Tamper counters- ``shirudo_tamper``, pinned as ``tamper``- Frozen; only the hooks add to it (T10).+ * - Integrity counters+ - ``shirudo_integrity``, pinned as ``integrity``+ - Frozen; only the hooks add to it (T6, T10).* - Payload binding of a pin- The ``security.bpf.shirudo.payload`` xattr on each upatch pindirectory@@ -1105,12 +1110,13 @@ port I/O, PCI resources, debugfs writes and ACPI table overrides changeit, an unsigned module joins it, and ``/proc/kcore`` reads it.``lsm/locked_down`` refuses what lockdown in integrity mode refuses, anunsigned module the kernel asks about included (A4), and-``/proc/kcore`` with it, to every task, whatever the command line says-(``Lockdown``). Hibernation is refused too, but a resume runs in the-initrd before ``init``: ``lsm/file_open`` refuses the write of a-``HibernateLocation`` EFI variable, which would have the next boot's-initrd resume from a device root chose, and A9 keeps the UKI from naming-one.+``/proc/kcore`` with it, to every task, whatever the command line says,+and counts each refusal on the integrity counter of its reason.+Hibernation is refused too, but a resume runs in the initrd before+``init``: ``lsm/file_open`` refuses the write of a ``HibernateLocation``+EFI variable, which would have the next boot's initrd resume from a+device root chose (``HibernateLocation``), and A9 keeps the UKI from+naming one. :doc:`integrity-counters` lists the counters... rst-class:: facts@@ -1120,7 +1126,13 @@ one.:Refusal: ``EPERM`` from ``kexec_load(2)`` and ``kexec_file_load(2)``,from each lockdown check and from the open of a``HibernateLocation`` EFI variable for writing-:Counters: ``Kexec``, ``Lockdown``+:Counters: ``Kexec``; the integrity counters ``ModuleSignature``,+ ``DevMem``, ``EfiTest``, ``KexecSignature``, ``PciAccess``,+ ``IoPort``, ``Msr``, ``AcpiTables``, ``DeviceTree``, ``PcmciaCis``,+ ``Tiocsserial``, ``ModuleParameters``, ``Mmiotrace``, ``Debugfs``,+ ``XmonWrite``, ``BpfWriteUser``, ``DbgWriteKernel``,+ ``RtasErrorInjection``, ``XenUserActions``, ``Kcore``,+ ``HibernateLocation`` and ``Other``:Tests: ``t4003``, ``t4101``, ``t6126``, ``t6154``:Residual: R6, R7, R12, U11, U16@@ -1288,7 +1300,11 @@ a task without authority (``SealSignal``, T3). Only thehooks add to it, and no task resets it from userspace. ``shirudostatus`` lists the counters that are not zero with their meaning,``status --json`` carries them all, and so does the keepalive body,-which the TPM quotes, in its ``tamper`` list.+which the TPM quotes, in its ``tamper`` list. The refusals of changes to+the running kernel (T6) count apart from those of shirudo's own state,+in ``shirudo_integrity``, which ``init`` creates, freezes and pins the+same way; ``status`` reports them in their own section and key, and the+keepalive in its ``integrity`` list.A counter is evidence of an attempt, not of a compromise. Somerefusals move no counter: the kernel's signature errors, the guards of@@ -1296,14 +1312,15 @@ the ``/run/shirudo`` tmpfs and the image mounts, the device-mapper andmapping checks, the seccomp and memory checks, and refusals by anotherLSM ordered before ``bpf``. Zero does not mean that nobody tried.:doc:`tamper-counters` lists every counter, its hooks and the refusals-without one.+without one, and :doc:`integrity-counters` the integrity counters... rst-class:: facts:Adversary: ADV-A and ADV-B-:Enforced at: every hook that counts; :doc:`tamper-counters` lists them+:Enforced at: every hook that counts; :doc:`tamper-counters` and+ :doc:`integrity-counters` list them:Refusal: the refused operation fails and its counter moves-:Counters: all, see :doc:`tamper-counters`+:Counters: all, see :doc:`tamper-counters` and :doc:`integrity-counters`:Tests: ``t6003``, ``t6108``:Residual: R17diff --git a/Documentation/start/quickstart.rst b/Documentation/start/quickstart.rstindex 253f7500..7b6ac2bc 100644--- a/Documentation/start/quickstart.rst+++ b/Documentation/start/quickstart.rst@@ -185,6 +185,9 @@ Check enforcementBpfCommand 8 detach, update, delete or unclassified bpf() commandObjGet 1 pin, map or link opened by another executable+ Integrity attempts (this boot):+ none+Loaded upatches (0):nonediff --git a/Makefile.shirudo b/Makefile.shirudoindex 317ed2ce..1c7c872d 100644--- a/Makefile.shirudo+++ b/Makefile.shirudo@@ -228,6 +228,7 @@ UTIL_SRCS := \util/identity.c \util/nv_writer.c \util/tamper.c \+ util/integrity.c \util/initrd.c \util/paths.c \util/harden.c \diff --git a/bpf/bpf2.c b/bpf/bpf2.cindex ef79c34f..768afbc7 100644--- a/bpf/bpf2.c+++ b/bpf/bpf2.c@@ -509,12 +509,64 @@ int BPF_PROG(shirudo_lsm_kernel_read_file, struct file *file,return shirudo_tamper_deny(TAMPER_KEXEC, -EPERM);}+#define REASON(name) bpf_core_enum_value(enum lockdown_reason, name)++/* The kernel's numbers move between releases; the counters' do not. */+static __always_inline enum integrity_point+integrity_point_of(enum lockdown_reason what)+{+ if (what == REASON(LOCKDOWN_MODULE_SIGNATURE))+ return INTEGRITY_MODULE_SIGNATURE;+ if (what == REASON(LOCKDOWN_DEV_MEM))+ return INTEGRITY_DEV_MEM;+ if (what == REASON(LOCKDOWN_EFI_TEST))+ return INTEGRITY_EFI_TEST;+ if (what == REASON(LOCKDOWN_KEXEC))+ return INTEGRITY_KEXEC;+ if (what == REASON(LOCKDOWN_PCI_ACCESS))+ return INTEGRITY_PCI_ACCESS;+ if (what == REASON(LOCKDOWN_IOPORT))+ return INTEGRITY_IOPORT;+ if (what == REASON(LOCKDOWN_MSR))+ return INTEGRITY_MSR;+ if (what == REASON(LOCKDOWN_ACPI_TABLES))+ return INTEGRITY_ACPI_TABLES;+ if (what == REASON(LOCKDOWN_DEVICE_TREE))+ return INTEGRITY_DEVICE_TREE;+ if (what == REASON(LOCKDOWN_PCMCIA_CIS))+ return INTEGRITY_PCMCIA_CIS;+ if (what == REASON(LOCKDOWN_TIOCSSERIAL))+ return INTEGRITY_TIOCSSERIAL;+ if (what == REASON(LOCKDOWN_MODULE_PARAMETERS))+ return INTEGRITY_MODULE_PARAMETERS;+ if (what == REASON(LOCKDOWN_MMIOTRACE))+ return INTEGRITY_MMIOTRACE;+ if (what == REASON(LOCKDOWN_DEBUGFS))+ return INTEGRITY_DEBUGFS;+ if (what == REASON(LOCKDOWN_XMON_WR))+ return INTEGRITY_XMON_WR;+ if (what == REASON(LOCKDOWN_BPF_WRITE_USER))+ return INTEGRITY_BPF_WRITE_USER;+ if (what == REASON(LOCKDOWN_DBG_WRITE_KERNEL))+ return INTEGRITY_DBG_WRITE_KERNEL;+ if (what == REASON(LOCKDOWN_RTAS_ERROR_INJECTION))+ return INTEGRITY_RTAS_ERROR_INJECTION;+ if (what == REASON(LOCKDOWN_XEN_USER_ACTIONS))+ return INTEGRITY_XEN_USER_ACTIONS;+ if (what == REASON(LOCKDOWN_KCORE))+ return INTEGRITY_KCORE;+ return INTEGRITY_OTHER;+}++#undef REASON+/** Lockdown in integrity mode, the ways root has to change the running* kernel, from an unsigned module and /dev/mem to debugfs writes, and* /proc/kcore, which that mode leaves readable, whether or not the* command line asks for lockdown: the kernel's own lockdown LSM decides- * first where it runs. The hibernation check, which every read of+ * first where it runs. Each refusal counts on the integrity counter of+ * its reason. The hibernation check, which every read of* /sys/power/state makes, is refused without a count.*/SEC("lsm/locked_down")@@ -529,7 +581,7 @@ int BPF_PROG(shirudo_lsm_locked_down, enum lockdown_reason what, int ret)(what > LOCKDOWN_NONE &&what < bpf_core_enum_value(enum lockdown_reason,LOCKDOWN_INTEGRITY_MAX)))- return shirudo_tamper_deny(TAMPER_LOCKDOWN, -EPERM);+ return shirudo_integrity_deny(integrity_point_of(what), -EPERM);return 0;}@@ -822,7 +874,8 @@ int BPF_PROG(shirudo_lsm_file_open, struct file *file, int ret)if (ret)return ret;if (hibernate_location(file))- return shirudo_tamper_deny(TAMPER_LOCKDOWN, -EPERM);+ return shirudo_integrity_deny(INTEGRITY_HIBERNATE_LOCATION,+ -EPERM);if (!id)return 0;mnt = BPF_CORE_READ(file, f_path.mnt);diff --git a/bpf/lib/integrity.h b/bpf/lib/integrity.hnew file mode 100644index 00000000..47fe8700--- /dev/null+++ b/bpf/lib/integrity.h@@ -0,0 +1,61 @@+/* SPDX-License-Identifier: GPL-2.0 OR BSD-2-Clause */+/*+ * Copyright (c) 2026 Authors of shirudo+ *+ * The integrity counters: refusals of the ways to change or read the+ * running kernel, apart from the tamper counters of shirudo's own state.+ */+#ifndef SHIRUDO_INTEGRITY_H+#define SHIRUDO_INTEGRITY_H++/*+ * A counter's position is its identity in the keepalive and to every+ * backend that reads it: append only, never between two.+ */+enum integrity_point {+ INTEGRITY_MODULE_SIGNATURE,+ INTEGRITY_DEV_MEM,+ INTEGRITY_EFI_TEST,+ INTEGRITY_KEXEC,+ INTEGRITY_PCI_ACCESS,+ INTEGRITY_IOPORT,+ INTEGRITY_MSR,+ INTEGRITY_ACPI_TABLES,+ INTEGRITY_DEVICE_TREE,+ INTEGRITY_PCMCIA_CIS,+ INTEGRITY_TIOCSSERIAL,+ INTEGRITY_MODULE_PARAMETERS,+ INTEGRITY_MMIOTRACE,+ INTEGRITY_DEBUGFS,+ INTEGRITY_XMON_WR,+ INTEGRITY_BPF_WRITE_USER,+ INTEGRITY_DBG_WRITE_KERNEL,+ INTEGRITY_RTAS_ERROR_INJECTION,+ INTEGRITY_XEN_USER_ACTIONS,+ INTEGRITY_KCORE,+ INTEGRITY_HIBERNATE_LOCATION,+ INTEGRITY_OTHER,+ INTEGRITY_MAX+};++#ifdef __BPF__+struct {+ __uint(type, BPF_MAP_TYPE_ARRAY);+ __uint(max_entries, INTEGRITY_MAX);+ __type(key, __u32);+ __type(value, __u64);+} shirudo_integrity SEC(".maps");++static __always_inline int shirudo_integrity_deny(enum integrity_point point,+ int err)+{+ __u32 key = point;+ __u64 *count;++ count = bpf_map_lookup_elem(&shirudo_integrity, &key);+ if (count)+ __sync_fetch_and_add(count, 1);+ return err;+}+#endif /* __BPF__ */+#endif /* SHIRUDO_INTEGRITY_H */diff --git a/bpf/lib/lsm.h b/bpf/lib/lsm.hindex 12a7841b..b7716cc2 100644--- a/bpf/lib/lsm.h+++ b/bpf/lib/lsm.h@@ -30,6 +30,7 @@#include <shirudo/enforcement.h>#include "identity.h"+#include "integrity.h"#include "policy.h"#include "tamper.h"diff --git a/bpf/lib/tamper.h b/bpf/lib/tamper.hindex d0688f7a..f0b3dcf7 100644--- a/bpf/lib/tamper.h+++ b/bpf/lib/tamper.h@@ -53,7 +53,6 @@ enum tamper_point {TAMPER_SEAL_UPROBE,TAMPER_EXEC_SHARED,TAMPER_XATTR_HANDLE,- TAMPER_LOCKDOWN,TAMPER_SEAL_RLIMIT,TAMPER_MAX};diff --git a/builtin-init.c b/builtin-init.cindex 32340bed..b05b18e7 100644--- a/builtin-init.c+++ b/builtin-init.c@@ -629,6 +629,11 @@ static int init_lsm(void)strerror(errno));return -errno;}+ if (unlink(INTEGRITY_PIN) != 0 && errno != ENOENT) {+ pr_err("unlink stale %s: %s", INTEGRITY_PIN,+ strerror(errno));+ return -errno;+ }if (!blob || !blob->data || !blob->size) {pr_err("embedded bpf2 blob missing");@@ -889,6 +894,7 @@ out:bpf_link__unpin(links[i]);unlink(IDENTITY_PIN);unlink(TAMPER_PIN);+ unlink(INTEGRITY_PIN);unlink(BPFFS_DIR "/task_authority");unlink(POLICY_PIN);unlink(SOCKET_POLICY_PIN);diff --git a/builtin-status.c b/builtin-status.cindex b498537a..5b582259 100644--- a/builtin-status.c+++ b/builtin-status.c@@ -51,6 +51,7 @@#include "util/malloc.h"#include "util/paths.h"#include "util/initrd.h"+#include "util/integrity.h"#include "util/format.h"#include "util/sysinfo.h"#include "util/timefmt.h"@@ -286,6 +287,25 @@ static void print_eventlog_table(void)xfree(buf, len + 1);}+static void print_counters(int rc, __u64 total, const __u64 *count,+ __u32 n, const char *(*name)(__u32),+ const char *(*meaning)(__u32))+{+ __u32 i;++ if (rc == -ENOENT)+ printf(" none recorded before init\n");+ else if (rc)+ printf(" unavailable: %s\n", strerror(-rc));+ else if (total == 0)+ printf(" none\n");+ for (i = 0; rc == 0 && i < n; i++) {+ if (count[i])+ printf(" %-20s %6llu %s\n", name(i),+ (__u64)count[i], meaning(i));+ }+}+static void print_system_human(const struct sysinfo *si){printf("\nSystem:\n");@@ -618,7 +638,16 @@ static const struct keepalive_snapshot_ops keepalive_ops = {.collect = keepalive_collect,};-static __u32 keepalive_flags(const struct chain_status *cst, int tamper_rc,+/* What the guards counted this boot, and each set's read error. */+struct guard_counts {+ struct tamper_counts tamper;+ struct integrity_counts integrity;+ int tamper_rc;+ int integrity_rc;+};++static __u32 keepalive_flags(const struct chain_status *cst,+ const struct guard_counts *counts,const struct keepalive_view *v, int state_rc){__u32 flags = 0;@@ -629,8 +658,10 @@ static __u32 keepalive_flags(const struct chain_status *cst, int tamper_rc,flags |= KEEPALIVE_BOUND_LATE;if (v->log_mismatch || (!state_rc && v->outcomes_rc))flags |= KEEPALIVE_TREE_LOG_MISMATCH;- if (tamper_rc)+ if (counts->tamper_rc)flags |= KEEPALIVE_TAMPER_UNAVAILABLE;+ if (counts->integrity_rc)+ flags |= KEEPALIVE_INTEGRITY_UNAVAILABLE;return flags;}@@ -638,7 +669,7 @@ static __u32 keepalive_flags(const struct chain_status *cst, int tamper_rc,static noinline_for_stack intkeepalive_body(const struct conditions_input *cin,const struct chain_status *cst,- const struct tamper_counts *tamper, int tamper_rc,+ const struct guard_counts *counts,const char *config_root_hex, char body[KEEPALIVE_BODY_MAX],size_t *len){@@ -671,9 +702,12 @@ keepalive_body(const struct conditions_input *cin,.image_root = img.root,.verdict = status_verdict(cin),.cond = keepalive_cond(conds, nc),- .flags = flags | keepalive_flags(cst, tamper_rc,+ .flags = flags | keepalive_flags(cst, counts,&v, state_rc),- .tamper = tamper_rc ? NULL : tamper->count,+ .tamper = counts->tamper_rc ? NULL :+ counts->tamper.count,+ .integrity = counts->integrity_rc ? NULL :+ counts->integrity.count,.set_sha256 = v.set_sha256,.count = v.count,.not_ok = v.not_ok,@@ -726,14 +760,13 @@ static int send_keepalive(const struct otel_opts *opts, const char *verdict,static noinline_for_stack intstatus_keepalive(const struct conditions_input *cin,const struct chain_status *cst,- const struct tamper_counts *tamper, int tamper_rc,+ const struct guard_counts *counts,const char *config_root_hex, const struct otel_opts *opts){char body[KEEPALIVE_BODY_MAX];size_t len;- if (keepalive_body(cin, cst, tamper, tamper_rc, config_root_hex, body,- &len))+ if (keepalive_body(cin, cst, counts, config_root_hex, body, &len))return 1;if (!opts) {printf("%s\n", body);@@ -1107,9 +1140,11 @@ int cmd_status(int argc, const char **argv)struct config otel_cfg __cleanup(config_clear) = {};struct otel_opts otel_opts = {};struct asset_view assets;- struct tamper_counts tamper = {};+ struct guard_counts counts = {+ .tamper_rc = -ENOENT,+ .integrity_rc = -ENOENT,+ };struct conditions_input cin;- int tamper_rc = -ENOENT;struct dirent **ups = NULL;char pcr_before_hex[2 * CHAIN_DIGEST_LEN + 1] = "";char phase_before_hex[2 * CHAIN_DIGEST_LEN + 1] = "";@@ -1274,7 +1309,8 @@ int cmd_status(int argc, const char **argv)eventlog_unlock(lock);gather_assets(&assets);- tamper_rc = tamper_read(&tamper);+ counts.tamper_rc = tamper_read(&counts.tamper);+ counts.integrity_rc = integrity_read(&counts.integrity);config_state = image_config_state(config_root);if (config_state != -ENODEV)hex_encode(config_root, sizeof(config_root), config_root_hex);@@ -1345,7 +1381,7 @@ int cmd_status(int argc, const char **argv)keyring_cond_input(&cin, &bpf, &dmv);if (keepalive || (otel && otel_endpoint_configured))- ret = status_keepalive(&cin, &cst, &tamper, tamper_rc,+ ret = status_keepalive(&cin, &cst, &counts,config_state ? NULL : config_root_hex,otel ? &otel_opts : NULL);if (otel && !otel_endpoint_configured && config_state &&@@ -1481,18 +1517,31 @@ int cmd_status(int argc, const char **argv)* so a collector's keys stay the same from one record to* the next; null until init has pinned the map.*/- if (tamper_rc == 0) {+ if (counts.tamper_rc == 0) {json_obj_open_key(&e, "tamper_attempts");- json_kv_int(&e, "total", (__s64)tamper.total);+ json_kv_int(&e, "total", (__s64)counts.tamper.total);json_obj_open_key(&e, "counters");for (i = 0; i < TAMPER_MAX; i++)json_kv_int(&e, tamper_name(i),- (__s64)tamper.count[i]);+ (__s64)counts.tamper.count[i]);json_obj_close(&e);json_obj_close(&e);} else {json_kv_null(&e, "tamper_attempts");}+ if (counts.integrity_rc == 0) {+ json_obj_open_key(&e, "integrity_attempts");+ json_kv_int(&e, "total",+ (__s64)counts.integrity.total);+ json_obj_open_key(&e, "counters");+ for (i = 0; i < INTEGRITY_MAX; i++)+ json_kv_int(&e, integrity_name(i),+ (__s64)counts.integrity.count[i]);+ json_obj_close(&e);+ json_obj_close(&e);+ } else {+ json_kv_null(&e, "integrity_attempts");+ }if (config_state != -ENODEV) {json_obj_open_key(&e, "config");json_kv_string(&e, "root_hash", config_root_hex);@@ -1612,19 +1661,13 @@ int cmd_status(int argc, const char **argv)printf("\n");conditions_print(conds, nc);printf("\nTamper attempts (this boot):\n");- if (tamper_rc == -ENOENT)- printf(" none recorded before init\n");- else if (tamper_rc)- printf(" unavailable: %s\n", strerror(-tamper_rc));- else if (tamper.total == 0)- printf(" none\n");- for (i = 0; tamper_rc == 0 && i < TAMPER_MAX; i++) {- if (tamper.count[i])- printf(" %-20s %6llu %s\n",- tamper_name(i),- (__u64)tamper.count[i],- tamper_meaning(i));- }+ print_counters(counts.tamper_rc, counts.tamper.total,+ counts.tamper.count, TAMPER_MAX, tamper_name,+ tamper_meaning);+ printf("\nIntegrity attempts (this boot):\n");+ print_counters(counts.integrity_rc, counts.integrity.total,+ counts.integrity.count, INTEGRITY_MAX,+ integrity_name, integrity_meaning);upatch_table_print(rows, n_rows);xfree(rows, n_rows * sizeof(*rows));rows = NULL;diff --git a/testing/ci-checks/t0008-check-docs.sh b/testing/ci-checks/t0008-check-docs.shindex c9955821..b59140ec 100755--- a/testing/ci-checks/t0008-check-docs.sh+++ b/testing/ci-checks/t0008-check-docs.sh@@ -37,6 +37,8 @@ good() {put tools/gen-initrd/gen '#!/bin/sh' &&put util/tamper.c 'static const struct point points[] = {' \' [0] = { "Good", 1 },' '};' &&+ put util/integrity.c 'static const struct point points[] = {' \+ ' [0] = { "Kept", 1 },' '};' &&put util/read.c 'int read_one;' &&put util/chained.c 'int chained;' &&put util/unread.c 'int unread;' &&@@ -50,10 +52,11 @@ good() {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 Documentation/security/integrity-counters.rst '``Kept``' &&put "$TM" ':Enforced at: ``lsm/file_open``,' \' ``lsm.s/inode_setattr``' \':Counters: none for a first attempt,' \- ' ``Good``' \+ ' ``Good``, ``Kept``' \':Tests: ``t1001``' \':Proofs: ``first``,' \' ``second``' &&@@ -62,7 +65,8 @@ good() {'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`' '' \+ ' :src:`util/integrity.c`, :src:`util/tamper.c`,' \+ ' :src:`util/unread.c`' '' \'Not covered yet' '---------------'}@@ -88,11 +92,18 @@ test_expect_success 'a hook on a continuation line is checked, by its section' '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" &&+ refuses "no counter is named Goodx" &&good && sed -i "s|\`\`second\`\`|\`\`secondx\`\`|" "$R/$TM" &&refuses "no proof is named secondx"'+test_expect_success 'an integrity counter needs its entry and a fact box' '+ good && put Documentation/security/integrity-counters.rst "none" &&+ refuses "no entry for the counter Kept" &&+ good && sed -i "s|, \`\`Kept\`\`||" "$R/$TM" &&+ refuses "no threat names the counter Kept"+'+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\")" &&diff --git a/testing/fixtures/keepalive/node-a-1.0.0.json b/testing/fixtures/keepalive/node-a-1.0.0.jsonindex c27c8b3d..55d9b479 100644--- a/testing/fixtures/keepalive/node-a-1.0.0.json+++ b/testing/fixtures/keepalive/node-a-1.0.0.json@@ -1 +1 @@-{"schema":"shirudo.keepalive/1","boot_id":"168d20a1-5011-4e1b-9924-d8b73c85aa4e","version_id":"d6d918ad22ff597579e6678bef75adca84d30f9661e0b7bbdbf534eebc138c1f","config_root":"1d8465c5b17838303fee92b3905420d294d2c22c576a0bdef0f69f190ed22807","kernel_release":"7.4.2","image_id":"fleet-os","image_version":"2026.11.1","image_root":"a3c3f1b0e4c2d7f09e3b6b2a8b1d5e7c4f6a9d0b2c8e1f3a5b7d9c0e2f4a6b8c","verdict":"ok","cond":5461,"flags":0,"tamper":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"tree_id":"fleet-base","generation":1,"base_seq":0,"last_seq":1,"base_root":"0000000000000000000000000000000000000000000000000000000000000000","projection_root":"04f83540c1727aefcf3c53449a99594c8fd1cc15e1466dbdbf3168cc8f9dc136","mask":"QA==","set_sha256":"6c9e113d02cd14646f617d7bba4a092b91bc3802dfdaae50e2fef7a01e0580aa","count":1,"not_ok":0}\ No newline at end of file+{"schema":"shirudo.keepalive/1","boot_id":"168d20a1-5011-4e1b-9924-d8b73c85aa4e","version_id":"d6d918ad22ff597579e6678bef75adca84d30f9661e0b7bbdbf534eebc138c1f","config_root":"1d8465c5b17838303fee92b3905420d294d2c22c576a0bdef0f69f190ed22807","kernel_release":"7.4.2","image_id":"fleet-os","image_version":"2026.11.1","image_root":"a3c3f1b0e4c2d7f09e3b6b2a8b1d5e7c4f6a9d0b2c8e1f3a5b7d9c0e2f4a6b8c","verdict":"ok","cond":5461,"flags":0,"tamper":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"integrity":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"tree_id":"fleet-base","generation":1,"base_seq":0,"last_seq":1,"base_root":"0000000000000000000000000000000000000000000000000000000000000000","projection_root":"04f83540c1727aefcf3c53449a99594c8fd1cc15e1466dbdbf3168cc8f9dc136","mask":"QA==","set_sha256":"6c9e113d02cd14646f617d7bba4a092b91bc3802dfdaae50e2fef7a01e0580aa","count":1,"not_ok":0}\ No newline at end of filediff --git a/testing/fixtures/keepalive/node-a-1.1.0.json b/testing/fixtures/keepalive/node-a-1.1.0.jsonindex 7e6be6df..2356f2af 100644--- a/testing/fixtures/keepalive/node-a-1.1.0.json+++ b/testing/fixtures/keepalive/node-a-1.1.0.json@@ -1 +1 @@-{"schema":"shirudo.keepalive/1","boot_id":"168d20a1-5011-4e1b-9924-d8b73c85aa4e","version_id":"d6d918ad22ff597579e6678bef75adca84d30f9661e0b7bbdbf534eebc138c1f","config_root":"1d8465c5b17838303fee92b3905420d294d2c22c576a0bdef0f69f190ed22807","kernel_release":"7.4.2","image_id":"fleet-os","image_version":"2026.11.1","image_root":"a3c3f1b0e4c2d7f09e3b6b2a8b1d5e7c4f6a9d0b2c8e1f3a5b7d9c0e2f4a6b8c","verdict":"ok","cond":5461,"flags":0,"tamper":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"tree_id":"fleet-base","generation":3,"base_seq":0,"last_seq":3,"base_root":"0000000000000000000000000000000000000000000000000000000000000000","projection_root":"154522480ff8884daa95589e80f26f20248bbf9c192dfbb3cee04e03b4f136a1","mask":"VA==","set_sha256":"74e5bd2c665109f6d8f926af5476c266ad70ab07293ff13b1a13d0b89aa5c1bf","count":1,"not_ok":0}\ No newline at end of file+{"schema":"shirudo.keepalive/1","boot_id":"168d20a1-5011-4e1b-9924-d8b73c85aa4e","version_id":"d6d918ad22ff597579e6678bef75adca84d30f9661e0b7bbdbf534eebc138c1f","config_root":"1d8465c5b17838303fee92b3905420d294d2c22c576a0bdef0f69f190ed22807","kernel_release":"7.4.2","image_id":"fleet-os","image_version":"2026.11.1","image_root":"a3c3f1b0e4c2d7f09e3b6b2a8b1d5e7c4f6a9d0b2c8e1f3a5b7d9c0e2f4a6b8c","verdict":"ok","cond":5461,"flags":0,"tamper":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"integrity":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"tree_id":"fleet-base","generation":3,"base_seq":0,"last_seq":3,"base_root":"0000000000000000000000000000000000000000000000000000000000000000","projection_root":"154522480ff8884daa95589e80f26f20248bbf9c192dfbb3cee04e03b4f136a1","mask":"VA==","set_sha256":"74e5bd2c665109f6d8f926af5476c266ad70ab07293ff13b1a13d0b89aa5c1bf","count":1,"not_ok":0}\ No newline at end of filediff --git a/testing/fixtures/keepalive/node-b-1.0.0.json b/testing/fixtures/keepalive/node-b-1.0.0.jsonindex aca50f27..030815a1 100644--- a/testing/fixtures/keepalive/node-b-1.0.0.json+++ b/testing/fixtures/keepalive/node-b-1.0.0.json@@ -1 +1 @@-{"schema":"shirudo.keepalive/1","boot_id":"9a6f14ea-0cc2-45e1-8e23-7b887120cf54","version_id":"d6d918ad22ff597579e6678bef75adca84d30f9661e0b7bbdbf534eebc138c1f","config_root":"ff2cbeff5d0e9c41a7b36f28d14ce09b73a5182e6fc40d97b5e2a1683c0f7ff8","kernel_release":"7.4.2","image_id":"fleet-os","image_version":"2026.11.1","image_root":null,"verdict":"ok","cond":5461,"flags":0,"tamper":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"tree_id":"fleet-base","generation":1,"base_seq":0,"last_seq":1,"base_root":"0000000000000000000000000000000000000000000000000000000000000000","projection_root":"0000000000000000000000000000000000000000000000000000000000000000","mask":"gA==","set_sha256":"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855","count":0,"not_ok":0}\ No newline at end of file+{"schema":"shirudo.keepalive/1","boot_id":"9a6f14ea-0cc2-45e1-8e23-7b887120cf54","version_id":"d6d918ad22ff597579e6678bef75adca84d30f9661e0b7bbdbf534eebc138c1f","config_root":"ff2cbeff5d0e9c41a7b36f28d14ce09b73a5182e6fc40d97b5e2a1683c0f7ff8","kernel_release":"7.4.2","image_id":"fleet-os","image_version":"2026.11.1","image_root":null,"verdict":"ok","cond":5461,"flags":0,"tamper":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"integrity":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"tree_id":"fleet-base","generation":1,"base_seq":0,"last_seq":1,"base_root":"0000000000000000000000000000000000000000000000000000000000000000","projection_root":"0000000000000000000000000000000000000000000000000000000000000000","mask":"gA==","set_sha256":"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855","count":0,"not_ok":0}\ No newline at end of filediff --git a/testing/fixtures/keepalive/node-b-1.1.0.json b/testing/fixtures/keepalive/node-b-1.1.0.jsonindex 24ce8552..a6c8b52a 100644--- a/testing/fixtures/keepalive/node-b-1.1.0.json+++ b/testing/fixtures/keepalive/node-b-1.1.0.json@@ -1 +1 @@-{"schema":"shirudo.keepalive/1","boot_id":"9a6f14ea-0cc2-45e1-8e23-7b887120cf54","version_id":"d6d918ad22ff597579e6678bef75adca84d30f9661e0b7bbdbf534eebc138c1f","config_root":"ff2cbeff5d0e9c41a7b36f28d14ce09b73a5182e6fc40d97b5e2a1683c0f7ff8","kernel_release":"7.4.2","image_id":"fleet-os","image_version":"2026.11.1","image_root":null,"verdict":"ok","cond":5461,"flags":0,"tamper":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"tree_id":"fleet-base","generation":3,"base_seq":0,"last_seq":3,"base_root":"0000000000000000000000000000000000000000000000000000000000000000","projection_root":"0000000000000000000000000000000000000000000000000000000000000000","mask":"qA==","set_sha256":"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855","count":0,"not_ok":0}\ No newline at end of file+{"schema":"shirudo.keepalive/1","boot_id":"9a6f14ea-0cc2-45e1-8e23-7b887120cf54","version_id":"d6d918ad22ff597579e6678bef75adca84d30f9661e0b7bbdbf534eebc138c1f","config_root":"ff2cbeff5d0e9c41a7b36f28d14ce09b73a5182e6fc40d97b5e2a1683c0f7ff8","kernel_release":"7.4.2","image_id":"fleet-os","image_version":"2026.11.1","image_root":null,"verdict":"ok","cond":5461,"flags":0,"tamper":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"integrity":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"tree_id":"fleet-base","generation":3,"base_seq":0,"last_seq":3,"base_root":"0000000000000000000000000000000000000000000000000000000000000000","projection_root":"0000000000000000000000000000000000000000000000000000000000000000","mask":"qA==","set_sha256":"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855","count":0,"not_ok":0}\ No newline at end of filediff --git a/testing/fixtures/keepalive/ops-16.json b/testing/fixtures/keepalive/ops-16.jsonindex bb5e6ef8..9209c584 100644--- a/testing/fixtures/keepalive/ops-16.json+++ b/testing/fixtures/keepalive/ops-16.json@@ -1 +1 @@-{"schema":"shirudo.keepalive/1","boot_id":"d5140906-4eab-4983-a62c-29e49d449ea3","version_id":"d6d918ad22ff597579e6678bef75adca84d30f9661e0b7bbdbf534eebc138c1f","config_root":"1fbdff17ad8d50404772901df54d5aa2c698eddbb413e286fc654f80931c688a","kernel_release":"7.4.0-shirudo","image_id":"fleet-os","image_version":"2026.11.1","image_root":"a3c3f1b0e4c2d7f09e3b6b2a8b1d5e7c4f6a9d0b2c8e1f3a5b7d9c0e2f4a6b8c","verdict":"ok","cond":5461,"flags":0,"tamper":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"tree_id":"fleet-base","generation":42,"base_seq":0,"last_seq":12,"base_root":"0000000000000000000000000000000000000000000000000000000000000000","projection_root":"f59301708fc8e150c5d2abb1009b4f13fc0dcc1304b708f77dc14b1541679e28","mask":"WdlZAA==","set_sha256":"ac1af1d44b5c1fe3f616384db421138aa4d296595797b5864908a89276e17e6d","count":7,"not_ok":0}\ No newline at end of file+{"schema":"shirudo.keepalive/1","boot_id":"d5140906-4eab-4983-a62c-29e49d449ea3","version_id":"d6d918ad22ff597579e6678bef75adca84d30f9661e0b7bbdbf534eebc138c1f","config_root":"1fbdff17ad8d50404772901df54d5aa2c698eddbb413e286fc654f80931c688a","kernel_release":"7.4.0-shirudo","image_id":"fleet-os","image_version":"2026.11.1","image_root":"a3c3f1b0e4c2d7f09e3b6b2a8b1d5e7c4f6a9d0b2c8e1f3a5b7d9c0e2f4a6b8c","verdict":"ok","cond":5461,"flags":0,"tamper":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"integrity":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"tree_id":"fleet-base","generation":42,"base_seq":0,"last_seq":12,"base_root":"0000000000000000000000000000000000000000000000000000000000000000","projection_root":"f59301708fc8e150c5d2abb1009b4f13fc0dcc1304b708f77dc14b1541679e28","mask":"WdlZAA==","set_sha256":"ac1af1d44b5c1fe3f616384db421138aa4d296595797b5864908a89276e17e6d","count":7,"not_ok":0}\ No newline at end of filediff --git a/testing/fixtures/keepalive/quotes.tsv b/testing/fixtures/keepalive/quotes.tsvindex 066d53e6..263883cb 100644--- a/testing/fixtures/keepalive/quotes.tsv+++ b/testing/fixtures/keepalive/quotes.tsv@@ -1,4 +1,4 @@-node-a-1.0.0.json /1RDR4AYACIACxNJbfFIbCzNEVI4hr7MwUEl2i/dk2o14cQnfgA11ZJiACClpyPhqCULTp7znABpnqXOsUGVgsw+AzUrr/mbPZVxxQAAAAAAAAAJAAAAAAAAAAABIBkQIwAWNjYAAAABAAsDAAAAACDjsMRCmPwcFJr79MiZb7kkJ65B5GSbk0yklZkbeFK4VQ== ABgACwAgmlgt0HOBFHdOE1O8XsEor2yjIjj5bq74a8NeIRpuujMAIKM4n+odypRP6CAoKTSLGp2xk9y2koqwauqR9fuZ0n4v ACMACwAFAHIAAAAQABgACwADABAAIAB0eTd0WyLf8saUGUqdVbbi8+dRaGLQHYwB7tOxf/TFACAzdeo6El8az+BGQowcDXmiLbZxNGeyYWv1lRtuXTuvEg== a5a723e1a8250b4e9ef39c00699ea5ceb1419582cc3e03352baff99b3d9571c5-node-a-1.1.0.json /1RDR4AYACIACxNJbfFIbCzNEVI4hr7MwUEl2i/dk2o14cQnfgA11ZJiACAVyBxfaY9/t3NO8neIGvgExVQnkt1HHUqf1hvuRBvaYgAAAAAAAAAbAAAAAAAAAAABIBkQIwAWNjYAAAABAAsDAAAAACDjsMRCmPwcFJr79MiZb7kkJ65B5GSbk0yklZkbeFK4VQ== ABgACwAgepyM0Gp9nljLdTTCMl4ipUVcMQ6NUKiZq4Vr253dGzcAIBM5wF2mqt1YqA6pk5Jd49Fwnl5yhFH125Oxo+xyaBCF ACMACwAFAHIAAAAQABgACwADABAAIAB0eTd0WyLf8saUGUqdVbbi8+dRaGLQHYwB7tOxf/TFACAzdeo6El8az+BGQowcDXmiLbZxNGeyYWv1lRtuXTuvEg== 15c81c5f698f7fb7734ef277881af804c5542792dd471d4a9fd61bee441bda62-node-b-1.0.0.json /1RDR4AYACIAC0uSx5ABSfNXIGebbaY8HpgpjnZdmiUGoDOMSLFbyFNVACBGpG64qfutWE2Ya4QJ+wVtoClds0UXHnWbB6OZqcVtfAAAAAAAAAAJAAAAAAAAAAABIBkQIwAWNjYAAAABAAsDAAAAACDjsMRCmPwcFJr79MiZb7kkJ65B5GSbk0yklZkbeFK4VQ== ABgACwAgwoeZG/DOwdM3N/dbOKjIyYLefUcZqVORWKlPZPldt48AIIXAyYHWjeHkbQOBZ5g+KaMoPS/j7AnRaM2EtQqYb1Dd ACMACwAFAHIAAAAQABgACwADABAAIGBI6SBUTMr4QsNzP2P3XZGifD6Iz6ueQRTOlU08ZtXyACBOOmUl0mrqCMlUF7EN+0AxeO5ynxm9gHnunTpRWWSLIg== 46a46eb8a9fbad584d986b8409fb056da0295db345171e759b07a399a9c56d7c-node-b-1.1.0.json /1RDR4AYACIAC0uSx5ABSfNXIGebbaY8HpgpjnZdmiUGoDOMSLFbyFNVACALvQW8P8t/OcFSDoK956JiA7rvICZ6MqNDONOqueXtVgAAAAAAAAAaAAAAAAAAAAABIBkQIwAWNjYAAAABAAsDAAAAACDjsMRCmPwcFJr79MiZb7kkJ65B5GSbk0yklZkbeFK4VQ== ABgACwAgIB1R21P0AU+7BdGJONnLmpzAoo5MlnldmiwpAKdj/cYAIBQ8YA2P58uoICyX/FEl4GMh4/Xo256ojqfOQGfSBAys ACMACwAFAHIAAAAQABgACwADABAAIGBI6SBUTMr4QsNzP2P3XZGifD6Iz6ueQRTOlU08ZtXyACBOOmUl0mrqCMlUF7EN+0AxeO5ynxm9gHnunTpRWWSLIg== 0bbd05bc3fcb7f39c1520e82bde7a26203baef20267a32a34338d3aab9e5ed56+node-a-1.0.0.json /1RDR4AYACIACzzRy0Vu4QrA2QYIAEG+suvM8y0yKdNz0mEYxxwsV7JhACBGoxowhIt2CnR3mlHNkt5dMhw/XJ9hQDbR+/zFux3/mwAAAAAAAAAIAAAAAAAAAAABIBkQIwAWNjYAAAABAAsDAAAAACDjsMRCmPwcFJr79MiZb7kkJ65B5GSbk0yklZkbeFK4VQ== ABgACwAgOsqFz+hIGty6pVF+/6bcAEeU/BgyqkKCdQuZwTRPMVoAIOQbyQfNRFynftUoFq3mdmn8p8uoC8XhTXsZX8BKcjYr ACMACwAFAHIAAAAQABgACwADABAAIIX85Uj/SFzk5dE+P7jISlhFEgTkQgD5WJOhOb8ayvhXACBzopZ76SQHVgqnhP8tiHB6O+rzISw+/6k3eeDT/UtQNA== 46a31a30848b760a74779a51cd92de5d321c3f5c9f614036d1fbfcc5bb1dff9b+node-a-1.1.0.json /1RDR4AYACIACzzRy0Vu4QrA2QYIAEG+suvM8y0yKdNz0mEYxxwsV7JhACB+8a36vsajTkF6VdKZ4rIDChYu23UCWpNELCY1TDaMIgAAAAAAAAAbAAAAAAAAAAABIBkQIwAWNjYAAAABAAsDAAAAACDjsMRCmPwcFJr79MiZb7kkJ65B5GSbk0yklZkbeFK4VQ== ABgACwAgENqr3I8/b72G/uLE46oL9Vd6fp12xo/T3IZYnPp88NkAIAqDLfPPAiS9JnBrPDwzXSP48cfQxRmxvC+vmE0IE6Dg ACMACwAFAHIAAAAQABgACwADABAAIIX85Uj/SFzk5dE+P7jISlhFEgTkQgD5WJOhOb8ayvhXACBzopZ76SQHVgqnhP8tiHB6O+rzISw+/6k3eeDT/UtQNA== 7ef1adfabec6a34e417a55d299e2b2030a162edb75025a93442c26354c368c22+node-b-1.0.0.json /1RDR4AYACIACzITVKDjpRV7SpQyL9Joyb8851Q9c6JkQYxGUaHW91SUACBl4pR+5PV9v2gAwwTPQiNCXCFFaNE6/qHwLQGjgtpZ6AAAAAAAAAAJAAAAAAAAAAABIBkQIwAWNjYAAAABAAsDAAAAACDjsMRCmPwcFJr79MiZb7kkJ65B5GSbk0yklZkbeFK4VQ== ABgACwAgy354AaCHOAs/ej7UQE+mzJprxHzfFU558ny3FFILeBoAINegZjzzEqwJlNDJHJvuaaQ5c5gIZS7Eins/k9aPjnoj ACMACwAFAHIAAAAQABgACwADABAAIHWuL1VjHRbjt8bd2H9s/Rn8iEB7E/DZyW6DPuebgp5HACCx9U/+/I/55mBuc4Sh5bhT8uVKrFv3qiW+GmLY1dDliA== 65e2947ee4f57dbf6800c304cf4223425c214568d13afea1f02d01a382da59e8+node-b-1.1.0.json /1RDR4AYACIACzITVKDjpRV7SpQyL9Joyb8851Q9c6JkQYxGUaHW91SUACDyFnDjslblAbFweN/6U8fHEItWTr1VE6gDPlP2EjizpgAAAAAAAAAbAAAAAAAAAAABIBkQIwAWNjYAAAABAAsDAAAAACDjsMRCmPwcFJr79MiZb7kkJ65B5GSbk0yklZkbeFK4VQ== ABgACwAg7m6jRDU0D0bzepqJ1fD8rc85Ks0JvY+npL8QwPy+R7IAIL5Oi9KGygqH/DZGqngGWdqcZRfbeBVfpBB9pUl1HQGi ACMACwAFAHIAAAAQABgACwADABAAIHWuL1VjHRbjt8bd2H9s/Rn8iEB7E/DZyW6DPuebgp5HACCx9U/+/I/55mBuc4Sh5bhT8uVKrFv3qiW+GmLY1dDliA== f21670e3b256e501b17078dffa53c7c7108b564ebd5513a8033e53f61238b3a6diff --git a/testing/fixtures/keepalive/recompute.py b/testing/fixtures/keepalive/recompute.pyindex 104746da..3f198531 100755--- a/testing/fixtures/keepalive/recompute.py+++ b/testing/fixtures/keepalive/recompute.py@@ -20,11 +20,12 @@ EMPTY_SET = "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"BODY_KEYS = ["schema", "boot_id", "version_id", "config_root", "kernel_release","image_id", "image_version", "image_root", "verdict", "cond", "flags",- "tamper", "tree_id", "generation", "base_seq", "last_seq", "base_root",- "projection_root", "mask", "set_sha256", "count", "not_ok",+ "tamper", "integrity", "tree_id", "generation", "base_seq", "last_seq",+ "base_root", "projection_root", "mask", "set_sha256", "count", "not_ok",]CANONICAL_KEYS = ["seq", "op", "id", "selector", "artifact"]-TAMPER_COUNTERS = 43+TAMPER_COUNTERS = 42+INTEGRITY_COUNTERS = 22ALL_OK = 0x1555OPERATION_DIGESTS = [@@ -51,9 +52,9 @@ MASKS = [# The body the example pages print for node A after release 1.1.0: six# conditions and no image keys.-PAGE_BODY_LEN = 744+PAGE_BODY_LEN = 800PAGE_BODY_SHA256 = \- "3b7aac94ab7c0145070d6fd82862a0b98e2f20f8da1e34f9db2d570ae926215b"+ "3a9fea87b58e250df58b7f336f6511a8b7c4a69752af3ccae3d76b2626bcbacd"PAGE_COND = 0x555VERSION_ID = "d6d918ad22ff597579e6678bef75adca84d30f9661e0b7bbdbf534eebc138c1f"@@ -228,6 +229,7 @@ def check_health(name, body):check(f"{name}: cond", body["cond"], ALL_OK)check(f"{name}: flags", body["flags"], 0)check(f"{name}: tamper", body["tamper"], [0] * TAMPER_COUNTERS)+ check(f"{name}: integrity", body["integrity"], [0] * INTEGRITY_COUNTERS)def check_node(tree, node, release, generation, head_seq):diff --git a/testing/functional/bpm/t7109-bpm-tree-keepalive.sh b/testing/functional/bpm/t7109-bpm-tree-keepalive.shindex bb9cb0bd..33533817 100644--- a/testing/functional/bpm/t7109-bpm-tree-keepalive.sh+++ b/testing/functional/bpm/t7109-bpm-tree-keepalive.sh@@ -126,9 +126,9 @@ import sysKEYS = ["schema", "boot_id", "version_id", "config_root", "kernel_release","image_id", "image_version", "image_root", "verdict", "cond", "flags",- "tamper", "tree_id", "generation", "base_seq", "last_seq",- "base_root", "projection_root", "mask", "set_sha256", "count",- "not_ok"]+ "tamper", "integrity", "tree_id", "generation", "base_seq",+ "last_seq", "base_root", "projection_root", "mask", "set_sha256",+ "count", "not_ok"]TREE_LOG_MISMATCH, TREE_OP_PENDING, SNAPSHOT_UNSETTLED = 4, 16, 32body_path, mode, state_path, outcomes_path, repo = sys.argv[1:6]diff --git a/testing/functional/otel/t8004-status-otel.sh b/testing/functional/otel/t8004-status-otel.shindex 424f0425..ab41f325 100644--- a/testing/functional/otel/t8004-status-otel.sh+++ b/testing/functional/otel/t8004-status-otel.sh@@ -33,9 +33,9 @@ import json, sysKEYS = ["schema", "boot_id", "version_id", "config_root", "kernel_release","image_id", "image_version", "image_root", "verdict", "cond",- "flags", "tamper", "tree_id", "generation", "base_seq", "last_seq",- "base_root", "projection_root", "mask", "set_sha256", "count",- "not_ok"]+ "flags", "tamper", "integrity", "tree_id", "generation",+ "base_seq", "last_seq", "base_root", "projection_root", "mask",+ "set_sha256", "count", "not_ok"]text = open(sys.argv[1]).read()assert text.endswith("}\n") and text.count("\n") == 1, textpairs = json.loads(text, object_pairs_hook=list)diff --git a/testing/functional/otel/t8106-status-otel-quote.sh b/testing/functional/otel/t8106-status-otel-quote.shindex 10429c5e..a901793b 100755--- a/testing/functional/otel/t8106-status-otel-quote.sh+++ b/testing/functional/otel/t8106-status-otel-quote.sh@@ -55,9 +55,9 @@ import base64, json, re, sysKEYS = ["schema", "boot_id", "version_id", "config_root", "kernel_release","image_id", "image_version", "image_root", "verdict", "cond",- "flags", "tamper", "tree_id", "generation", "base_seq", "last_seq",- "base_root", "projection_root", "mask", "set_sha256", "count",- "not_ok"]+ "flags", "tamper", "integrity", "tree_id", "generation",+ "base_seq", "last_seq", "base_root", "projection_root", "mask",+ "set_sha256", "count", "not_ok"]SEVERITY = {"ok": (9, "INFO"), "degraded": (13, "WARN"),"init-pending": (13, "WARN"), "reboot-pending": (13, "WARN"),"tampered": (17, "ERROR"), "lsm-off": (17, "ERROR")}diff --git a/testing/functional/tamperproof/t6003-tamper-points.sh b/testing/functional/tamperproof/t6003-tamper-points.shindex 034210de..1004f634 100755--- a/testing/functional/tamperproof/t6003-tamper-points.sh+++ b/testing/functional/tamperproof/t6003-tamper-points.sh@@ -2,12 +2,12 @@# SPDX-License-Identifier: BSD-2-Clause# Copyright (c) 2026 Authors of shirudo#-# t6003 -- the tamper points are the one enum the LSM counts with and-# status names them from (bpf/lib/tamper.h), and a counter is-# only as good as its name; this keeps every member in the table of-# names and meanings util/tamper.c holds. Also checks that status-# reports the counters as absent, not as an error, where init has not-# run.+# t6003 -- the tamper and integrity points are the enums the LSM counts+# with and status names them from (bpf/lib/tamper.h, integrity.h), and a+# counter is only as good as its name; this keeps every member in the+# table of names and meanings util/tamper.c and util/integrity.c hold.+# Also checks that status reports the counters as absent, not as an+# error, where init has not run.cd "$(dirname "$0")/../..". ./test-lib.sh@@ -25,6 +25,15 @@ test_expect_success 'every point has a name and a meaning' 'cmp "$W/points" "$W/table"'+test_expect_success 'every integrity point has a name and a meaning' '+ sed -n "s/^\tINTEGRITY_\([A-Z_]*\),$/\1/p" \+ ../bpf/lib/integrity.h >"$W/integrity-points" &&+ sed -n "s/^\t\[INTEGRITY_\([A-Z_]*\)\] = { \"[A-Za-z]*\",$/\1/p" \+ ../util/integrity.c >"$W/integrity-table" &&+ [ -s "$W/integrity-points" ] &&+ cmp "$W/integrity-points" "$W/integrity-table"+'+test_expect_success 'status --json reports the counters as null without init' 'if [ -e /run/shirudo/bpffs/tamper ]; thenecho "skipping: a tamper map is pinned on this host"@@ -33,6 +42,7 @@ test_expect_success 'status --json reports the counters as null without init' 'import json, sysd = json.load(sys.stdin)assert \"tamper_attempts\" in d and d[\"tamper_attempts\"] is None+assert \"integrity_attempts\" in d and d[\"integrity_attempts\"] is None"fi'diff --git a/testing/functional/tamperproof/t6154-lockdown.sh b/testing/functional/tamperproof/t6154-lockdown.shindex 92e86407..637f4be6 100755--- a/testing/functional/tamperproof/t6154-lockdown.sh+++ b/testing/functional/tamperproof/t6154-lockdown.sh@@ -4,9 +4,10 @@## t6154 -- bpf2 refuses what lockdown in integrity mode refuses, whatever# the command line says, and /proc/kcore with it: an unsigned module and-# the reads and writes of the running kernel fail with EPERM and count as-# Lockdown, while the hibernation check every read of /sys/power/state-# makes counts nothing.+# the reads and writes of the running kernel fail with EPERM and each+# counts on the integrity counter of its reason, which status, its JSON+# and the keepalive report, while the hibernation check every read of+# /sys/power/state makes counts nothing.cd "$(dirname "$0")/../..". ./integration-lib.sh@@ -17,7 +18,8 @@ trap 'rm -rf "$W"' EXITcounter() {"$SHIRUDO_BIN" status --json | python3 -c 'import json, sys-print(json.load(sys.stdin)["tamper_attempts"]["counters"][sys.argv[1]])+d = json.load(sys.stdin)["integrity_attempts"]+print(d["total"] if sys.argv[1] == "total" else d["counters"][sys.argv[1]])' "$1"}# Prints the errno name an open of $1 for reading fails with, or done.@@ -31,14 +33,14 @@ except OSError as e:print(errno.errorcode[e.errno])' "$1"}-counter Lockdown >/dev/null || test_skip_all "no tamper counters"+counter total >/dev/null || test_skip_all "no integrity counters"# The guest's modules are signed; a copy without the signature is what the# kernel asks lockdown about.test_expect_success 'a module without its signature is refused and counted' 'module=$(find "/lib/modules/$(uname -r)" -name "*.ko" | head -1) &&[ -n "$module" ] &&- now=$(counter Lockdown) &&+ now=$(counter ModuleSignature) &&python3 - "$module" "$W/unsigned.ko" >"$W/module" <<-\PY &&import ctypes, errno, os, platform, sysMARKER = b"~Module signature appended~\n"@@ -55,21 +57,21 @@ test_expect_success 'a module without its signature is refused and counted' 'print("done" if ret == 0 else errno.errorcode[ctypes.get_errno()])PYgrep -qx EPERM "$W/module" &&- [ "$(counter Lockdown)" -gt "$now" ]+ [ "$(counter ModuleSignature)" -gt "$now" ]'if [ -e /proc/kcore ]; thentest_expect_success '/proc/kcore is refused and counted' '- now=$(counter Lockdown) &&+ now=$(counter Kcore) &&[ "$(open_errno /proc/kcore)" = EPERM ] &&- [ "$(counter Lockdown)" -gt "$now" ]+ [ "$(counter Kcore)" -gt "$now" ]'fiCONFIG=$(ls /sys/bus/pci/devices/*/config 2>/dev/null | head -1)if [ -n "$CONFIG" ]; then# The interrupt line byte written back as it is, should the write pass.test_expect_success 'a PCI config write is refused and counted' '- now=$(counter Lockdown) &&+ now=$(counter PciAccess) &&python3 - "$CONFIG" >"$W/pci" <<-\PY &&import errno, syswith open(sys.argv[1], "r+b", buffering=0) as f:@@ -83,7 +85,7 @@ if [ -n "$CONFIG" ]; thenprint(errno.errorcode[e.errno])PYgrep -qx EPERM "$W/pci" &&- [ "$(counter Lockdown)" -gt "$now" ]+ [ "$(counter PciAccess)" -gt "$now" ]'fiif [ -e /dev/mem ]; then@@ -92,8 +94,29 @@ if [ -e /dev/mem ]; then'fitest_expect_success 'reading /sys/power/state counts nothing' '- now=$(counter Lockdown) &&+ now=$(counter total) &&cat /sys/power/state >/dev/null 2>&1 || :- [ "$(counter Lockdown)" -eq "$now" ]+ [ "$(counter total)" -eq "$now" ]+'+test_expect_success 'status lists the integrity counters apart from the tamper counters' '+ "$SHIRUDO_BIN" status >"$W/status" &&+ sed -n "/^Integrity attempts (this boot):/,/^\$/p" "$W/status" \+ >"$W/integrity" &&+ grep -q "^ ModuleSignature *[1-9][0-9]* module load without" \+ "$W/integrity" &&+ ! sed -n "/^Tamper attempts (this boot):/,/^\$/p" "$W/status" |+ grep -q "ModuleSignature"+'+test_expect_success 'the keepalive carries every integrity counter in order' '+ "$SHIRUDO_BIN" status --keepalive | python3 -c "+import json, sys+body = json.load(sys.stdin)+integrity = body[\"integrity\"]+assert len(integrity) == 22 and integrity[0] > 0, integrity+assert body[\"flags\"] & 64 == 0, body[\"flags\"]+"+'+test_expect_success 'root cannot open the integrity counter map' '+ [ "$(open_errno /run/shirudo/bpffs/integrity)" = EACCES ]'test_donediff --git a/testing/proofs/cbmc/keepalive-emit.c b/testing/proofs/cbmc/keepalive-emit.cindex e64576e6..d7fb4cae 100644--- a/testing/proofs/cbmc/keepalive-emit.c+++ b/testing/proofs/cbmc/keepalive-emit.c@@ -3,7 +3,7 @@* Copyright (c) 2026 Authors of shirudo** keepalive_emit() of util/keepalive.c: three bodies, each one JSON- * object of 22 members; a last number of up to LEN + 1 digits in a room+ * object of 23 members; a last number of up to LEN + 1 digits in a room* for LEN changes only its digits, or is -ENOSPC exactly when too long;* a bad input, a room cut short or a string not UTF-8 leaves no body.*/@@ -18,15 +18,16 @@#define HASH \"0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"#define NOT_A_HASH "sha256:0123456789abcdef"-#define MEMBERS 22+#define MEMBERS 23/* Past the longest of these bodies, and a room inside the shortest. */-#define ROOM 832+#define ROOM 896#define CUT_SHORT (ROOM / 4)enum state { START, KEY, STRING, COLON, VALUE, ELEMENT, ZERO, DIGITS, WORD,NEXT, END };static const __u64 counters[TAMPER_MAX];+static const __u64 integrity[INTEGRITY_MAX];static char reference[ROOM];/* keepalive_mask() is not reached: the mask comes in as text. */@@ -169,8 +170,9 @@ static struct keepalive_input with_every_value(void).image_root = HASH,.verdict = "ok",.cond = 5461,- .flags = 63,+ .flags = 127,.tamper = counters,+ .integrity = integrity,.tree = true,.tree_id = "t",.generation = 42,@@ -205,7 +207,7 @@ static void is_an_object(const struct keepalive_input *in)__CPROVER_assert(!keepalive_emit(in, buf, ROOM, &len) && len < ROOM &&!buf[len], "the body fits, terminated");__CPROVER_assert(json_members(buf, len) == MEMBERS,- "one JSON object of 22 members");+ "one JSON object of 23 members");}/*diff --git a/testing/proofs/cbmc/proofs.list b/testing/proofs/cbmc/proofs.listindex 6e98532c..37e6d095 100644--- a/testing/proofs/cbmc/proofs.list+++ b/testing/proofs/cbmc/proofs.list@@ -56,7 +56,7 @@ log-escape --unwind 7 LEN=0-5json-emit-string --unwind 5 --unwindset json_string.0:27,put_string_n.0:5,put_raw.0:7,well_formed.0:27,replaced.0:5,memchr.0:9,memcmp.0:13 LEN=0-4json-emit-buffer --unwind 1 --unwindset json_raw_value.0:5,harness.0:5 --malloc-may-fail --malloc-fail-null LEN=0-4json-emit-nest --object-bits 12 --unwind 1 --unwindset json_text.0:57,sequences.0:4,sequences.1:5,any_depth.0:4,any_depth.1:4,strcmp.0:12,memchr.0:9,put_string_n.0:2,put_string_n.1:2,put_raw.0:8,json_kv_raw.0:3,json_raw_value.0:3,json_raw.0:5,strlen.0:3,vsnprintf.2:5,vsnprintf.0:2,format_number.0:3,format_number.2:5,format_number.3:3-keepalive-emit -I ../../.. --object-bits 12 --max-field-sensitivity-array-size 832 --unwind 1 --unwindset json_members.0:833,power_of_ten.0:6,put_string_n.0:5,put_string_n.1:66,put_raw.0:7,strlen.0:66,hex_is_lower.0:66,kv_tamper.0:44,kv_no_tree.0:8,json_raw_value.0:6,vsnprintf.2:4,vsnprintf.0:2,format_number.0:6,format_number.2:5,format_number.3:6,ends_in_any_number.0:6,ends_in_any_number.1:833,ends_in_any_number.2:5 LEN=0-3+keepalive-emit -I ../../.. --object-bits 12 --max-field-sensitivity-array-size 896 --unwind 1 --unwindset json_members.0:897,power_of_ten.0:6,put_string_n.0:5,put_string_n.1:66,put_raw.0:7,strlen.0:66,hex_is_lower.0:66,kv_counters.0:43,kv_no_tree.0:8,json_raw_value.0:6,vsnprintf.2:4,vsnprintf.0:2,format_number.0:6,format_number.2:5,format_number.3:6,ends_in_any_number.0:6,ends_in_any_number.1:897,ends_in_any_number.2:5 LEN=0-3json-string --unwind 5 --unwindset json_string.0:7,parse_string.0:5,parse_string.1:7,memchr.0:9,memcmp.0:7,harness.0:8 LEN=0-6json-escape --unwind 5 --unwindset parse_string.0:4,memcmp.0:9json-roundtrip --unwind 1 --unwindset put_string_n.0:5,put_string_n.1:5,put_raw.0:7,vsnprintf.2:4,vsnprintf.0:2,format_number.0:3,format_number.2:5,format_number.3:3,parse_string.1:6,parse_string.0:4,hex4.0:5,utf8_width.0:4,memcmp.0:5 LEN=0-4diff --git a/testing/unit/keepalive.c b/testing/unit/keepalive.cindex d3e45e73..3e29a8e4 100644--- a/testing/unit/keepalive.c+++ b/testing/unit/keepalive.c@@ -7,6 +7,7 @@#include <shirudo/string.h>+#include "integrity.h"#include "json.h"#include "keepalive.h"#include "tamper.h"@@ -45,6 +46,7 @@"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"static const __u64 no_tamper[TAMPER_MAX];+static const __u64 no_integrity[INTEGRITY_MAX];static void expect_mask(const __u8 *codes, size_t n, const char *want){@@ -312,6 +314,7 @@ static struct keepalive_input node_a(void).verdict = "ok",.cond = ALL_OK,.tamper = no_tamper,+ .integrity = no_integrity,.tree = true,.tree_id = "fleet-base",.base_root = ZEROS,@@ -411,7 +414,7 @@ static struct keepalive_input all_null(void).version_id = VERSION_ID,.kernel_release = "k",.verdict = "init-pending",- .flags = 8,+ .flags = 72,.set_sha256 = SET_EMPTY,};}@@ -425,9 +428,10 @@ static void body_with_every_nullable_key_null(void)"\"version_id\":\"" VERSION_ID "\",\"config_root\":null,""\"kernel_release\":\"k\",\"image_id\":null,""\"image_version\":null,\"image_root\":null,"- "\"verdict\":\"init-pending\",\"cond\":0,\"flags\":8,"- "\"tamper\":null,\"tree_id\":null,\"generation\":null,"- "\"base_seq\":null,\"last_seq\":null,\"base_root\":null,"+ "\"verdict\":\"init-pending\",\"cond\":0,\"flags\":72,"+ "\"tamper\":null,\"integrity\":null,\"tree_id\":null,"+ "\"generation\":null,\"base_seq\":null,\"last_seq\":null,"+ "\"base_root\":null,""\"projection_root\":null,\"mask\":null,""\"set_sha256\":\"" SET_EMPTY "\",\"count\":0,""\"not_ok\":0}");@@ -493,7 +497,9 @@ static void body_gives_each_nullable_key_as_null(void)in.image_root = "";expect_member(&in, ",\"image_root\":null,\"verdict\":");in.tamper = NULL;- expect_member(&in, ",\"tamper\":null,\"tree_id\":\"fleet-base\",");+ expect_member(&in, ",\"tamper\":null,\"integrity\":[0,");+ in.integrity = NULL;+ expect_member(&in, ",\"integrity\":null,\"tree_id\":\"fleet-base\",");in.base_root = NULL;expect_member(&in, ",\"base_root\":null,\"projection_root\":\"");in.base_root = "";@@ -524,8 +530,8 @@ struct key_walk {static const char * const body_keys[] = {"schema", "boot_id", "version_id", "config_root", "kernel_release","image_id", "image_version", "image_root", "verdict", "cond", "flags",- "tamper", "tree_id", "generation", "base_seq", "last_seq", "base_root",- "projection_root", "mask", "set_sha256", "count", "not_ok",+ "tamper", "integrity", "tree_id", "generation", "base_seq", "last_seq",+ "base_root", "projection_root", "mask", "set_sha256", "count", "not_ok",};static int walk_open(void *ctx, bool array)@@ -568,7 +574,7 @@ static void expect_the_keys_in_order(const struct keepalive_input *in)ASSERT_EQ(keepalive_emit(in, body, sizeof(body), &len), 0);ASSERT_EQ(json_walk(body, len, &visitor, &walk), 0);- EXPECT_EQ(walk.n, 22);+ EXPECT_EQ(walk.n, 23);EXPECT_EQ(walk.n, ARRAY_SIZE(body_keys));EXPECT_TRUE(walk.in_order);}@@ -595,15 +601,23 @@ static const char * const tamper_order[] = {"SealRename", "SealSetattr", "SealXattr", "SealLabel", "SealPtrace","SealPerf", "ExecTraced", "SealEntry", "PerfAttach", "PinEntry","SealCopyUp", "Kexec", "TpmExtend", "ObjGet", "SealSignal",- "SealCoreDump", "SealUprobe", "ExecShared", "XattrHandle", "Lockdown",- "SealRlimit",+ "SealCoreDump", "SealUprobe", "ExecShared", "XattrHandle", "SealRlimit",+};++/* The same for enum integrity_point. */+static const char * const integrity_order[] = {+ "ModuleSignature", "DevMem", "EfiTest", "KexecSignature", "PciAccess",+ "IoPort", "Msr", "AcpiTables", "DeviceTree", "PcmciaCis",+ "Tiocsserial", "ModuleParameters", "Mmiotrace", "Debugfs", "XmonWrite",+ "BpfWriteUser", "DbgWriteKernel", "RtasErrorInjection",+ "XenUserActions", "Kcore", "HibernateLocation", "Other",};static void tamper_counters_keep_their_places(void){size_t i;- ASSERT_EQ(ARRAY_SIZE(tamper_order), 43);+ ASSERT_EQ(ARRAY_SIZE(tamper_order), 42);ASSERT_EQ(TAMPER_MAX, ARRAY_SIZE(tamper_order));EXPECT_EQ(TAMPER_LOAD_NOT_LOADER, 0);EXPECT_EQ(TAMPER_SEAL_RLIMIT, TAMPER_MAX - 1);@@ -611,19 +625,42 @@ static void tamper_counters_keep_their_places(void)EXPECT_STREQ(tamper_name(i), tamper_order[i]);}+static void integrity_counters_keep_their_places(void)+{+ size_t i;++ ASSERT_EQ(ARRAY_SIZE(integrity_order), 22);+ ASSERT_EQ(INTEGRITY_MAX, ARRAY_SIZE(integrity_order));+ EXPECT_EQ(INTEGRITY_MODULE_SIGNATURE, 0);+ EXPECT_EQ(INTEGRITY_OTHER, INTEGRITY_MAX - 1);+ for (i = 0; i < ARRAY_SIZE(integrity_order); i++) {+ EXPECT_STREQ(integrity_name(i), integrity_order[i]);+ EXPECT_TRUE(strcmp(integrity_meaning(i), "?"));+ }+ EXPECT_STREQ(integrity_name(INTEGRITY_MAX), "?");+}+static void body_lists_the_counters_in_enum_order(void){struct keepalive_input in = node_a_at_1_0_0();+ __u64 integrity[INTEGRITY_MAX];__u64 tamper[TAMPER_MAX];size_t i;for (i = 0; i < TAMPER_MAX; i++)tamper[i] = i + 1;tamper[TAMPER_SEAL_SIGNAL] = ~0ULL;+ for (i = 0; i < INTEGRITY_MAX; i++)+ integrity[i] = 100 + i;+ integrity[INTEGRITY_KCORE] = ~0ULL;in.tamper = tamper;+ in.integrity = integrity;expect_member(&in, ",\"tamper\":[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,""16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,"- "34,35,36,18446744073709551615,38,39,40,41,42,43],\"tree_id\":");+ "34,35,36,18446744073709551615,38,39,40,41,42],"+ "\"integrity\":[100,101,102,103,104,105,106,107,108,109,"+ "110,111,112,113,114,115,116,117,118,"+ "18446744073709551615,120,121],\"tree_id\":");}static void body_refuses_a_missing_string(void)@@ -730,6 +767,7 @@ static void body_of_the_largest_values_fits(void).count = ~0ULL,.not_ok = ~0ULL,};+ __u64 integrity[INTEGRITY_MAX];__u64 tamper[TAMPER_MAX];size_t whole, len, i;@@ -740,10 +778,13 @@ static void body_of_the_largest_values_fits(void)sizeof(mask)), 0);for (i = 0; i < TAMPER_MAX; i++)tamper[i] = ~0ULL;+ for (i = 0; i < INTEGRITY_MAX; i++)+ integrity[i] = ~0ULL;in.tamper = tamper;+ in.integrity = integrity;ASSERT_EQ(keepalive_emit(&in, body, sizeof(body), &whole), 0);- EXPECT_EQ(whole, 3424);+ EXPECT_EQ(whole, 3879);EXPECT_LT(whole, KEEPALIVE_BODY_MAX);EXPECT_EQ(keepalive_emit(&in, body, whole, &len), -ENOSPC);EXPECT_EQ(keepalive_emit(&in, body, whole + 1, &len), 0);@@ -930,6 +971,7 @@ static const struct unit_case cases[] = {UNIT_CASE(body_tells_an_empty_mask_from_none),UNIT_CASE(body_has_every_key_in_order),UNIT_CASE(tamper_counters_keep_their_places),+ UNIT_CASE(integrity_counters_keep_their_places),UNIT_CASE(body_lists_the_counters_in_enum_order),UNIT_CASE(body_refuses_a_missing_string),UNIT_CASE(body_refuses_what_is_no_hash),diff --git a/util/image_guards.c b/util/image_guards.cindex b7a3b215..d999325a 100644--- a/util/image_guards.c+++ b/util/image_guards.c@@ -21,6 +21,7 @@#include "identity.h"#include "image_guards.h"+#include "integrity.h"#include "log.h"#include "paths.h"#include "tamper.h"@@ -185,6 +186,11 @@ const struct guard_map shirudo_guard_maps[GUARD_MAP_COUNT] = {BPF_MAP_TYPE_ARRAY, sizeof(__u32),sizeof(__u64), TAMPER_MAX, 0,},+ [GUARD_INTEGRITY] = {+ "shirudo_integrity", INTEGRITY_PIN,+ BPF_MAP_TYPE_ARRAY, sizeof(__u32),+ sizeof(__u64), INTEGRITY_MAX, 0,+ },};/* Initial authenticated boot creates mappings before these guards exist. */diff --git a/util/image_guards.h b/util/image_guards.hindex 6b19a20c..96c12793 100644--- a/util/image_guards.h+++ b/util/image_guards.h@@ -40,6 +40,7 @@ enum guard_map_index {GUARD_TAMPER,GUARD_POLICY,GUARD_SOCKET_POLICY,+ GUARD_INTEGRITY,GUARD_MAP_COUNT,};diff --git a/util/integrity.c b/util/integrity.cnew file mode 100644index 00000000..7015eb57--- /dev/null+++ b/util/integrity.c@@ -0,0 +1,81 @@+// SPDX-License-Identifier: BSD-2-Clause+/*+ * Copyright (c) 2026 Authors of shirudo+ *+ * Read back the integrity counters init pinned in the private bpffs.+ */+#include <shirudo/misc.h>++#include "integrity.h"+#include "paths.h"+#include "tamper.h"++static const struct {+ const char *name;+ const char *meaning;+} integrity_points[INTEGRITY_MAX] = {+ [INTEGRITY_MODULE_SIGNATURE] = { "ModuleSignature",+ "module load without a valid signature" },+ [INTEGRITY_DEV_MEM] = { "DevMem",+ "/dev/mem or /dev/port" },+ [INTEGRITY_EFI_TEST] = { "EfiTest",+ "EFI runtime services through efi_test" },+ [INTEGRITY_KEXEC] = { "KexecSignature",+ "kexec of a kernel without a valid signature" },+ [INTEGRITY_PCI_ACCESS] = { "PciAccess",+ "PCI configuration write or BAR mapping" },+ [INTEGRITY_IOPORT] = { "IoPort",+ "raw I/O port access" },+ [INTEGRITY_MSR] = { "Msr",+ "model-specific register write" },+ [INTEGRITY_ACPI_TABLES] = { "AcpiTables",+ "ACPI table override or custom method" },+ [INTEGRITY_DEVICE_TREE] = { "DeviceTree",+ "device tree overlay" },+ [INTEGRITY_PCMCIA_CIS] = { "PcmciaCis",+ "PCMCIA CIS override" },+ [INTEGRITY_TIOCSSERIAL] = { "Tiocsserial",+ "serial port I/O or IRQ reconfiguration" },+ [INTEGRITY_MODULE_PARAMETERS] = { "ModuleParameters",+ "module parameter that sets hardware addresses" },+ [INTEGRITY_MMIOTRACE] = { "Mmiotrace",+ "MMIO tracing" },+ [INTEGRITY_DEBUGFS] = { "Debugfs",+ "debugfs file that writes or maps" },+ [INTEGRITY_XMON_WR] = { "XmonWrite",+ "xmon write access" },+ [INTEGRITY_BPF_WRITE_USER] = { "BpfWriteUser",+ "BPF program that writes user memory" },+ [INTEGRITY_DBG_WRITE_KERNEL] = { "DbgWriteKernel",+ "kernel debugger write" },+ [INTEGRITY_RTAS_ERROR_INJECTION] = { "RtasErrorInjection",+ "RTAS error injection" },+ [INTEGRITY_XEN_USER_ACTIONS] = { "XenUserActions",+ "Xen user action that writes memory" },+ [INTEGRITY_KCORE] = { "Kcore",+ "/proc/kcore, the kernel's memory" },+ [INTEGRITY_HIBERNATE_LOCATION] = { "HibernateLocation",+ "EFI variable naming a resume device" },+ [INTEGRITY_OTHER] = { "Other",+ "lockdown reason this build does not name" },+};++const char *integrity_name(enum integrity_point point)+{+ if (point >= INTEGRITY_MAX || !integrity_points[point].name)+ return "?";+ return integrity_points[point].name;+}++const char *integrity_meaning(enum integrity_point point)+{+ if (point >= INTEGRITY_MAX || !integrity_points[point].meaning)+ return "?";+ return integrity_points[point].meaning;+}++int integrity_read(struct integrity_counts *out)+{+ return counters_read(INTEGRITY_PIN, INTEGRITY_MAX, out->count,+ &out->total);+}diff --git a/util/integrity.h b/util/integrity.hnew file mode 100644index 00000000..021491c9--- /dev/null+++ b/util/integrity.h@@ -0,0 +1,25 @@+/* SPDX-License-Identifier: BSD-2-Clause */+/*+ * Copyright (c) 2026 Authors of shirudo+ *+ * The integrity counters the LSM keeps, read back from their bpffs pin.+ */+#ifndef SHIRUDO_UTIL_INTEGRITY_H+#define SHIRUDO_UTIL_INTEGRITY_H++#include <shirudo/misc.h>++#include "bpf/lib/integrity.h"++struct integrity_counts {+ __u64 count[INTEGRITY_MAX];+ __u64 total;+};++const char *integrity_name(enum integrity_point point);+const char *integrity_meaning(enum integrity_point point);++/* As tamper_read(), for the integrity counters. */+int integrity_read(struct integrity_counts *out);++#endif /* SHIRUDO_UTIL_INTEGRITY_H */diff --git a/util/keepalive.c b/util/keepalive.cindex a3fdfbff..666cd33a 100644--- a/util/keepalive.c+++ b/util/keepalive.c@@ -131,17 +131,18 @@ static void kv_string_or_null(struct json_emit *e, const char *key,json_kv_string(e, key, val);}-static void kv_tamper(struct json_emit *e, const __u64 *tamper)+static void kv_counters(struct json_emit *e, const char *key,+ const __u64 *count, size_t n){size_t i;- if (!tamper) {- json_kv_null(e, "tamper");+ if (!count) {+ json_kv_null(e, key);return;}- json_arr_open(e, "tamper");- for (i = 0; i < TAMPER_MAX; i++)- json_u64_value(e, tamper[i]);+ json_arr_open(e, key);+ for (i = 0; i < n; i++)+ json_u64_value(e, count[i]);json_arr_close(e);}@@ -189,7 +190,8 @@ static void body(struct json_emit *e, const struct keepalive_input *in)json_kv_string(e, "verdict", in->verdict);json_kv_u64(e, "cond", in->cond);json_kv_u64(e, "flags", in->flags);- kv_tamper(e, in->tamper);+ kv_counters(e, "tamper", in->tamper, TAMPER_MAX);+ kv_counters(e, "integrity", in->integrity, INTEGRITY_MAX);kv_tree(e, in);json_kv_string(e, "set_sha256", in->set_sha256);json_kv_u64(e, "count", in->count);diff --git a/util/keepalive.h b/util/keepalive.hindex dcf334f3..9c5ade28 100644--- a/util/keepalive.h+++ b/util/keepalive.h@@ -14,6 +14,7 @@#include <shirudo/misc.h>+#include "bpf/lib/integrity.h"#include "bpf/lib/tamper.h"#include "bpm_tree.h"#include "conditions.h"@@ -43,6 +44,7 @@ BUILD_BUG_ON(KEEPALIVE_WINDOW_OPS < 1 ||#define KEEPALIVE_TAMPER_UNAVAILABLE (1u << 3)#define KEEPALIVE_TREE_OP_PENDING (1u << 4)#define KEEPALIVE_SNAPSHOT_UNSETTLED (1u << 5)+#define KEEPALIVE_INTEGRITY_UNAVAILABLE (1u << 6)/** How many times a snapshot reads the tree before it gives up on a state@@ -67,6 +69,7 @@ struct keepalive_input {__u16 cond; /* keepalive_cond() */__u32 flags;const __u64 *tamper; /* TAMPER_MAX counters or null */+ const __u64 *integrity; /* INTEGRITY_MAX counters or null *//* Not set: the node follows no tree and the seven tree keys are null. */bool tree;const char *tree_id;diff --git a/util/paths.h b/util/paths.hindex 651e79e0..dbe015ec 100644--- a/util/paths.h+++ b/util/paths.h@@ -107,6 +107,7 @@#define BPFFS_UPATCHES_DIR BPFFS_DIR "/upatches"#define IDENTITY_PIN BPFFS_DIR "/identity"#define TAMPER_PIN BPFFS_DIR "/tamper"+#define INTEGRITY_PIN BPFFS_DIR "/integrity"#define POLICY_PIN BPFFS_DIR "/task_policy"#define SEAL_SOCKET_POST_CREATE_PIN \BPFFS_DIR "/seal_socket_post_create_link"diff --git a/util/tamper.c b/util/tamper.cindex 17841078..a77f1d23 100644--- a/util/tamper.c+++ b/util/tamper.c@@ -102,8 +102,6 @@ static const struct {"exec of the runtime binary by a task that shares its file system context" },[TAMPER_XATTR_HANDLE] = { "XattrHandle","XFS attribute change by file handle, which passes no xattr hook" },- [TAMPER_LOCKDOWN] = { "Lockdown",- "change or read of the running kernel that lockdown refuses" },[TAMPER_SEAL_RLIMIT] = { "SealRlimit","resource limit of a shirudo task changed by another task" },};@@ -122,33 +120,38 @@ const char *tamper_meaning(enum tamper_point point)return tamper_points[point].meaning;}-int tamper_read(struct tamper_counts *out)+int counters_read(const char *pin, __u32 n, __u64 *count, __u64 *total){struct bpf_map_info info = {};__u32 len = sizeof(info);int fd, ret;__u32 key;- memset(out, 0, sizeof(*out));- fd = bpf_obj_get(TAMPER_PIN);+ memset(count, 0, n * sizeof(*count));+ *total = 0;+ fd = bpf_obj_get(pin);if (fd < 0)return -errno;ret = bpf_map_get_info_by_fd(fd, &info, &len);if (ret) {ret = -errno;- } else if (info.max_entries != TAMPER_MAX ||- info.value_size != sizeof(out->count[0])) {+ } else if (info.max_entries != n || info.value_size != sizeof(*count)) {ret = -EPROTO;} else {- for (key = 0; key < TAMPER_MAX; key++) {- ret = bpf_map_lookup_elem(fd, &key, &out->count[key]);+ for (key = 0; key < n; key++) {+ ret = bpf_map_lookup_elem(fd, &key, &count[key]);if (ret) {ret = -errno;break;}- out->total += out->count[key];+ *total += count[key];}}close(fd);return ret;}++int tamper_read(struct tamper_counts *out)+{+ return counters_read(TAMPER_PIN, TAMPER_MAX, out->count, &out->total);+}diff --git a/util/tamper.h b/util/tamper.hindex 7df8c659..2c9e4f09 100644--- a/util/tamper.h+++ b/util/tamper.h@@ -26,4 +26,7 @@ const char *tamper_meaning(enum tamper_point point);*/int tamper_read(struct tamper_counts *out);+/* tamper_read() of the n counters of any such map, pinned at pin. */+int counters_read(const char *pin, __u32 n, __u64 *count, __u64 *total);+#endif /* SHIRUDO_UTIL_TAMPER_H */