eBPF-based security platform
status: report the dm-verity keyring and every link of both keyrings
Daniel Borkmann554ba03bf4ae
diff --git a/Documentation/concepts/background/keyrings.rst b/Documentation/concepts/background/keyrings.rstindex 39d4de3d..d91d97b4 100644--- a/Documentation/concepts/background/keyrings.rst+++ b/Documentation/concepts/background/keyrings.rst@@ -172,7 +172,10 @@ or that holds keys beyond the set, is refused as well.Init then records the serials of both keyrings, of the ``.dm-verity``key and of the enrolled ``.bpf`` keys in a frozen map. Later commandscompare the ``.bpf`` serial with that record and refuse ``tampered`` on-a mismatch. shirudo's ``lsm/key_permission`` program refuses write, set+a mismatch. ``shirudo status`` compares both keyrings with it and+follows every link, whatever its type: a swapped or missing keyring, a+link ``init`` did not record or a missing config key makes its verdict+``tampered`` (see :doc:`/operate/read-status`). shirudo's ``lsm/key_permission`` program refuses write, setattribute and unlink on the recorded keyrings and keys to every taskwithout runtime authority, and refuses a search through an unpossessedreference, which is how ``keyctl`` reaches a key by serial. Thediff --git a/Documentation/contribute/test-coverage.rst b/Documentation/contribute/test-coverage.rstindex 99a2bb3a..be186230 100644--- a/Documentation/contribute/test-coverage.rst+++ b/Documentation/contribute/test-coverage.rst@@ -249,7 +249,7 @@ signed config image.* - ``t6003-tamper-points``- Every tamper counter has a name and a meaning* - ``t6004-conditions``- - Status conditions: keyring, register, config activation+ - Status conditions: both keyrings, register, config activation* - ``t6005-mode-objects``- The embedded admission and seal objects include imageenforcement@@ -338,6 +338,8 @@ signed config image.- A mutated loader, the payload binding, links by pin or id* - ``t6139-serializer-runs``- Repeated peeks and concurrent drains+ * - ``t6140-status-keyrings``+ - Status reports both keyrings with each certificate's frozen key``bpm`` (7)~~~~~~~~~~~@@ -532,7 +534,7 @@ Coverage by area``t6134``, ``t6135``, ``t6136``, ``t6137``* - Keyrings- ``t2101``, ``t2102``, ``t2103``, ``t5101``, ``t5104``,- ``t6004``, ``t6104``, ``t6112``, ``t6129``+ ``t6004``, ``t6104``, ``t6112``, ``t6129``, ``t6140``* - Signing keys and the trusted set- ``t2001``, ``t2002``, ``t2003``, ``t2004``, ``t2005``,``t5003``diff --git a/Documentation/operate/boot-integration.rst b/Documentation/operate/boot-integration.rstindex 212ec312..5f9fe346 100644--- a/Documentation/operate/boot-integration.rst+++ b/Documentation/operate/boot-integration.rst@@ -432,15 +432,15 @@ Boot and verifyRoles: targetMode: productionStatus: ok- Version-ID: 58b05ab35a2bcefaa649faf15f8c6be0211e24cea710450c1a29298c3b5c7de0+ Version-ID: 447b34bc8bc5547334ced4c737f987a9d3f8f03e332cf234626f0b81b5955064Conditions:TYPE STATUS DETAILLsmAttached OK lsm/bpf link present and pinned- KeyringSealed OK serial=420195959 in the BPF keyring, pin matches+ KeyringSealed OK bpf serial=130847582, dm-verity serial=962472513, pins matchChainIntact OK live register == eventlog replayTpmMeasured OK NV index 0x01818E00 readable- ConfigActive OK config 12dbf3c75083.. is active+ ConfigActive OK config dc90bacc356f.. is active...TPM Measurement:TPM: reachable (device:/dev/tpmrm0)diff --git a/Documentation/operate/initialize.rst b/Documentation/operate/initialize.rstindex d05b4ca4..b2d21008 100644--- a/Documentation/operate/initialize.rst+++ b/Documentation/operate/initialize.rst@@ -68,21 +68,21 @@ Check that init workedRoles: targetMode: productionStatus: ok- Version-ID: 58b05ab35a2bcefaa649faf15f8c6be0211e24cea710450c1a29298c3b5c7de0+ Version-ID: 447b34bc8bc5547334ced4c737f987a9d3f8f03e332cf234626f0b81b5955064Conditions:TYPE STATUS DETAILLsmAttached OK lsm/bpf link present and pinned- KeyringSealed OK serial=420195959 in the BPF keyring, pin matches+ KeyringSealed OK bpf serial=130847582, dm-verity serial=962472513, pins matchChainIntact OK live register == eventlog replayTpmMeasured OK NV index 0x01818E00 readable- ConfigActive OK config 12dbf3c75083.. is active+ ConfigActive OK config dc90bacc356f.. is active...TPM Measurement:TPM: reachable (device:/dev/tpmrm0)NV index: 0x01818E00 (anchored in PCR 9)- Chain: e57e1428ab398e758b63f8eda52bac87b5d85c1368c2d8d786ed446448e46239- Register name: 000be3a552e2219550d2597ab96f3fffdeec0d01ce27cde858e0858ab0cdaba6c045+ Chain: dc21c3dabcd2fd0a751c7146ad71c595f2386a4406feb64c3d6e2bd65c5bc706+ Register name: 000b9b7b0f925415fdf0d5676369f8cc9146b9e3142537148b31e79dbffcc96e72f8Anchored: yes (name on record)PCR before init: 0000000000000000000000000000000000000000000000000000000000000000Phase at init: 0000000000000000000000000000000000000000000000000000000000000000 (PCR 11)diff --git a/Documentation/operate/read-status.rst b/Documentation/operate/read-status.rstindex 2a1edc75..ac05d05a 100644--- a/Documentation/operate/read-status.rst+++ b/Documentation/operate/read-status.rst@@ -60,38 +60,50 @@ loaded, captured from the test VM:Roles: targetMode: productionStatus: ok- Version-ID: 58b05ab35a2bcefaa649faf15f8c6be0211e24cea710450c1a29298c3b5c7de0+ Version-ID: 447b34bc8bc5547334ced4c737f987a9d3f8f03e332cf234626f0b81b5955064Conditions:TYPE STATUS DETAILLsmAttached OK lsm/bpf link present and pinned- KeyringSealed OK serial=420195959 in the BPF keyring, pin matches+ KeyringSealed OK bpf serial=130847582, dm-verity serial=962472513, pins matchChainIntact OK live register == eventlog replayTpmMeasured OK NV index 0x01818E00 readable- ConfigActive OK config 12dbf3c75083.. is active+ ConfigActive OK config dc90bacc356f.. is activeTamper attempts (refused this boot):- LoadNotLoader 27 program load that is not a signed loader+ LoadNotLoader 21 program load that is not a signed loaderMapCreate 1 map creation by another executable- BpfCommand 12 detach, update, delete or unclassified bpf() command+ BpfCommand 10 detach, update, delete or unclassified bpf() commandSealPtrace 7 ptrace of a shirudo taskKeyring (.bpf):- Serial: 420195959- Frozen serial: 420195959 (matches)+ Serial: 130847582+ Frozen serial: 130847582 (matches)Certificates: 2 trusted, 0 revoked, 0 unvouched, 2 in the bpf keyring- 2edb279c05efee6b489a65ae07fd6d402a54b6e495be68f6d364544e9b5a37e2- d1dc6624ee6bd0c277864fab0a8a15f8509308aa2338768cb772117c157f8d61 (primary)+ d1bc43c91b9dabf4cd6f3ddf08a177927b3dac8ca833ddc496167253761b4497 (primary)+ CN=shirudo, ML-DSA-87, valid 2026-10-29 to 2036-10-26+ key 199275792 shirudo: 6ec99b4c3d1c51e461ce1299fae6ab87d212ce9c (frozen)+ c1c30b07f86808e81ae1c0458c926f00b85bcc815d371d23d7683903f2d3266e+ CN=shirudo, ML-DSA-87, valid 2026-10-29 to 2036-10-26+ key 106884895 shirudo: c350bd270c426c5760b202062e15e274ea30f45d (frozen)++ Keyring (.dm-verity):+ Serial: 962472513+ Frozen serial: 962472513 (matches)+ Certificates: 1 trusted, 1 in the dm-verity keyring+ d1bc43c91b9dabf4cd6f3ddf08a177927b3dac8ca833ddc496167253761b4497 (config)+ CN=shirudo, ML-DSA-87, valid 2026-10-29 to 2036-10-26+ key 200951639 shirudo: 6ec99b4c3d1c51e461ce1299fae6ab87d212ce9c (frozen)upatches loaded (1):NAME LOCATION MAPS STATUS AGE- shirudo-test-basic fentry/do_nanosleep 0 success 1s+ shirudo-test-basic fentry/do_nanosleep 0 success 2sTPM Measurement:TPM: reachable (device:/dev/tpmrm0)NV index: 0x01818E00 (anchored in PCR 9)- Chain: c50b22ac27c5bb6a90ee5ff9b440fbbd5bb60b84a2aa7b395daec3f330886fcd- Register name: 000be3a552e2219550d2597ab96f3fffdeec0d01ce27cde858e0858ab0cdaba6c045+ Chain: 0307d216caac3067fe645d4a548b25ac5ed0f1e8cf5ae3b189feaefc47e81a84+ Register name: 000b9b7b0f925415fdf0d5676369f8cc9146b9e3142537148b31e79dbffcc96e72f8Anchored: yes (name on record)PCR before init: 0000000000000000000000000000000000000000000000000000000000000000Phase at init: 0000000000000000000000000000000000000000000000000000000000000000 (PCR 11)@@ -153,11 +165,13 @@ verdict is derived from them.- The ``lsm/bpf`` link is pinned. ``ALERT`` ``lsm/bpf absent --enforcement OFF`` means enforcement did not come up this boot.* - ``KeyringSealed``- - The live ``.bpf`` keyring is the one ``init`` sealed and recorded- in the frozen identity map. ``WARN`` ``shirudo keyring absent- (not init'd?)`` before ``init``. ``ALERT`` ``pin serial=<pinned>- != live serial=<live> (swapped?)`` or ``pin serial=<pinned>, the- BPF keyring is gone (removed?)`` after it.+ - The live ``.bpf`` and ``.dm-verity`` keyrings are the ones+ ``init`` sealed and recorded in the frozen identity map, they+ hold no link ``init`` did not freeze, and ``.dm-verity`` still+ holds the config key. ``WARN`` ``shirudo keyring absent (not+ init'd?)`` before ``init``. ``ALERT`` after it names the keyring+ and what changed: a swapped or missing keyring, links ``init``+ did not freeze, or the missing config key.* - ``ChainIntact``- The live register is the NV index ``init`` bound this boot, wasbound once, and equals this boot's eventlog records replayed.@@ -182,24 +196,48 @@ means every counter is zero. ``(none recorded: init has not pinned thecounters this boot)`` means ``init`` did not get that far.:ref:`status-tamper-counters` explains how to read them.-Keyring-~~~~~~~+Keyrings+~~~~~~~~++Two sections, ``Keyring (.bpf)`` for the keys that verify signed+loaders and ``Keyring (.dm-verity)`` for the key that verifies config+roots, read the same way.``Serial``- The serial of the kernel's ``.bpf`` keyring.+ The serial of the kernel's keyring.``Frozen serial``The serial ``init`` recorded when it sealed the keyring, followed by``(matches)``, ``(MISMATCH -- swapped?)`` or ``(GONE -- removed?)``.``Certificates``- The trusted set: the runtime image's primary certificate and the- vouched certificates of the active signed config, less its- revocations. ``unvouched`` counts certificates in the config that- have no valid vouch and are therefore not members. The last number- counts the keys in the ``.bpf`` keyring itself. Each member's public- key fingerprint follows, the runtime image's certificate marked- ``(primary)``. :doc:`/operate/keys` explains the set.+ The certificates the keyring should hold, and how many keys it+ holds. For ``.bpf`` this is the trusted set: the runtime image's+ primary certificate and the vouched certificates of the active+ signed config, less its revocations; ``unvouched`` counts+ certificates in the config without a valid vouch, which are+ therefore not members. :doc:`/operate/keys` explains the set. For+ ``.dm-verity`` it is the config certificate the runtime image names,+ marked ``(config)``.++ Each certificate follows with its public key fingerprint, the+ runtime image's ``.bpf`` certificate marked ``(primary)``, and two+ lines below it. The first gives the subject, the key algorithm and+ the validity dates, which the kernel does not compare with the+ clock. The second is the key that holds the certificate in the+ keyring, by serial and the kernel's description, ``(frozen)`` when+ ``init`` recorded it. ``not in the keyring (enrolled at the next+ boot)`` marks a ``.bpf`` certificate a config update added after the+ boot; ``not in the keyring (MISSING)`` under ``.dm-verity`` means the+ config key is gone.++``Other links``+ Shown only when the keyring holds a link that is no certificate's+ key. Each line names the kind of link, ``key`` for a public key or+ the kernel's type such as ``keyring``, its serial and description,+ and ``(NOT frozen)`` when ``init`` did not record it. The kernel+ trusts every key such a link reaches, so ``KeyringSealed`` is+ ``ALERT`` and the verdict ``tampered``.upatches loaded~~~~~~~~~~~~~~~@@ -382,6 +420,22 @@ The keyring ``init`` sealed is gone:...KeyringSealed ALERT pin serial=<pinned>, the BPF keyring is gone (removed?)+The same for ``.dm-verity`` reads ``dm-verity keyring serial swap+detected`` or ``the dm-verity keyring init froze is gone``.++A keyring holds a link ``init`` did not freeze, which the kernel trusts+for signatures from then on:++.. code-block:: text++ Status: tampered (a keyring holds a link init did not freeze)+ ...+ KeyringSealed ALERT the dm-verity keyring holds 1 link init did not freeze++The keyring section lists that link under ``Other links`` with+``(NOT frozen)``. If instead the config key is gone from+``.dm-verity``, the reason is ``the config key init froze is gone``.+The config cannot be verified against its records:.. code-block:: text@@ -610,6 +664,11 @@ The fields that matter for monitoring:``Key was rejected by service``.* - ``keyring_serial_matches``- It is ``false``.+ * - ``bpf_keyring.serial_matches`` and+ ``dm_verity_keyring.serial_matches``+ - Either is ``false``.+ * - ``other_links[].frozen`` in either keyring+ - Any is ``false``.* - ``tpm.register_bound`` and ``tpm.register_anchored``- Either is ``false``.* - ``tpm.chain_matches_eventlog``diff --git a/Documentation/reference/cli/status.rst b/Documentation/reference/cli/status.rstindex 6c09f00c..131e8360 100644--- a/Documentation/reference/cli/status.rst+++ b/Documentation/reference/cli/status.rst@@ -52,8 +52,10 @@ The report shows five conditions, each ``OK``, ``WARN`` or ``ALERT``:- Applies when* - ``tampered``- The live register differs from the eventlog replay, the ``.bpf``- keyring is not the one ``init`` froze or is gone, or the selected- config cannot be verified against its records.+ or ``.dm-verity`` keyring is not the one ``init`` froze or is+ gone, a keyring holds a link ``init`` did not freeze, the config+ key is gone from ``.dm-verity``, or the selected config cannot be+ verified against its records.* - ``lsm-off``- The LSM link is not pinned.* - ``init-pending``@@ -66,8 +68,9 @@ The report shows five conditions, each ``OK``, ``WARN`` or ``ALERT``:- None of the above.The human report follows the verdict with the tamper counters that moved-this boot, the ``.bpf`` keyring and the trusted certificates, the loaded-upatches, the TPM measurement state and the assets under+this boot, the ``.bpf`` and ``.dm-verity`` keyrings with the+certificates each should hold and the key that holds each one, the+loaded upatches, the TPM measurement state and the assets under``/var/lib/shirudo``. :doc:`/operate/read-status` explains each field and:doc:`/reference/formats/status-json` the JSON document.@@ -149,8 +152,10 @@ Files and environment---------------------- Reads ``/run/shirudo/bpffs`` (pins, identity, tamper counters), the- ``.bpf`` keyring, the TPM register, ``/var/lib/shirudo/eventlog``,- ``/var/lib/shirudo/keys`` and the config activation records.+ ``.bpf`` and ``.dm-verity`` keyrings, the TPM register,+ ``/var/lib/shirudo/eventlog``, ``/var/lib/shirudo/keys``, the config+ certificate the runtime image's bootstrap names and the config+ activation records.- With ``--otel``: ``map_export.*`` and the ``OTEL_EXPORTER_OTLP_*``variables (see :doc:`/reference/environment`).``shirudo-keepalive.service`` reads them from@@ -168,38 +173,50 @@ Show the state of a target:Roles: targetMode: productionStatus: ok- Version-ID: 58b05ab35a2bcefaa649faf15f8c6be0211e24cea710450c1a29298c3b5c7de0+ Version-ID: 447b34bc8bc5547334ced4c737f987a9d3f8f03e332cf234626f0b81b5955064Conditions:TYPE STATUS DETAILLsmAttached OK lsm/bpf link present and pinned- KeyringSealed OK serial=420195959 in the BPF keyring, pin matches+ KeyringSealed OK bpf serial=130847582, dm-verity serial=962472513, pins matchChainIntact OK live register == eventlog replayTpmMeasured OK NV index 0x01818E00 readable- ConfigActive OK config 12dbf3c75083.. is active+ ConfigActive OK config dc90bacc356f.. is activeTamper attempts (refused this boot):- LoadNotLoader 27 program load that is not a signed loader+ LoadNotLoader 21 program load that is not a signed loaderMapCreate 1 map creation by another executable- BpfCommand 12 detach, update, delete or unclassified bpf() command+ BpfCommand 10 detach, update, delete or unclassified bpf() commandSealPtrace 7 ptrace of a shirudo taskKeyring (.bpf):- Serial: 420195959- Frozen serial: 420195959 (matches)+ Serial: 130847582+ Frozen serial: 130847582 (matches)Certificates: 2 trusted, 0 revoked, 0 unvouched, 2 in the bpf keyring- 2edb279c05efee6b489a65ae07fd6d402a54b6e495be68f6d364544e9b5a37e2- d1dc6624ee6bd0c277864fab0a8a15f8509308aa2338768cb772117c157f8d61 (primary)+ d1bc43c91b9dabf4cd6f3ddf08a177927b3dac8ca833ddc496167253761b4497 (primary)+ CN=shirudo, ML-DSA-87, valid 2026-10-29 to 2036-10-26+ key 199275792 shirudo: 6ec99b4c3d1c51e461ce1299fae6ab87d212ce9c (frozen)+ c1c30b07f86808e81ae1c0458c926f00b85bcc815d371d23d7683903f2d3266e+ CN=shirudo, ML-DSA-87, valid 2026-10-29 to 2036-10-26+ key 106884895 shirudo: c350bd270c426c5760b202062e15e274ea30f45d (frozen)++ Keyring (.dm-verity):+ Serial: 962472513+ Frozen serial: 962472513 (matches)+ Certificates: 1 trusted, 1 in the dm-verity keyring+ d1bc43c91b9dabf4cd6f3ddf08a177927b3dac8ca833ddc496167253761b4497 (config)+ CN=shirudo, ML-DSA-87, valid 2026-10-29 to 2036-10-26+ key 200951639 shirudo: 6ec99b4c3d1c51e461ce1299fae6ab87d212ce9c (frozen)upatches loaded (1):NAME LOCATION MAPS STATUS AGE- shirudo-test-basic fentry/do_nanosleep 0 success 1s+ shirudo-test-basic fentry/do_nanosleep 0 success 2sTPM Measurement:TPM: reachable (device:/dev/tpmrm0)NV index: 0x01818E00 (anchored in PCR 9)- Chain: c50b22ac27c5bb6a90ee5ff9b440fbbd5bb60b84a2aa7b395daec3f330886fcd- Register name: 000be3a552e2219550d2597ab96f3fffdeec0d01ce27cde858e0858ab0cdaba6c045+ Chain: 0307d216caac3067fe645d4a548b25ac5ed0f1e8cf5ae3b189feaefc47e81a84+ Register name: 000b9b7b0f925415fdf0d5676369f8cc9146b9e3142537148b31e79dbffcc96e72f8Anchored: yes (name on record)PCR before init: 0000000000000000000000000000000000000000000000000000000000000000Phase at init: 0000000000000000000000000000000000000000000000000000000000000000 (PCR 11)diff --git a/Documentation/reference/formats/status-json.rst b/Documentation/reference/formats/status-json.rstindex 9e50c79e..45927d5f 100644--- a/Documentation/reference/formats/status-json.rst+++ b/Documentation/reference/formats/status-json.rst@@ -100,6 +100,14 @@ determined, as noted.- integer or ``null``- Asymmetric keys in the ``.bpf`` keyring. ``null`` when thekeyring is absent.+ * - ``bpf_keyring``+ - object+ - The ``.bpf`` keyring, its trusted certificates and their keys,+ see `Keyrings`_.+ * - ``dm_verity_keyring``+ - object+ - The ``.dm-verity`` keyring, the config certificate and its key,+ see `Keyrings`_.* - ``signing_key_present``- boolean- Same value as ``is_operator``.@@ -147,8 +155,10 @@ Verdicts- Condition* - ``tampered``- The live register differs from the eventlog replay, the- ``.bpf`` keyring's serial differs from the pinned serial, the- keyring ``init`` pinned is gone, or the selected config cannot be+ ``.bpf`` or ``.dm-verity`` keyring's serial differs from the+ pinned serial, a keyring ``init`` pinned is gone, a keyring holds+ a link ``init`` did not freeze, the config key ``init`` froze is+ gone from ``.dm-verity``, or the selected config cannot beverified against its activation records.* - ``lsm-off``- The LSM link is not pinned. Enforcement is off.@@ -166,8 +176,10 @@ Conditions----------``conditions`` always holds these five types, in this order. ``status``-is ``OK``, ``WARN`` or ``ALERT``. ``<serial>`` and ``<root>`` stand for-a keyring serial and the first 12 hex digits of the config root hash.+is ``OK``, ``WARN`` or ``ALERT``. ``<serial>``, ``<n>`` and ``<root>``+stand for a keyring serial, a number of links and the first 12 hex+digits of the config root hash. ``KeyringSealed`` reports the first of+its details that applies, in the order listed... list-table:::header-rows: 1@@ -183,17 +195,34 @@ a keyring serial and the first 12 hex digits of the config root hash.- ``ALERT``- ``lsm/bpf absent -- enforcement OFF``* - ``KeyringSealed``- - ``OK``- - ``serial=<serial> in the BPF keyring, pin matches``+ - ``ALERT``+ - ``pin serial=<serial>, the BPF keyring is gone (removed?)``* -- ``WARN``- ``shirudo keyring absent (not init'd?)``* -- ``ALERT``- - ``pin serial=<serial>, the BPF keyring is gone (removed?)``+ - ``pin serial=<serial> != live serial=<serial> (swapped?)``* -- ``ALERT``- - ``pin serial=<serial> != live serial=<serial> (swapped?)``+ - ``the BPF keyring holds <n> link(s) init did not freeze``+ * -+ - ``ALERT``+ - ``dm-verity pin serial=<serial>, the dm-verity keyring is gone+ (removed?)``+ * -+ - ``ALERT``+ - ``dm-verity pin serial=<serial> != live serial=<serial>+ (swapped?)``+ * -+ - ``ALERT``+ - ``the dm-verity keyring holds <n> link(s) init did not freeze``+ * -+ - ``ALERT``+ - ``the config key init froze is gone from the dm-verity keyring``+ * -+ - ``OK``+ - ``bpf serial=<serial>, dm-verity serial=<serial>, pins match``* - ``ChainIntact``- ``OK``- ``live register == eventlog replay``@@ -237,6 +266,96 @@ a keyring serial and the first 12 hex digits of the config root hash.- ``the config PCR, activation records and mounted config disagree(tamper?)``+Keyrings+--------++``bpf_keyring`` and ``dm_verity_keyring`` have the same shape. A link+is one entry of the keyring: the key of a certificate, or anything else+the keyring holds, another keyring included (see+:doc:`/concepts/background/keyrings`). A link is frozen when ``init``+recorded its serial: every key of ``.bpf`` and the config key of+``.dm-verity``.++.. list-table::+ :header-rows: 1+ :widths: 22 18 60++ * - Field+ - Type+ - Value+ * - ``present``+ - boolean+ - ``true`` when ``init`` recorded the keyring and it exists.+ * - ``serial``+ - integer or ``null``+ - Serial of the live keyring. ``null`` when it is absent.+ * - ``serial_pinned``+ - integer or ``null``+ - Serial ``init`` froze in the identity pin. ``null`` before+ ``init``.+ * - ``serial_matches``+ - boolean or ``null``+ - ``serial`` equals ``serial_pinned``. ``null`` unless both are+ known.+ * - ``certs``+ - array of object+ - The certificates the keyring should hold: the trusted set for+ ``.bpf``, the config certificate the runtime image names for+ ``.dm-verity``. Each is described below.+ * - ``other_links``+ - array of object+ - Every link that holds none of ``certs``, each with ``serial``,+ ``type`` (``asymmetric``, ``keyring`` and so on), ``description``+ and ``frozen``. ``type`` and ``description`` are ``null`` for a+ link shirudo cannot describe. Empty on a healthy target.++Each entry of ``certs``:++.. list-table::+ :header-rows: 1+ :widths: 22 18 60++ * - Field+ - Type+ - Value+ * - ``sha256``+ - string+ - SHA-256 of the certificate's DER file.+ * - ``fingerprint``+ - string+ - SHA-256 of its public key.+ * - ``primary``+ - boolean+ - In ``bpf_keyring`` only: the runtime image's certificate.+ * - ``config``+ - boolean+ - In ``dm_verity_keyring`` only: always ``true``.+ * - ``subject``+ - string or ``null``+ - The certificate's subject on one line, for example+ ``CN=shirudo``.+ * - ``algorithm``+ - string or ``null``+ - The public key algorithm, for example ``ML-DSA-87``.+ * - ``not_before``, ``not_after``+ - string or ``null``+ - The validity dates, ``YYYY-MM-DD`` in UTC. The kernel does not+ compare them with the clock.+ * - ``key_serial``+ - integer or ``null``+ - Serial of the key in the keyring that holds the certificate.+ ``null`` when the keyring holds none: for ``.bpf`` a certificate+ added by a config update, enrolled at the next boot.+ * - ``key_description``+ - string or ``null``+ - The kernel's description of that key, ``<subject>: <key id>``.+ * - ``frozen``+ - boolean or ``null``+ - ``init`` froze that key. ``null`` without a key.++``subject``, ``algorithm`` and the dates are ``null`` when the+certificate cannot be parsed.+upatches_loaded---------------@@ -521,6 +640,12 @@ Fields to alert on* - ``keyring_serial_matches``- ``false``- The ``.bpf`` keyring was replaced.+ * - ``bpf_keyring.serial_matches``, ``dm_verity_keyring.serial_matches``+ - ``false``+ - The keyring was replaced.+ * - ``other_links[].frozen`` in either keyring+ - ``false``+ - A link ``init`` did not freeze is trusted for signatures.* - ``tpm.chain_matches_eventlog``- ``false``- The register and the eventlog disagree.@@ -556,7 +681,7 @@ indented here:{"schema": 1,- "version_id": "58b05ab35a2bcefaa649faf15f8c6be0211e24cea710450c1a29298c3b5c7de0",+ "version_id": "447b34bc8bc5547334ced4c737f987a9d3f8f03e332cf234626f0b81b5955064","is_target": true,"is_operator": false,"status": "ok",@@ -569,7 +694,7 @@ indented here:{"type": "KeyringSealed","status": "OK",- "detail": "serial=420195959 in the BPF keyring, pin matches"+ "detail": "bpf serial=130847582, dm-verity serial=962472513, pins match"},{"type": "ChainIntact",@@ -584,32 +709,86 @@ indented here:{"type": "ConfigActive","status": "OK",- "detail": "config 12dbf3c75083.. is active"+ "detail": "config dc90bacc356f.. is active"}],"lsm_attached": true,"mode": "production","keyring_mode": "bpf","keyring_present": true,- "keyring_serial": 420195959,- "keyring_serial_pinned": 420195959,+ "keyring_serial": 130847582,+ "keyring_serial_pinned": 130847582,"keyring_serial_matches": true,"cert_present": true,"certs": [{- "sha256": "3702e8ffe817ade6151eea338194649cc3a5be1e0b940e462a1a75e52f7095d0",- "fingerprint": "2edb279c05efee6b489a65ae07fd6d402a54b6e495be68f6d364544e9b5a37e2",- "primary": false+ "sha256": "08915eb1c67b2446e3708d766f0c5acb5d6ef2f71606cd27a28ce7a1f8c22815",+ "fingerprint": "d1bc43c91b9dabf4cd6f3ddf08a177927b3dac8ca833ddc496167253761b4497",+ "primary": true},{- "sha256": "d95db97ff4658b96b8b538afef41a25ca9f7a2c4d0abffdb26cbac7b0ba294b9",- "fingerprint": "d1dc6624ee6bd0c277864fab0a8a15f8509308aa2338768cb772117c157f8d61",- "primary": true+ "sha256": "f2b0444aa3873b394afda3d222a20dc6506ebfb33e07ac17a7e2069bdabb3126",+ "fingerprint": "c1c30b07f86808e81ae1c0458c926f00b85bcc815d371d23d7683903f2d3266e",+ "primary": false}],"certs_revoked": 0,"certs_unvouched": 0,"certs_enrolled": 2,+ "bpf_keyring": {+ "present": true,+ "serial": 130847582,+ "serial_pinned": 130847582,+ "serial_matches": true,+ "certs": [+ {+ "sha256": "08915eb1c67b2446e3708d766f0c5acb5d6ef2f71606cd27a28ce7a1f8c22815",+ "fingerprint": "d1bc43c91b9dabf4cd6f3ddf08a177927b3dac8ca833ddc496167253761b4497",+ "primary": true,+ "subject": "CN=shirudo",+ "algorithm": "ML-DSA-87",+ "not_before": "2026-10-29",+ "not_after": "2036-10-26",+ "key_serial": 199275792,+ "key_description": "shirudo: 6ec99b4c3d1c51e461ce1299fae6ab87d212ce9c",+ "frozen": true+ },+ {+ "sha256": "f2b0444aa3873b394afda3d222a20dc6506ebfb33e07ac17a7e2069bdabb3126",+ "fingerprint": "c1c30b07f86808e81ae1c0458c926f00b85bcc815d371d23d7683903f2d3266e",+ "primary": false,+ "subject": "CN=shirudo",+ "algorithm": "ML-DSA-87",+ "not_before": "2026-10-29",+ "not_after": "2036-10-26",+ "key_serial": 106884895,+ "key_description": "shirudo: c350bd270c426c5760b202062e15e274ea30f45d",+ "frozen": true+ }+ ],+ "other_links": []+ },+ "dm_verity_keyring": {+ "present": true,+ "serial": 962472513,+ "serial_pinned": 962472513,+ "serial_matches": true,+ "certs": [+ {+ "sha256": "08915eb1c67b2446e3708d766f0c5acb5d6ef2f71606cd27a28ce7a1f8c22815",+ "fingerprint": "d1bc43c91b9dabf4cd6f3ddf08a177927b3dac8ca833ddc496167253761b4497",+ "config": true,+ "subject": "CN=shirudo",+ "algorithm": "ML-DSA-87",+ "not_before": "2026-10-29",+ "not_after": "2036-10-26",+ "key_serial": 200951639,+ "key_description": "shirudo: 6ec99b4c3d1c51e461ce1299fae6ab87d212ce9c",+ "frozen": true+ }+ ],+ "other_links": []+ },"signing_key_present": false,"upatches_loaded": [{@@ -617,8 +796,8 @@ indented here:"location": "fentry/do_nanosleep","status": "success","n_maps": 0,- "loaded_at": "2026-10-29T16:21:18Z",- "age_sec": 1,+ "loaded_at": "2026-10-29T21:29:10Z",+ "age_sec": 2,"payload_sha256": "8aee7072a1a15e4dddc93ad6b253a0e2e70ad6cdf767442aa8a1c1997bc3069f"}],@@ -633,11 +812,11 @@ indented here:"bpffs_mounted": true},"tamper_attempts": {- "total": 47,+ "total": 39,"counters": {- "LoadNotLoader": 27, "LoadUnsigned": 0, "LoadUnverified": 0, "LoadKeyringKind": 0,+ "LoadNotLoader": 21, "LoadUnsigned": 0, "LoadUnverified": 0, "LoadKeyringKind": 0,"LoadKeyring": 0, "MapCreate": 1, "MapWrite": 0, "MapFdWrite": 0,- "ProgRun": 0, "ProgAttach": 0, "ObjPin": 0, "BpfCommand": 12,+ "ProgRun": 0, "ProgAttach": 0, "ObjPin": 0, "BpfCommand": 10,"ExeIdentity": 0, "KeyringWrite": 0, "PinUnlink": 0, "PinRename": 0,"PinXattr": 0, "BpffsUmount": 0, "BpffsUmountAbove": 0, "BpffsMount": 0,"SealWrite": 0, "SealUnlink": 0, "SealRename": 0, "SealSetattr": 0,@@ -647,15 +826,15 @@ indented here:}},"config": {- "root_hash": "12dbf3c750834908c0f6510481e35fbb0cc76cf6b1896de524304535e63aff0f",+ "root_hash": "dc90bacc356f04c2e34a2f3c00c13c2a555c7cc5ee7cdc57fd568f2b44910c99","activation_pending": false,"error": null},"tpm": {"reachable": true,"nv_index": "0x01818E00",- "chain": "c50b22ac27c5bb6a90ee5ff9b440fbbd5bb60b84a2aa7b395daec3f330886fcd",- "nv_name": "000be3a552e2219550d2597ab96f3fffdeec0d01ce27cde858e0858ab0cdaba6c045",+ "chain": "0307d216caac3067fe645d4a548b25ac5ed0f1e8cf5ae3b189feaefc47e81a84",+ "nv_name": "000b9b7b0f925415fdf0d5676369f8cc9146b9e3142537148b31e79dbffcc96e72f8","register_bound": true,"register_anchored": true,"init_records": 1,@@ -688,17 +867,17 @@ of the same target read:.. code-block:: json{- "total": 73,+ "total": 51,"counters": {- "LoadNotLoader": 39, "LoadUnsigned": 0, "LoadUnverified": 0, "LoadKeyringKind": 0,+ "LoadNotLoader": 27, "LoadUnsigned": 0, "LoadUnverified": 0, "LoadKeyringKind": 0,"LoadKeyring": 0, "MapCreate": 1, "MapWrite": 0, "MapFdWrite": 0,- "ProgRun": 0, "ProgAttach": 0, "ObjPin": 0, "BpfCommand": 16,+ "ProgRun": 0, "ProgAttach": 0, "ObjPin": 0, "BpfCommand": 12,"ExeIdentity": 0, "KeyringWrite": 0, "PinUnlink": 1, "PinRename": 0,"PinXattr": 0, "BpffsUmount": 1, "BpffsUmountAbove": 0, "BpffsMount": 0,"SealWrite": 1, "SealUnlink": 0, "SealRename": 0, "SealSetattr": 0,- "SealXattr": 0, "SealLabel": 0, "SealPtrace": 12, "SealPerf": 0,+ "SealXattr": 0, "SealLabel": 0, "SealPtrace": 7, "SealPerf": 0,"ExecTraced": 0, "SealEntry": 0, "PerfAttach": 0, "PinEntry": 0,- "SealCopyUp": 0, "Kexec": 0, "TpmExtend": 0, "ObjGet": 2+ "SealCopyUp": 0, "Kexec": 0, "TpmExtend": 0, "ObjGet": 1}}diff --git a/Documentation/start/quickstart.rst b/Documentation/start/quickstart.rstindex d01e10d5..f1a214de 100644--- a/Documentation/start/quickstart.rst+++ b/Documentation/start/quickstart.rst@@ -152,15 +152,15 @@ Check enforcementRoles: targetMode: productionStatus: ok- Version-ID: 58b05ab35a2bcefaa649faf15f8c6be0211e24cea710450c1a29298c3b5c7de0+ Version-ID: 447b34bc8bc5547334ced4c737f987a9d3f8f03e332cf234626f0b81b5955064Conditions:TYPE STATUS DETAILLsmAttached OK lsm/bpf link present and pinned- KeyringSealed OK serial=531121468 in the BPF keyring, pin matches+ KeyringSealed OK bpf serial=130847582, dm-verity serial=962472513, pins matchChainIntact OK live register == eventlog replayTpmMeasured OK NV index 0x01818E00 readable- ConfigActive OK config 12dbf3c75083.. is active+ ConfigActive OK config dc90bacc356f.. is activeTamper attempts (refused this boot):LoadNotLoader 15 program load that is not a signed loader@@ -169,19 +169,31 @@ Check enforcementSealPtrace 6 ptrace of a shirudo taskKeyring (.bpf):- Serial: 531121468- Frozen serial: 531121468 (matches)+ Serial: 130847582+ Frozen serial: 130847582 (matches)Certificates: 2 trusted, 0 revoked, 0 unvouched, 2 in the bpf keyring- 2edb279c05efee6b489a65ae07fd6d402a54b6e495be68f6d364544e9b5a37e2- d1dc6624ee6bd0c277864fab0a8a15f8509308aa2338768cb772117c157f8d61 (primary)+ d1bc43c91b9dabf4cd6f3ddf08a177927b3dac8ca833ddc496167253761b4497 (primary)+ CN=shirudo, ML-DSA-87, valid 2026-10-29 to 2036-10-26+ key 199275792 shirudo: 6ec99b4c3d1c51e461ce1299fae6ab87d212ce9c (frozen)+ c1c30b07f86808e81ae1c0458c926f00b85bcc815d371d23d7683903f2d3266e+ CN=shirudo, ML-DSA-87, valid 2026-10-29 to 2036-10-26+ key 106884895 shirudo: c350bd270c426c5760b202062e15e274ea30f45d (frozen)++ Keyring (.dm-verity):+ Serial: 962472513+ Frozen serial: 962472513 (matches)+ Certificates: 1 trusted, 1 in the dm-verity keyring+ d1bc43c91b9dabf4cd6f3ddf08a177927b3dac8ca833ddc496167253761b4497 (config)+ CN=shirudo, ML-DSA-87, valid 2026-10-29 to 2036-10-26+ key 200951639 shirudo: 6ec99b4c3d1c51e461ce1299fae6ab87d212ce9c (frozen)upatches loaded (0):TPM Measurement:TPM: reachable (device:/dev/tpmrm0)NV index: 0x01818E00 (anchored in PCR 9)- Chain: d1bdb80f7c0cfc1560f0a5a0b974d282bfd05fc95852b7649d59a054b450aa51- Register name: 000ba2eb9b8bacc4945436016666062d11be813365bf252841e557b34d5fe3ffae1a+ Chain: dc21c3dabcd2fd0a751c7146ad71c595f2386a4406feb64c3d6e2bd65c5bc706+ Register name: 000b9b7b0f925415fdf0d5676369f8cc9146b9e3142537148b31e79dbffcc96e72f8Anchored: yes (name on record)PCR before init: 0000000000000000000000000000000000000000000000000000000000000000Phase at init: 0000000000000000000000000000000000000000000000000000000000000000 (PCR 11)diff --git a/builtin-status.c b/builtin-status.cindex 816e766e..5c4a8468 100644--- a/builtin-status.c+++ b/builtin-status.c@@ -33,6 +33,7 @@#include "util/bpm_tree.h"#include "util/conditions.h"#include "util/config.h"+#include "util/crypto.h"#include "util/eventlog.h"#define SHIRUDO_KERNEL_LOG_MAX 100@@ -41,6 +42,7 @@#include "util/json.h"#include "util/macros.h"#include "util/identity.h"+#include "util/image_bootstrap.h"#include "util/image_runtime.h"#include "util/keyring.h"#include "util/keys.h"@@ -492,15 +494,365 @@ static bool status_otel_endpoint_configured(const struct shirudo_config *cfg)return endpoint && endpoint[0];}-static void count_asymmetric(key_serial_t serial, const char *type,- const char *description, void *ud)+#define STATUS_SUBJECT_MAX 256++/* A certificate a keyring should hold, and the link that holds it. */+struct status_cert {+ __u8 sha256[32];+ __u8 fingerprint[32];+ bool primary;+ int info_rc;+ char subject[STATUS_SUBJECT_MAX];+ char algorithm[32];+ char not_before[11];+ char not_after[11];+ long link; /* into the keyring's links, or -1 */+};++struct status_link {+ bool frozen;+ bool cert; /* holds one of the certificates */+};++/*+ * A keyring init froze: its live and frozen serials, every link it holds+ * and which of those init froze, and the certificates it should hold.+ */+struct status_keyring {+ key_serial_t serial; /* live, or -errno */+ key_serial_t pinned; /* frozen, 0 for none, -errno */+ struct keyring_link *links;+ struct status_link *state;+ size_t n_links;+ int links_rc;+ struct status_cert certs[SHIRUDO_KEYS_MAX];+ size_t n_certs;+ int certs_rc;+ size_t n_unfrozen;+ size_t n_asymmetric;+ bool key_missing;+};++static void keyring_view_links(struct status_keyring *k,+ const __s32 *frozen, size_t n_frozen)+{+ size_t i, j;++ k->links_rc = k->serial >= 0 ?+ keyring_links(k->serial, &k->links, &k->n_links) :+ k->serial;+ if (k->links_rc || !k->n_links)+ return;+ k->state = xcalloc(k->n_links, sizeof(*k->state));+ if (!k->state) {+ xfree(k->links, k->n_links * sizeof(*k->links));+ k->links = NULL;+ k->n_links = 0;+ k->links_rc = -ENOMEM;+ return;+ }+ for (i = 0; i < k->n_links; i++) {+ for (j = 0; j < n_frozen; j++)+ if (k->links[i].serial == frozen[j])+ k->state[i].frozen = true;+ if (!k->state[i].frozen)+ k->n_unfrozen++;+ if (!k->links[i].err &&+ !strcmp(k->links[i].type, "asymmetric"))+ k->n_asymmetric++;+ }+}++static void keyring_view_free(struct status_keyring *k)+{+ if (k->links)+ xfree(k->links, k->n_links * sizeof(*k->links));+ if (k->state)+ xfree(k->state, k->n_links * sizeof(*k->state));+}++/* Its subject, key and dates, and the link whose key it is. */+static void keyring_view_cert(struct status_keyring *k, struct status_cert *c,+ const __u8 *der, size_t len)+{+ struct shirudo_cert cert = {};+ char desc[KEYRING_DESC_MAX];+ size_t i;++ c->link = -1;+ c->info_rc = cert_read_der(der, len, &cert);+ if (!c->info_rc) {+ c->info_rc = cert_subject(&cert, c->subject,+ sizeof(c->subject));+ if (!c->info_rc)+ c->info_rc = cert_key_algorithm(&cert, c->algorithm,+ sizeof(c->algorithm));+ if (!c->info_rc)+ c->info_rc = cert_validity(&cert, c->not_before,+ c->not_after);+ cert_free(&cert);+ }+ if (k->links_rc || keyring_cert_description(der, len, desc))+ return;+ for (i = 0; i < k->n_links; i++) {+ if (k->links[i].err || k->state[i].cert ||+ strcmp(k->links[i].type, "asymmetric") ||+ strcmp(k->links[i].description, desc))+ continue;+ k->state[i].cert = true;+ c->link = (long)i;+ break;+ }+}++static void keyring_view_bpf(struct status_keyring *k,+ const struct shirudo_identity *ident,+ const struct shirudo_trusted_set *certs,+ int certs_rc)+{+ size_t i, n_frozen = 0;++ if (k->pinned >= 1)+ n_frozen = ident->n_keys < SHIRUDO_IDENTITY_KEYS_MAX ?+ ident->n_keys : SHIRUDO_IDENTITY_KEYS_MAX;+ keyring_view_links(k, ident->key_serials, n_frozen);+ k->certs_rc = certs_rc;+ for (i = 0; certs_rc == 0 && i < certs->n; i++) {+ struct status_cert *c = &k->certs[k->n_certs++];+ const __u8 *der;+ size_t len;++ memcpy(c->sha256, certs->certs[i].sha256, 32);+ memcpy(c->fingerprint, certs->certs[i].fingerprint, 32);+ c->primary = certs->certs[i].primary;+ c->link = -1;+ c->info_rc = keys_cert_der(&certs->certs[i], &der, &len);+ if (!c->info_rc)+ keyring_view_cert(k, c, der, len);+ }+}++/* The config certificate comes from the runtime image's bootstrap. */+static void keyring_view_dm_verity(struct status_keyring *k,+ const struct shirudo_identity *ident)+{+ struct shirudo_image_bootstrap boot = {};+ struct status_cert *c = &k->certs[0];+ __u8 *der = NULL;+ size_t len = 0;+ size_t i;++ keyring_view_links(k, &ident->dm_verity_key,+ k->pinned >= 1 && ident->dm_verity_key > 0);+ if (!k->links_rc && k->pinned >= 1 && ident->dm_verity_key > 0) {+ k->key_missing = true;+ for (i = 0; i < k->n_links; i++)+ if (k->links[i].serial == ident->dm_verity_key)+ k->key_missing = false;+ }+ k->certs_rc = shirudo_image_bootstrap_read(SHIRUDO_RUNTIME_CONF_PATH,+ &boot, false);+ if (!k->certs_rc && !boot.certificate[0])+ k->certs_rc = -ENOENT;+ if (!k->certs_rc)+ k->certs_rc = keys_read_der(boot.certificate, &der, &len);+ if (!k->certs_rc)+ k->certs_rc = keys_digest_der(der, len, c->sha256,+ c->fingerprint);+ if (!k->certs_rc) {+ c->primary = true;+ k->n_certs = 1;+ keyring_view_cert(k, c, der, len);+ }+ if (der)+ xfree(der, len);+}++static void keyring_cond_input(struct shirudo_conditions_input *in,+ const struct status_keyring *bpf,+ const struct status_keyring *dmv)+{+ in->bpf_unfrozen = (int)bpf->n_unfrozen;+ in->dmv_present = dmv->serial >= 0;+ in->dmv_serial = dmv->serial;+ in->dmvp_seen = dmv->pinned >= 1;+ in->dmv_serial_pinned = in->dmvp_seen ? dmv->pinned : 0;+ in->dmvm_seen = in->dmv_present && in->dmvp_seen;+ in->dmv_serial_matches = in->dmvm_seen && dmv->serial == dmv->pinned;+ in->dmv_unfrozen = (int)dmv->n_unfrozen;+ in->dmv_key_missing = dmv->key_missing;+}++static void keyring_emit_json(struct shirudo_json_emit *e, const char *key,+ const struct status_keyring *k,+ const char *role)+{+ size_t i;++ json_obj_open_key(e, key);+ json_kv_bool(e, "present", k->serial >= 0);+ if (k->serial >= 0)+ json_kv_int(e, "serial", k->serial);+ else+ json_kv_null(e, "serial");+ if (k->pinned >= 1)+ json_kv_int(e, "serial_pinned", k->pinned);+ else+ json_kv_null(e, "serial_pinned");+ if (k->serial >= 0 && k->pinned >= 1)+ json_kv_bool(e, "serial_matches", k->serial == k->pinned);+ else+ json_kv_null(e, "serial_matches");+ json_arr_open(e, "certs");+ for (i = 0; i < k->n_certs; i++) {+ const struct status_cert *c = &k->certs[i];+ const struct keyring_link *l = c->link >= 0 ?+ &k->links[c->link] : NULL;+ char sha_hex[65], fp_hex[65];++ hex_encode(c->sha256, 32, sha_hex);+ hex_encode(c->fingerprint, 32, fp_hex);+ json_obj_open(e);+ json_kv_string(e, "sha256", sha_hex);+ json_kv_string(e, "fingerprint", fp_hex);+ json_kv_bool(e, role, c->primary);+ if (c->info_rc) {+ json_kv_null(e, "subject");+ json_kv_null(e, "algorithm");+ json_kv_null(e, "not_before");+ json_kv_null(e, "not_after");+ } else {+ json_kv_string(e, "subject", c->subject);+ json_kv_string(e, "algorithm", c->algorithm);+ json_kv_string(e, "not_before", c->not_before);+ json_kv_string(e, "not_after", c->not_after);+ }+ if (l) {+ json_kv_int(e, "key_serial", l->serial);+ json_kv_string(e, "key_description", l->description);+ json_kv_bool(e, "frozen", k->state[c->link].frozen);+ } else {+ json_kv_null(e, "key_serial");+ json_kv_null(e, "key_description");+ json_kv_null(e, "frozen");+ }+ json_obj_close(e);+ }+ json_arr_close(e);+ json_arr_open(e, "other_links");+ for (i = 0; i < k->n_links; i++) {+ const struct keyring_link *l = &k->links[i];++ if (k->state[i].cert)+ continue;+ json_obj_open(e);+ json_kv_int(e, "serial", l->serial);+ if (l->err) {+ json_kv_null(e, "type");+ json_kv_null(e, "description");+ } else {+ json_kv_string(e, "type", l->type);+ json_kv_string(e, "description", l->description);+ }+ json_kv_bool(e, "frozen", k->state[i].frozen);+ json_obj_close(e);+ }+ json_arr_close(e);+ json_obj_close(e);+}++/* Kernel descriptions carry certificate subjects: keep the terminal safe. */+static void print_safe(const char *s)+{+ for (; *s; s++)+ putchar((__u8)*s < 0x20 || *s == 0x7f ? '?' : *s);+}++static void print_link(const struct status_keyring *k, size_t i,+ const char *indent)+{+ const struct keyring_link *l = &k->links[i];++ if (l->err) {+ printf("%slink %d (cannot describe: %s)", indent,+ (int)l->serial, strerror(-l->err));+ } else {+ printf("%s%s %d ", indent,+ strcmp(l->type, "asymmetric") ? l->type : "key",+ (int)l->serial);+ print_safe(l->description);+ }+ printf(" (%s)\n", k->state[i].frozen ? "frozen" : "NOT frozen");+}++static void print_keyring_certs(const struct status_keyring *k,+ const char *role, const char *unlinked){- size_t *n = ud;+ size_t i;++ for (i = 0; i < k->n_certs; i++) {+ const struct status_cert *c = &k->certs[i];+ char fp_hex[65];++ hex_encode(c->fingerprint, 32, fp_hex);+ printf(" %s%s%s%s\n", fp_hex, c->primary ? " (" : "",+ c->primary ? role : "", c->primary ? ")" : "");+ if (c->info_rc)+ printf(" (details unreadable: %s)\n",+ strerror(-c->info_rc));+ else+ printf(" %s, %s, valid %s to %s\n", c->subject,+ c->algorithm, c->not_before, c->not_after);+ if (c->link >= 0)+ print_link(k, (size_t)c->link, " ");+ else if (!k->links_rc)+ printf(" not in the keyring (%s)\n", unlinked);+ }+}- (void)serial;- (void)description;- if (strcmp(type, "asymmetric") == 0)- (*n)++;+static void print_other_links(const struct status_keyring *k)+{+ bool header = false;+ size_t i;++ for (i = 0; i < k->n_links; i++) {+ if (k->state[i].cert)+ continue;+ if (!header)+ printf(" Other links:\n");+ header = true;+ print_link(k, i, " ");+ }+}++static void print_keyring_serials(const struct status_keyring *k)+{+ if (k->serial >= 0)+ printf(" %-22s %lld\n", "Serial:", (__s64)k->serial);+ else if (k->pinned == -ENOENT)+ printf(" %-22s %s\n", "Serial:",+ "absent (operator host, or `shirudo init` "+ "not yet run)");+ else if (k->serial == -ENOKEY)+ printf(" %-22s %s\n", "Serial:", "absent");+ else+ printf(" %-22s lookup error: %s\n", "Serial:",+ strerror(-k->serial));+ if (k->pinned == -ENOENT || k->pinned == 0)+ printf(" %-22s %s\n", "Frozen serial:", "(none this boot)");+ else if (k->pinned < 0)+ printf(" %-22s unreadable: %s\n", "Frozen serial:",+ strerror(-k->pinned));+ else+ printf(" %-22s %lld%s\n", "Frozen serial:",+ (__s64)k->pinned, k->serial < 0 ?+ " (GONE -- removed?)" :+ k->serial == k->pinned ?+ " (matches)" :+ " (MISMATCH -- swapped?)");+ if (k->links_rc && k->serial >= 0)+ printf(" %-22s unreadable: %s\n", "Links:",+ strerror(-k->links_rc));}int cmd_status(int argc, const char **argv)@@ -517,7 +869,8 @@ int cmd_status(int argc, const char **argv)struct shirudo_sysinfo sysi = {};struct shirudo_trusted_set certs = {};int certs_enrolled = -1;- struct shirudo_identity ident;+ struct status_keyring bpf = {}, dmv = {};+ struct shirudo_identity ident = {};int certs_rc = -ENOENT;struct shirudo_config otel_cfg = {};struct shirudo_otel_opts otel_opts = {};@@ -639,13 +992,15 @@ int cmd_status(int argc, const char **argv)*/certs_rc = keys_load(SHIRUDO_KEYS_DIR, NULL,!strcmp(keyring_mode, "bpf"), &certs);- if (!strcmp(keyring_mode, "bpf") && keyring_present) {- size_t n = 0;-- if (keyring_list(keyring_serial, count_asymmetric,- &n) == 0)- certs_enrolled = (int)n;- }+ bpf.serial = keyring_serial;+ bpf.pinned = keyring_pinned;+ keyring_view_bpf(&bpf, &ident, &certs, certs_rc);+ if (!bpf.links_rc)+ certs_enrolled = (int)bpf.n_asymmetric;+ dmv.pinned = keyring_pinned < 0 ? keyring_pinned : ident.dm_verity_ring;+ dmv.serial = dmv.pinned >= 1 ? shirudo_keyring_dm_verity_serial() :+ -ENOKEY;+ keyring_view_dm_verity(&dmv, &ident);mode = lsm_attached ? "production" : "inactive";is_operator = access(SHIRUDO_SIGNING_KEY_PATH, F_OK) == 0;cert_present = access(shirudo_cert_path(), F_OK) == 0;@@ -705,14 +1060,16 @@ int cmd_status(int argc, const char **argv)struct shirudo_json_emit e;/*- * The events[] dump re-emits the log, so size the buffer- * from it with headroom for the fixed fields and the- * optional sections; every loaded upatch adds a row whose- * strings JSON escaping can grow sixfold. The clamp below- * keeps it under SHIRUDO_JSON_MAX_BYTES.+ * Every loaded upatch adds a row, every certificate and link+ * of the keyrings an entry, whose strings JSON escaping can+ * grow sixfold, and the events[] dump re-emits the log. The+ * clamp below keeps it under SHIRUDO_JSON_MAX_BYTES.*/json_cap = 16384 + (size_t)n_ups *(6 * sizeof(struct shirudo_upatch_table_row) + 256);+ json_cap += (bpf.n_certs + bpf.n_links + dmv.n_certs ++ dmv.n_links) *+ (6 * (KEYRING_DESC_MAX + STATUS_SUBJECT_MAX) + 512);if (include_eventlog && ev_rc == 0)json_cap += 65536 + 3 * (size_t)ev_bytes;if (include_kernel_log)@@ -755,6 +1112,7 @@ int cmd_status(int argc, const char **argv)cin.config_seen = config_state != -ENODEV;cin.config_state = config_state;cin.config_root = config_root_hex;+ keyring_cond_input(&cin, &bpf, &dmv);otel_status = status_verdict(&cin);json_kv_string(&e, "status",otel_status);@@ -817,6 +1175,8 @@ int cmd_status(int argc, const char **argv)certs_enrolled);elsejson_kv_null(&e, "certs_enrolled");+ keyring_emit_json(&e, "bpf_keyring", &bpf, "primary");+ keyring_emit_json(&e, "dm_verity_keyring", &dmv, "config");json_kv_bool(&e, "signing_key_present", is_operator);{struct shirudo_upatch_table_row *rows = NULL;@@ -1068,6 +1428,7 @@ int cmd_status(int argc, const char **argv)cin.config_seen = config_state != -ENODEV;cin.config_state = config_state;cin.config_root = config_root_hex;+ keyring_cond_input(&cin, &bpf, &dmv);verdict = status_verdict(&cin);status_reason(&cin, reason, sizeof(reason));nc = conditions(&cin, conds, ARRAY_SIZE(conds));@@ -1106,31 +1467,7 @@ int cmd_status(int argc, const char **argv)}printf("\nKeyring (.bpf):\n");- if (keyring_present)- printf(" %-22s %lld\n", "Serial:",- (__s64)keyring_serial);- else if (keyring_pinned == -ENOENT)- printf(" %-22s %s\n", "Serial:",- "absent (operator host, or `shirudo init` "- "not yet run)");- else if (keyring_serial == -ENOKEY)- printf(" %-22s %s\n", "Serial:", "absent");- else- printf(" %-22s lookup error: %s\n", "Serial:",- strerror(-keyring_serial));- if (keyring_pinned == -ENOENT)- printf(" %-22s %s\n", "Frozen serial:",- "(none this boot)");- else if (keyring_pinned < 0)- printf(" %-22s unreadable: %s\n", "Frozen serial:",- strerror(-keyring_pinned));- else- printf(" %-22s %lld%s\n", "Frozen serial:",- (__s64)keyring_pinned, !keyring_present ?- " (GONE -- removed?)" :- keyring_serial == keyring_pinned ?- " (matches)" :- " (MISMATCH -- swapped?)");+ print_keyring_serials(&bpf);if (certs_rc == 0) {printf(" %-22s %zu trusted, %zu revoked, %zu ""unvouched", "Certificates:", certs.n,@@ -1139,16 +1476,26 @@ int cmd_status(int argc, const char **argv)printf(", %d in the bpf keyring",certs_enrolled);printf("\n");- for (i = 0; i < (int)certs.n; i++) {- char fp_hex[65];-- hex_encode(certs.certs[i].fingerprint,- 32, fp_hex);- printf(" %s%s\n", fp_hex,- certs.certs[i].primary ? " (primary)" :- "");- }+ print_keyring_certs(&bpf, "primary",+ "enrolled at the next boot");+ }+ print_other_links(&bpf);++ printf("\nKeyring (.dm-verity):\n");+ print_keyring_serials(&dmv);+ if (dmv.certs_rc == 0) {+ printf(" %-22s %zu trusted", "Certificates:",+ dmv.n_certs);+ if (!dmv.links_rc)+ printf(", %zu in the dm-verity keyring",+ dmv.n_asymmetric);+ printf("\n");+ print_keyring_certs(&dmv, "config", "MISSING");+ } else if (dmv.certs_rc != -ENOENT) {+ printf(" %-22s unreadable: %s\n", "Certificates:",+ strerror(-dmv.certs_rc));}+ print_other_links(&dmv);if (include_system) {print_system_human(&sysi);@@ -1290,6 +1637,8 @@ int cmd_status(int argc, const char **argv)}out:+ keyring_view_free(&bpf);+ keyring_view_free(&dmv);for (i = 0; i < n_ups; i++)libc_free(ups[i]);libc_free(ups);diff --git a/testing/functional/tamperproof/t6004-conditions.sh b/testing/functional/tamperproof/t6004-conditions.shindex 38481e49..c500d539 100755--- a/testing/functional/tamperproof/t6004-conditions.sh+++ b/testing/functional/tamperproof/t6004-conditions.sh@@ -2,9 +2,10 @@# SPDX-License-Identifier: BSD-2-Clause# Copyright (c) 2026 Authors of shirudo#-# t6004 -- util/conditions.c: the KeyringSealed condition names the kind-# of keyring the anchor is in, a keyring other than the one init froze,-# or none where it froze one, makes the status tampered, and the register+# t6004 -- util/conditions.c: the KeyringSealed condition covers the bpf+# and dm-verity keyrings init froze; a keyring other than the one init+# froze, none where it froze one, a link init did not freeze or a config+# key that is gone makes the status tampered, and the register# conditions tell a TPM that does not answer from one with no register.# A pending config activation is reboot-pending, and a config its records# cannot vouch for is tampered.@@ -17,7 +18,7 @@ H=helper/test-conditionstest_expect_success 'the bpf keyring init froze is the production anchor' 'out=$(./$H 1 bpf 100 100 match) &&echo "$out" | grep -qx "status=ok" &&- echo "$out" | grep -qx "KeyringSealed OK serial=100 in the BPF keyring, pin matches"+ echo "$out" | grep -qx "KeyringSealed OK bpf serial=100, dm-verity serial=200, pins match"'test_expect_success 'before init the keyring is pending, not tampered' '@@ -39,6 +40,42 @@ test_expect_success 'a frozen bpf keyring that is gone is tampered' 'echo "$out" | grep -qx "KeyringSealed ALERT pin serial=100, the BPF keyring is gone (removed?)"'+test_expect_success 'a swapped dm-verity keyring is tampered' '+ out=$(SHIRUDO_TEST_DMV_SERIAL=201 ./$H 1 bpf 100 100 match) &&+ echo "$out" | grep -qx "status=tampered" &&+ echo "$out" | grep -qx "reason=dm-verity keyring serial swap detected" &&+ echo "$out" | grep -qx "KeyringSealed ALERT dm-verity pin serial=200 != live serial=201 (swapped?)"+'++test_expect_success 'a frozen dm-verity keyring that is gone is tampered' '+ out=$(SHIRUDO_TEST_DMV_SERIAL=-1 ./$H 1 bpf 100 100 match) &&+ echo "$out" | grep -qx "status=tampered" &&+ echo "$out" | grep -qx "reason=the dm-verity keyring init froze is gone" &&+ echo "$out" | grep -qx "KeyringSealed ALERT dm-verity pin serial=200, the dm-verity keyring is gone (removed?)"+'++test_expect_success 'a link init did not freeze is tampered, in either keyring' '+ out=$(SHIRUDO_TEST_BPF_UNFROZEN=1 ./$H 1 bpf 100 100 match) &&+ echo "$out" | grep -qx "status=tampered" &&+ echo "$out" | grep -qx "reason=a keyring holds a link init did not freeze" &&+ echo "$out" | grep -qx "KeyringSealed ALERT the BPF keyring holds 1 link init did not freeze" &&+ out=$(SHIRUDO_TEST_DMV_UNFROZEN=2 ./$H 1 bpf 100 100 match) &&+ echo "$out" | grep -qx "status=tampered" &&+ echo "$out" | grep -qx "KeyringSealed ALERT the dm-verity keyring holds 2 links init did not freeze"+'++test_expect_success 'a config key that is gone is tampered' '+ out=$(SHIRUDO_TEST_DMV_KEY=missing ./$H 1 bpf 100 100 match) &&+ echo "$out" | grep -qx "status=tampered" &&+ echo "$out" | grep -qx "reason=the config key init froze is gone" &&+ echo "$out" | grep -qx "KeyringSealed ALERT the config key init froze is gone from the dm-verity keyring"+'++test_expect_success 'a bpf keyring swap is reported before the dm-verity state' '+ SHIRUDO_TEST_DMV_SERIAL=201 ./$H 1 bpf 101 100 match |+ grep -qx "KeyringSealed ALERT pin serial=100 != live serial=101 (swapped?)"+'+test_expect_success 'with the LSM off a gone keyring is still tampered' './$H 0 bpf -1 200 none | grep -qx "status=tampered"'diff --git a/testing/functional/tamperproof/t6140-status-keyrings.sh b/testing/functional/tamperproof/t6140-status-keyrings.shnew file mode 100644index 00000000..147d33a9--- /dev/null+++ b/testing/functional/tamperproof/t6140-status-keyrings.sh@@ -0,0 +1,94 @@+#!/bin/sh+# SPDX-License-Identifier: BSD-2-Clause+# Copyright (c) 2026 Authors of shirudo+#+# t6140 -- status reports both keyrings init froze as the kernel holds+# them: the serials keyctl names, each certificate with the key that+# holds it, the config certificate the runtime image carries, and no+# link init did not freeze.++cd "$(dirname "$0")/../.."+. ./integration-lib.sh+target_guard+command -v python3 >/dev/null 2>&1 || test_skip_all "no python3"+command -v keyctl >/dev/null 2>&1 || test_skip_all "no keyctl"++W=$(mktemp -d) || exit 1+trap 'rm -rf "$W"' EXIT+"$SHIRUDO_BIN" status --json >"$W/status.json" 2>/dev/null ||+ test_skip_all "status --json failed"+RING=$(report_field keyring_serial <"$W/status.json")+case "$RING" in+ ''|None|0|-*) test_skip_all "no anchor keyring frozen this boot" ;;+esac+DM_RING=$(awk '$8 == "keyring" && $9 == ".dm-verity:" { print $1 }' /proc/keys)+[ -n "$DM_RING" ] || test_skip_all "no dm-verity keyring"+DM_RING=$((0x$DM_RING))+CONFIG_CERT=/run/shirudo/runtime/etc/shirudo/config-cert.der++test_expect_success 'both keyrings are the ones init froze, with nothing added' '+ python3 - "$W/status.json" "$RING" "$DM_RING" <<"PY"+import json, sys+d = json.load(open(sys.argv[1], encoding="utf-8"))+rings = (("bpf_keyring", int(sys.argv[2])),+ ("dm_verity_keyring", int(sys.argv[3])))+for key, serial in rings:+ k = d[key]+ assert k["present"] and k["serial_matches"], (key, k)+ assert k["serial"] == serial == k["serial_pinned"], (key, k)+ assert k["other_links"] == [], (key, k["other_links"])+sealed = [c for c in d["conditions"] if c["type"] == "KeyringSealed"][0]+assert sealed["status"] == "OK", sealed+assert sealed["detail"] == "bpf serial=%d, dm-verity serial=%d, pins match" % (+ rings[0][1], rings[1][1]), sealed+assert d["status"] != "tampered", d["status"]+PY+'++test_expect_success 'each key status names is the one keyctl lists' '+ python3 - "$W/status.json" "$RING" "$DM_RING" <<"PY"+import json, subprocess, sys+d = json.load(open(sys.argv[1], encoding="utf-8"))+def links(ring):+ out = subprocess.run(["keyctl", "rlist", ring], check=True,+ capture_output=True, text=True).stdout+ return sorted(int(s) for s in out.split())+bpf = d["bpf_keyring"]+held = sorted(c["key_serial"] for c in bpf["certs"] if c["key_serial"])+assert held and held == links(sys.argv[2]), (held, links(sys.argv[2]))+assert any(c["primary"] and c["key_serial"] for c in bpf["certs"]), bpf+assert d["certs_enrolled"] == len(held), d["certs_enrolled"]+for c in bpf["certs"]:+ assert c["frozen"] is (True if c["key_serial"] else None), c+ assert c["subject"] and c["algorithm"] and c["not_after"], c+dmv = d["dm_verity_keyring"]+assert len(dmv["certs"]) == 1, dmv["certs"]+c = dmv["certs"][0]+assert c["config"] and c["frozen"] is True, c+assert [c["key_serial"]] == links(sys.argv[3]), (c, links(sys.argv[3]))+PY+'++test_expect_success 'the config certificate is the one the runtime image carries' '+ [ -s "$CONFIG_CERT" ] &&+ python3 - "$W/status.json" "$CONFIG_CERT" <<"PY"+import hashlib, json, sys+d = json.load(open(sys.argv[1], encoding="utf-8"))+with open(sys.argv[2], "rb") as stream:+ digest = hashlib.sha256(stream.read()).hexdigest()+assert d["dm_verity_keyring"]["certs"][0]["sha256"] == digest, digest+PY+'++test_expect_success 'the report shows each certificate with its frozen key' '+ "$SHIRUDO_BIN" status >"$W/status.txt" &&+ grep -qx "Keyring (.bpf):" "$W/status.txt" &&+ grep -qx "Keyring (.dm-verity):" "$W/status.txt" &&+ [ "$(grep -c "^ Frozen serial: .* (matches)$" "$W/status.txt")" = 2 ] &&+ grep -Eqx " [0-9a-f]{64} \(config\)" "$W/status.txt" &&+ grep -Eqx " [0-9a-f]{64} \(primary\)" "$W/status.txt" &&+ grep -Eq "^ key [0-9]+ .* \(frozen\)$" "$W/status.txt" &&+ ! grep -q "NOT frozen\|Other links:" "$W/status.txt"+'++test_donediff --git a/testing/helper/test-conditions.c b/testing/helper/test-conditions.cindex b15254c0..7864d281 100644--- a/testing/helper/test-conditions.c+++ b/testing/helper/test-conditions.c@@ -10,7 +10,12 @@** serial is the live keyring's, -1 when it is absent; pinned the one init* froze, 0 when it froze none; the last word the register's replay, with- * notpm for no TPM answering and none for no register bound.+ * notpm for no TPM answering and none for no register bound. The+ * dm-verity keyring follows the bpf one at serial 200 unless+ * SHIRUDO_TEST_DMV_SERIAL and SHIRUDO_TEST_DMV_PINNED say otherwise;+ * SHIRUDO_TEST_BPF_UNFROZEN and SHIRUDO_TEST_DMV_UNFROZEN count links+ * init did not freeze, and SHIRUDO_TEST_DMV_KEY=missing drops the config+ * key.*/#include <stdint.h>@@ -29,6 +34,16 @@ static int arg_s64(const char *s, __s64 *out)return parse_s64(s, strlen(s), -1, INT32_MAX, out);}+static __s64 env_s64(const char *name, __s64 def)+{+ const char *s = getenv(name);+ __s64 v;++ if (!s || arg_s64(s, &v))+ return def;+ return v;+}+int main(int argc, char **argv){struct shirudo_condition conds[SHIRUDO_CONDITIONS_MAX];@@ -57,6 +72,19 @@ int main(int argc, char **argv)in.ksp_seen = pinned >= 1;in.ksm_seen = in.keyring_present && pinned >= 1;in.keyring_serial_matches = in.ksm_seen && serial == pinned;+ in.bpf_unfrozen = (int)env_s64("SHIRUDO_TEST_BPF_UNFROZEN", 0);+ in.dmv_serial = env_s64("SHIRUDO_TEST_DMV_SERIAL",+ serial >= 0 ? 200 : -1);+ in.dmv_serial_pinned = env_s64("SHIRUDO_TEST_DMV_PINNED",+ pinned >= 1 ? 200 : 0);+ in.dmv_present = in.dmv_serial >= 0;+ in.dmvp_seen = in.dmv_serial_pinned >= 1;+ in.dmvm_seen = in.dmv_present && in.dmvp_seen;+ in.dmv_serial_matches = in.dmvm_seen &&+ in.dmv_serial == in.dmv_serial_pinned;+ in.dmv_unfrozen = (int)env_s64("SHIRUDO_TEST_DMV_UNFROZEN", 0);+ config = getenv("SHIRUDO_TEST_DMV_KEY");+ in.dmv_key_missing = config && !strcmp(config, "missing");in.tpm_reachable = strcmp(argv[5], "notpm") != 0;in.chain_seen = in.tpm_reachable && strcmp(argv[5], "none") != 0;in.cm_seen = in.chain_seen;diff --git a/util/conditions.c b/util/conditions.cindex a6a70b88..ae0529b2 100644--- a/util/conditions.c+++ b/util/conditions.c@@ -6,6 +6,7 @@*/#include <errno.h>+#include <stdarg.h>#include <stdio.h>#include <string.h>@@ -29,6 +30,73 @@ static const char *config_untrusted_detail(int state)return "the config PCR, activation records and mounted config disagree (tamper?)";}+static bool keyring_tampered(const struct shirudo_conditions_input *in)+{+ return (in->ksp_seen && !in->keyring_present) ||+ (in->ksm_seen && !in->keyring_serial_matches) ||+ (in->dmvp_seen && !in->dmv_present) ||+ (in->dmvm_seen && !in->dmv_serial_matches) ||+ in->bpf_unfrozen || in->dmv_unfrozen || in->dmv_key_missing;+}++static void __printf(3, 4)+set_detail(struct shirudo_condition *c, const char *status,+ const char *fmt, ...)+{+ va_list ap;++ c->status = status;+ va_start(ap, fmt);+ if (vstrsprintf(c->detail, sizeof(c->detail), fmt, ap) < 0)+ strscpy(c->detail, "?", sizeof(c->detail));+ va_end(ap);+}++static void keyring_condition(const struct shirudo_conditions_input *in,+ struct shirudo_condition *c)+{+ c->type = "KeyringSealed";+ if (!in->keyring_present && in->ksp_seen)+ set_detail(c, "ALERT",+ "pin serial=%lld, the BPF keyring is gone (removed?)",+ (__s64)in->keyring_serial_pinned);+ else if (!in->keyring_present)+ set_detail(c, "WARN", "shirudo keyring absent (not init'd?)");+ else if (in->ksm_seen && !in->keyring_serial_matches)+ set_detail(c, "ALERT",+ "pin serial=%lld != live serial=%lld (swapped?)",+ (__s64)in->keyring_serial_pinned,+ (__s64)in->keyring_serial);+ else if (in->bpf_unfrozen)+ set_detail(c, "ALERT",+ "the BPF keyring holds %d link%s init did not freeze",+ in->bpf_unfrozen, in->bpf_unfrozen == 1 ? "" : "s");+ else if (in->dmvp_seen && !in->dmv_present)+ set_detail(c, "ALERT",+ "dm-verity pin serial=%lld, the dm-verity keyring is gone (removed?)",+ (__s64)in->dmv_serial_pinned);+ else if (in->dmvm_seen && !in->dmv_serial_matches)+ set_detail(c, "ALERT",+ "dm-verity pin serial=%lld != live serial=%lld (swapped?)",+ (__s64)in->dmv_serial_pinned,+ (__s64)in->dmv_serial);+ else if (in->dmv_unfrozen)+ set_detail(c, "ALERT",+ "the dm-verity keyring holds %d link%s init did not freeze",+ in->dmv_unfrozen, in->dmv_unfrozen == 1 ? "" : "s");+ else if (in->dmv_key_missing)+ set_detail(c, "ALERT",+ "the config key init froze is gone from the dm-verity keyring");+ else if (in->ksp_seen && in->dmvp_seen)+ set_detail(c, "OK",+ "bpf serial=%lld, dm-verity serial=%lld, pins match",+ (__s64)in->keyring_serial, (__s64)in->dmv_serial);+ else+ set_detail(c, "OK", "bpf serial=%lld, %s",+ (__s64)in->keyring_serial,+ in->ksp_seen ? "pin matches" : "no pin recorded");+}+size_t conditions(const struct shirudo_conditions_input *in,struct shirudo_condition *c, size_t cap){@@ -43,39 +111,8 @@ size_t conditions(const struct shirudo_conditions_input *in,sizeof(c[n].detail));n++;}- if (n < cap) {- c[n].type = "KeyringSealed";- if (!in->keyring_present && in->ksp_seen) {- c[n].status = "ALERT";- if (strsprintf(c[n].detail, sizeof(c[n].detail),- "pin serial=%lld, the BPF keyring is "- "gone (removed?)",- (__s64)in->keyring_serial_pinned) < 0)- strscpy(c[n].detail, "?", sizeof(c[n].detail));- } else if (!in->keyring_present) {- c[n].status = "WARN";- strscpy(c[n].detail,- "shirudo keyring absent (not init'd?)",- sizeof(c[n].detail));- } else if (in->ksm_seen && !in->keyring_serial_matches) {- c[n].status = "ALERT";- if (strsprintf(c[n].detail, sizeof(c[n].detail),- "pin serial=%lld != live serial=%lld "- "(swapped?)",- (__s64)in->keyring_serial_pinned,- (__s64)in->keyring_serial) < 0)- strscpy(c[n].detail, "?", sizeof(c[n].detail));- } else {- c[n].status = "OK";- if (strsprintf(c[n].detail, sizeof(c[n].detail),- "serial=%lld in the BPF keyring, %s",- (__s64)in->keyring_serial,- in->ksp_seen ? "pin matches" :- "no pin recorded") < 0)- strscpy(c[n].detail, "?", sizeof(c[n].detail));- }- n++;- }+ if (n < cap)+ keyring_condition(in, &c[n++]);if (n < cap) {c[n].type = "ChainIntact";if (!in->chain_seen) {@@ -165,9 +202,8 @@ const char *status_verdict(const struct shirudo_conditions_input *in)return "unreachable";if (!in->parsed)return "unparseable";- if ((in->cm_seen && !in->chain_matches) ||- (in->ksm_seen && !in->keyring_serial_matches) ||- (in->ksp_seen && !in->keyring_present) || config_untrusted(in))+ if ((in->cm_seen && !in->chain_matches) || keyring_tampered(in) ||+ config_untrusted(in))return "tampered";if (!in->lsm_attached)return "lsm-off";@@ -197,10 +233,21 @@ void status_reason(const struct shirudo_conditions_input *in,else if (config_untrusted(in))strscpy(buf, "the selected config cannot be verified against its records",cap);- else if (!in->keyring_present)+ else if (in->ksp_seen && !in->keyring_present)strscpy(buf, "the keyring init froze is gone", cap);- else+ else if (in->ksm_seen && !in->keyring_serial_matches)strscpy(buf, "keyring serial swap detected", cap);+ else if (in->dmvp_seen && !in->dmv_present)+ strscpy(buf, "the dm-verity keyring init froze is gone",+ cap);+ else if (in->dmvm_seen && !in->dmv_serial_matches)+ strscpy(buf, "dm-verity keyring serial swap detected",+ cap);+ else if (in->bpf_unfrozen || in->dmv_unfrozen)+ strscpy(buf, "a keyring holds a link init did not freeze",+ cap);+ else+ strscpy(buf, "the config key init froze is gone", cap);} else if (strcmp(v, "lsm-off") == 0) {strscpy(buf, "LSM not attached -- enforcement OFF", cap);} else if (strcmp(v, "init-pending") == 0) {diff --git a/util/conditions.h b/util/conditions.hindex 6aa1c72a..4740e1dd 100644--- a/util/conditions.h+++ b/util/conditions.h@@ -30,6 +30,14 @@ struct shirudo_conditions_input {__s64 keyring_serial_pinned;int keyring_serial_matches; /* 0/1 if ksm_seen */int ks_seen, ksp_seen, ksm_seen;+ int bpf_unfrozen; /* links init did not freeze */+ int dmv_present; /* the .dm-verity keyring exists */+ __s64 dmv_serial;+ __s64 dmv_serial_pinned;+ int dmv_serial_matches; /* 0/1 if dmvm_seen */+ int dmvp_seen, dmvm_seen;+ int dmv_unfrozen;+ int dmv_key_missing; /* init's config key is gone */int tpm_reachable;int chain_seen;int chain_matches; /* 0/1 if cm_seen */