eBPF-based security platform
cli: streamline the human output and complete the JSON forms
Daniel Borkmann3600516fb223
diff --git a/Documentation/concepts/glossary.rst b/Documentation/concepts/glossary.rstindex d4696e88..e0098edf 100644--- a/Documentation/concepts/glossary.rst+++ b/Documentation/concepts/glossary.rst@@ -454,7 +454,7 @@ it.overall status of ``ok``, ``degraded``, ``reboot-pending``,``init-pending``, ``lsm-off`` or ``tampered``, and ``OK``, ``WARN``or ``ALERT`` for each condition. ``shirudo attest verify`` ends with- ``verdict: ok`` or ``verdict: FAIL``. See :doc:`/operate/run/read-status`.+ ``verdict: ok`` or ``verdict: fail``. See :doc:`/operate/run/read-status`.vouchA detached CMS signature by a trusted key over the prefixdiff --git a/Documentation/contribute/code/develop-locally.rst b/Documentation/contribute/code/develop-locally.rstindex c383579e..fa013a30 100644--- a/Documentation/contribute/code/develop-locally.rst+++ b/Documentation/contribute/code/develop-locally.rst@@ -362,9 +362,9 @@ Install ittarget# shirudo bpm listexec-count 1.0.0 devtarget# shirudo upatch list- upatches (/var/lib/shirudo/upatches):- loaded type kind payload-sha256 name- yes load bpf 00357162c0dfd6dc.. exec-count+ Archived upatches (/var/lib/shirudo/upatches):+ NAME LOADED TYPE KIND PAYLOAD+ exec-count yes load bpf 00357162c0dfd6dc..Watch the data--------------@@ -483,7 +483,7 @@ Remove itThe target runs the package's signed unload directive, measures theunload and deletes the package. ``shirudo bpm list`` prints nothing- and ``shirudo upatch list`` prints ``(none persisted)``.+ and ``shirudo upatch list`` prints ``none``.2. Check the collector's terminal. The map records stop, and thekeepalives go on.@@ -521,7 +521,7 @@ target runs takes a new bundle and a new VM.a new VM, which takes about two minutes once the kernel and the diskimage exist. It refuses a name that still has state, hence``vm-clean``. ``shirudo status`` on the target then prints a new- ``Version-ID``. The target accepts only the binary on its+ ``Version ID``. The target accepts only the binary on itsauthenticated runtime image, so there is no faster way to run changedtarget code. The rebuilt bundle has a new signing key, so repeat thispage from `Boot the target`_ with an empty registry: remove and startdiff --git a/Documentation/contribute/testing/test-coverage.rst b/Documentation/contribute/testing/test-coverage.rstindex 63b67c3d..532759f5 100644--- a/Documentation/contribute/testing/test-coverage.rst+++ b/Documentation/contribute/testing/test-coverage.rst@@ -524,7 +524,7 @@ the binaries the functional tests run.* - ``kconfig``- A kernel configuration and ``node.labels``* - ``kernel``- - ``/dev/kmsg`` records, ``/proc/modules`` and kernel notes+ - The kernel's ELF notes* - ``oci-http``- Registry and token server responses* - ``oci-manifest``@@ -794,8 +794,7 @@ Commands and procedures- ``upatch load`` or ``upatch unload`` refusing ``tampered`` for astale ``--expect-chain``. Only ``attest verify`` is tested with thatoption.-- ``status --include-eventlog``, ``--include-kernellog``,- ``--include-modules`` and ``--show-full``.+- ``status --include-eventlog`` and ``--show-full``.- ``upatch rewrite-rodata`` in ``shirudo-build``, which``kernel-obs`` uses to rewrite its watch lists.- The ``kernel-cve`` package. Its Beefile is a seed of the ``beefile``diff --git a/Documentation/operate/deploy/boot-integration.rst b/Documentation/operate/deploy/boot-integration.rstindex 9ad24953..4f9bd2a0 100644--- a/Documentation/operate/deploy/boot-integration.rst+++ b/Documentation/operate/deploy/boot-integration.rst@@ -429,26 +429,50 @@ Boot and verify.. code-block:: consoletarget# shirudo status- Host: docs- Roles: target- Mode: production- Status: ok- Version-ID: 447b34bc8bc5547334ced4c737f987a9d3f8f03e332cf234626f0b81b5955064+ Host: docs+ Roles: target+ Mode: production+ Status: ok+ Version ID: d0d7aa800303439023907d1979d917d46a21bec21f816689c138728a28e84af9++ Conditions:+ TYPE STATUS DETAIL+ LsmAttached OK lsm/bpf link present and pinned+ KeyringSealed OK bpf serial 272801410, dm-verity serial 799624487, pins match+ ChainIntact OK live register equals the eventlog replay+ UpatchesMeasured OK every pinned or archived upatch is in this boot's records+ TpmMeasured OK NV index 0x01818E00 readable+ ConfigActive OK config 6d5ed552f448.. is active++ Tamper attempts (this boot):+ LoadNotLoader 15 program load that is not a signed loader+ MapCreate 1 map creation by another executable+ BpfCommand 8 detach, update, delete or unclassified bpf() command+ BpffsUmount 1 unmount of the private bpffs+ SealWrite 1 write open of a sealed file+ SealPtrace 7 ptrace of a shirudo task+ SealEntry 2 entry into a sealed directory, or a sealed inode linked++ Loaded upatches (1):+ NAME LOCATION MAPS STATUS AGE+ shirudo-test-basic fentry/do_nanosleep 0 success 1s++ Folded: keyrings, TPM measurement, assets (--show-full)Conditions:TYPE STATUS DETAILLsmAttached OK lsm/bpf link present and pinned- KeyringSealed OK bpf serial=130847582, dm-verity serial=962472513, pins match- ChainIntact OK live register == eventlog replay+ KeyringSealed OK bpf serial 130847582, dm-verity serial 962472513, pins match+ ChainIntact OK live register equals the eventlog replayTpmMeasured OK NV index 0x01818E00 readableConfigActive OK config dc90bacc356f.. is active...- TPM Measurement:- TPM: reachable (device:/dev/tpmrm0)- NV index: 0x01818E00 (anchored in PCR 9)+ TPM measurement:+ TPM: reachable (device:/dev/tpmrm0)+ NV index: 0x01818E00 (anchored in PCR 9)...- Bound in: initrd- Chain vs eventlog: matches+ Bound in: initrd+ Chain vs eventlog: matches...Check for ``Mode: production``, ``Status: ok``, five ``OK``@@ -461,7 +485,13 @@ Boot and verify.. code-block:: consoletarget# shirudo image status- {"root_hash":"12dbf3c750834908c0f6510481e35fbb0cc76cf6b1896de524304535e63aff0f","pcr":14,"sequence":1,"reset_count":1,"restart_count":0,"pending":false,"consistent":true}+ Config root hash: 6d5ed552f4487728d1ccec8604ddb44b66b18e3430614c20bb4d284995f99f63+ PCR: 14+ Sequence: 1+ TPM reset count: 1+ Restart count: 0+ Pending: no+ Consistent: yes``root_hash`` is the root of ``initial``, ``pcr`` is ``config.pcr``,``pending`` is ``false`` and ``consistent`` is ``true``. The commanddiff --git a/Documentation/operate/deploy/initialize.rst b/Documentation/operate/deploy/initialize.rstindex 4065709c..7f1e838b 100644--- a/Documentation/operate/deploy/initialize.rst+++ b/Documentation/operate/deploy/initialize.rst@@ -64,31 +64,55 @@ Check that init worked.. code-block:: consoletarget# shirudo status- Host: docs- Roles: target- Mode: production- Status: ok- Version-ID: 447b34bc8bc5547334ced4c737f987a9d3f8f03e332cf234626f0b81b5955064+ Host: docs+ Roles: target+ Mode: production+ Status: ok+ Version ID: d0d7aa800303439023907d1979d917d46a21bec21f816689c138728a28e84af9++ Conditions:+ TYPE STATUS DETAIL+ LsmAttached OK lsm/bpf link present and pinned+ KeyringSealed OK bpf serial 272801410, dm-verity serial 799624487, pins match+ ChainIntact OK live register equals the eventlog replay+ UpatchesMeasured OK every pinned or archived upatch is in this boot's records+ TpmMeasured OK NV index 0x01818E00 readable+ ConfigActive OK config 6d5ed552f448.. is active++ Tamper attempts (this boot):+ LoadNotLoader 15 program load that is not a signed loader+ MapCreate 1 map creation by another executable+ BpfCommand 8 detach, update, delete or unclassified bpf() command+ BpffsUmount 1 unmount of the private bpffs+ SealWrite 1 write open of a sealed file+ SealPtrace 7 ptrace of a shirudo task+ SealEntry 2 entry into a sealed directory, or a sealed inode linked++ Loaded upatches (1):+ NAME LOCATION MAPS STATUS AGE+ shirudo-test-basic fentry/do_nanosleep 0 success 1s++ Folded: keyrings, TPM measurement, assets (--show-full)Conditions:TYPE STATUS DETAILLsmAttached OK lsm/bpf link present and pinned- KeyringSealed OK bpf serial=130847582, dm-verity serial=962472513, pins match- ChainIntact OK live register == eventlog replay+ KeyringSealed OK bpf serial 130847582, dm-verity serial 962472513, pins match+ ChainIntact OK live register equals the eventlog replayTpmMeasured OK NV index 0x01818E00 readableConfigActive OK config dc90bacc356f.. is active...- TPM Measurement:- TPM: reachable (device:/dev/tpmrm0)- NV index: 0x01818E00 (anchored in PCR 9)- Chain: dc21c3dabcd2fd0a751c7146ad71c595f2386a4406feb64c3d6e2bd65c5bc706- Register name: 000b9b7b0f925415fdf0d5676369f8cc9146b9e3142537148b31e79dbffcc96e72f8- Anchored: yes (name on record)- PCR before init: 0000000000000000000000000000000000000000000000000000000000000000- Phase at init: 0000000000000000000000000000000000000000000000000000000000000000 (PCR 11)- Bound in: initrd- Chain vs eventlog: matches- Eventlog: /var/lib/shirudo/eventlog (3 entries, 2675 bytes)+ TPM measurement:+ TPM: reachable (device:/dev/tpmrm0)+ NV index: 0x01818E00 (anchored in PCR 9)+ Chain: dc21c3dabcd2fd0a751c7146ad71c595f2386a4406feb64c3d6e2bd65c5bc706+ Register name: 000b9b7b0f925415fdf0d5676369f8cc9146b9e3142537148b31e79dbffcc96e72f8+ Anchored: yes (name on record)+ PCR before init: 0000000000000000000000000000000000000000000000000000000000000000+ Phase at init: 0000000000000000000000000000000000000000000000000000000000000000 (PCR 11)+ Bound in: initrd+ Chain vs eventlog: matches+ Eventlog: /var/lib/shirudo/eventlog (3 entries, 2675 bytes)...``Status: ok`` and five ``OK`` conditions mean that enforcement is@@ -159,18 +183,18 @@ It changes no persistent or enforcement state:.. code-block:: consoletarget# shirudo init --check-only- pre-flight checks:- root OK- bpf_lsm_active OK- bpffs_supported OK- signed_loader_kernel_abi OK- cert_on_disk OK- cert_algorithm OK- cert_kernel_support OK- kernel_keyring OK- embedded_loader OK- tpm2_reachable OK: TCTI override: device:/dev/tpmrm0- 10/10 passed (0 failed)+ Pre-flight checks:+ OK root+ OK bpf_lsm_active+ OK bpffs_supported+ OK signed_loader_kernel_abi+ OK cert_on_disk+ OK cert_algorithm+ OK cert_kernel_support+ OK kernel_keyring+ OK embedded_loader+ OK tpm2_reachable: TCTI from the config: device:/dev/tpmrm0+ 10 of 10 passed:doc:`/reference/cli/init` describes each check.@@ -246,8 +270,8 @@ Register binding failures~~~~~~~~~~~~~~~~~~~~~~~~~When init cannot bind the register, it logs-``init: incomplete -- LSM active and upatches loaded, but TPM register-not advanced`` after one of these lines:+``init: incomplete: LSM active and upatches loaded, but the TPM register+did not advance`` after one of these lines:.. list-table:::header-rows: 1diff --git a/Documentation/operate/maintain/backup-recovery.rst b/Documentation/operate/maintain/backup-recovery.rstindex 634f51c6..25af90b3 100644--- a/Documentation/operate/maintain/backup-recovery.rst+++ b/Documentation/operate/maintain/backup-recovery.rst@@ -184,7 +184,7 @@ leaves the activation pending. The journal shows one of:.. code-block:: textinit: boot-restore failed; further changes and attestation remain blocked- init: incomplete -- LSM active and upatches loaded, but TPM register not advanced+ init: incomplete: LSM active and upatches loaded, but the TPM register did not advanceIn this state the LSM is attached and enforcement is up. The upatchesrestored before the failure stay loaded, the register is not bound, and@@ -260,8 +260,7 @@ either changes while the system runs, as on a resume from hibernation:skip that check.- ``shirudo status`` reports ``tampered`` with the reason ``the selectedconfig cannot be verified against its records``, and ``ConfigActive``- reads ``the config activation record does not belong to this TPM boot- (tamper?)``.+ reads ``the config activation record does not belong to this TPM boot``.- The register can be gone, which ``ChainIntact`` reports as a warning.If you know the TPM was reset, reboot. Do not run ``init`` again: after adiff --git a/Documentation/operate/maintain/keys.rst b/Documentation/operate/maintain/keys.rstindex ec554fc1..453da545 100644--- a/Documentation/operate/maintain/keys.rst+++ b/Documentation/operate/maintain/keys.rst@@ -169,7 +169,7 @@ Check what a target trustsCert (/run/shirudo/runtime/keys/cert.der):Subject: /CN=shirudoIssuer: /CN=shirudo (self-signed)- Public-key: ML-DSA-87+ Public key: ML-DSA-87Fingerprint: SHA256:75171e034357238625311a1c810f7466835ac1dfbc73e9fbd383523439b24125SPKI fingerprint: SHA256:7773eae1c45bc435d9591068da9c318afacfe486007f5386a70ade477f670d69Issued: 2026-10-29T21:50:28Zdiff --git a/Documentation/operate/plan/system-requirements.rst b/Documentation/operate/plan/system-requirements.rstindex 78defc2a..10d81c36 100644--- a/Documentation/operate/plan/system-requirements.rst+++ b/Documentation/operate/plan/system-requirements.rst@@ -382,18 +382,18 @@ Run the checks as root on a target:.. code-block:: consoletarget# shirudo init --check-only- pre-flight checks:- root OK- bpf_lsm_active OK- bpffs_supported OK- signed_loader_kernel_abi OK- cert_on_disk OK- cert_algorithm OK- cert_kernel_support OK- kernel_keyring OK- embedded_loader OK- tpm2_reachable OK: TCTI override: device:/dev/tpmrm0- 10/10 passed (0 failed)+ Pre-flight checks:+ OK root+ OK bpf_lsm_active+ OK bpffs_supported+ OK signed_loader_kernel_abi+ OK cert_on_disk+ OK cert_algorithm+ OK cert_kernel_support+ OK kernel_keyring+ OK embedded_loader+ OK tpm2_reachable: TCTI from the config: device:/dev/tpmrm0+ 10 of 10 passedA failed check prints ``FAIL`` and its reason, and the command exits 1after ``init: pre-flight failed (<failed>/<total> checks)``.diff --git a/Documentation/operate/run/attest.rst b/Documentation/operate/run/attest.rstindex e6a43871..3b09aa68 100644--- a/Documentation/operate/run/attest.rst+++ b/Documentation/operate/run/attest.rst@@ -158,7 +158,7 @@ you trust.--ak-name=<ak-name> --ek-name=<ek-name> --expect-credential=<credential>The report must contain- ``ok: attestation key: activated the credential made for it under the endorsement key``+ ``OK attestation key: activated the credential made for it under the endorsement key``and end with ``verdict: ok``.7. Record ``<ak-name>`` and ``<ek-name>`` for this target in your@@ -254,7 +254,7 @@ Verify evidenceyou activated. ``<config-pcr>`` is ``config.pcr`` of the runtimebootstrap file.-3. Check the exit status: 0 for ``verdict: ok``, 1 for ``verdict: FAIL``+3. Check the exit status: 0 for ``verdict: ok``, 1 for ``verdict: fail``and 2 for a usage error or a file that is not an evidence document.The report prints one line per check, ``ok:`` or ``FAIL:``, and@@ -265,37 +265,37 @@ target, verified with ``--ak-name`` and ``--expect-chain`` only:operator$ shirudo attest verify --evidence=ev.json --nonce=$NONCE \--ak-name=<ak-name> --expect-chain=<register>- ok: nonce matches the request- ok: attestation key: restricted, fixed to this TPM- ok: attestation key: name matches its public area- ok: attestation key: the pinned key- ok: endorsement key: name matches its public area- ok: endorsement key: TCG default template under the endorsement policy- ok: quote: ECDSA signature by the attestation key- ok: quote: signed by the key as an endorsement primary- ok: quote: carries the nonce- ok: quote: covers the PCRs the document lists- ok: quote: PCR digest matches the listed values- ok: register: ECDSA signature by the attestation key- ok: register: signed by the key as an endorsement primary- ok: register: carries the nonce- ok: register: certification names the listed index- ok: register: certified contents match the listed value- ok: quote and certification are of one TPM reset- ok: config: config root history matches the quoted PCR- note: config root has no operator approval; use --expect-config-root with --expect-config-pcr- note: config records a selection; direct TPM writer protection is deferred- ok: eventlog: this boot has an init record- ok: register: the document names index 0x01818E00 and PCRs 9 and 11- ok: register: public area is bound to PCRs 9 and 11 as recorded- note: binding: made in the initrd- ok: eventlog: one init record for this TPM reset (1 this boot)- ok: register: init record is of the TPM's current reset count- ok: eventlog: 2 records replay to the certified value- ok: anchor: record digest matches the index name- ok: anchor: PCR 9 equals the recorded value extended by the anchor- ok: state: register equals the expected value- note: event after boot: upatch_load basic+ OK nonce matches the request+ OK attestation key: restricted, fixed to this TPM+ OK attestation key: name matches its public area+ OK attestation key: the pinned key+ OK endorsement key: name matches its public area+ OK endorsement key: TCG default template under the endorsement policy+ OK quote: ECDSA signature by the attestation key+ OK quote: signed by the key as an endorsement primary+ OK quote: carries the nonce+ OK quote: covers the PCRs the document lists+ OK quote: PCR digest matches the listed values+ OK register: ECDSA signature by the attestation key+ OK register: signed by the key as an endorsement primary+ OK register: carries the nonce+ OK register: certification names the listed index+ OK register: certified contents match the listed value+ OK quote and certification are of one TPM reset+ OK config: config root history matches the quoted PCR+ note config root has no operator approval; use --expect-config-root with --expect-config-pcr+ note config records a selection; direct TPM writer protection is deferred+ OK eventlog: this boot has an init record+ OK register: the document names index 0x01818E00 and PCRs 9 and 11+ OK register: public area is bound to PCRs 9 and 11 as recorded+ note binding: made in the initrd+ OK eventlog: one init record for this TPM reset (1 this boot)+ OK register: init record is of the TPM's current reset count+ OK eventlog: 2 records replay to the certified value+ OK anchor: record digest matches the index name+ OK anchor: PCR 9 equals the recorded value extended by the anchor+ OK state: register equals the expected value+ note event after boot: upatch_load basicverdict: okRead it in groups:@@ -329,10 +329,10 @@ A wrong or stale nonce fails the first check, and the verdict follows:operator$ shirudo attest verify --evidence=ev.json --nonce=<wrong-nonce> \--ak-name=<ak-name>- FAIL: nonce matches the request- ok: attestation key: restricted, fixed to this TPM+ FAIL nonce matches the request+ OK attestation key: restricted, fixed to this TPM...- verdict: FAIL+ verdict: failA target whose state differs from your records fails the state lines.This report is from a second test target. The verifier expected the boot@@ -343,17 +343,17 @@ set only, but a load and an unload happened after boot:operator$ shirudo attest verify --evidence=ev.json --nonce=$NONCE \--ak-name=<ak-name> --cert=cert.der --require-initrd --strict-anchor...- ok: binding: made while the initrd ran- ok: eventlog: one init record for this TPM reset (1 this boot)- ok: register: init record is of the TPM's current reset count- ok: eventlog: 3 records replay to the certified value- ok: anchor: record digest matches the index name- ok: anchor: PCR 9 equals the recorded value extended by the anchor- FAIL: state: init event covers the expected certificate, set and tree root- FAIL: state: 2 events after boot change the register- note: event after boot: upatch_load shirudo-test-basic- note: event after boot: upatch_unload shirudo-test-basic- verdict: FAIL+ OK binding: made while the initrd ran+ OK eventlog: one init record for this TPM reset (1 this boot)+ OK register: init record is of the TPM's current reset count+ OK eventlog: 3 records replay to the certified value+ OK anchor: record digest matches the index name+ OK anchor: PCR 9 equals the recorded value extended by the anchor+ FAIL state: init event covers the expected certificate, set and tree root+ FAIL state: 2 events after boot change the register+ note event after boot: upatch_load shirudo-test-basic+ note event after boot: upatch_unload shirudo-test-basic+ verdict: failThe init event line fails too, because that target enrolled twocertificates and the verifier passed one. A failed state check does not@@ -371,14 +371,14 @@ evidence and the nonce:operator$ shirudo attest verify --evidence=ev.json --nonce=$NONCEattest verify: no --ak-name; the signer is not pinned- ok: nonce matches the request- ok: attestation key: restricted, fixed to this TPM- ok: attestation key: name matches its public area- note: attestation key not pinned: name 000b6e354140b22198138167393ecd1233cfc27e8b16ef0b2b60cce88563c5588dbc+ OK nonce matches the request+ OK attestation key: restricted, fixed to this TPM+ OK attestation key: name matches its public area+ note attestation key not pinned: name 000b6e354140b22198138167393ecd1233cfc27e8b16ef0b2b60cce88563c5588dbc...- note: no expected state given; the register value is e57e1428ab398e758b63f8eda52bac87b5d85c1368c2d8d786ed446448e46239- note: event after boot: upatch_load shirudo-test-basic- note: event after boot: upatch_unload shirudo-test-basic+ note no expected state given; the register value is e57e1428ab398e758b63f8eda52bac87b5d85c1368c2d8d786ed446448e46239+ note event after boot: upatch_load shirudo-test-basic+ note event after boot: upatch_unload shirudo-test-basicverdict: okThe verdict is ``ok`` and the exit status 0, but the run proves onlydiff --git a/Documentation/operate/run/deliver-packages.rst b/Documentation/operate/run/deliver-packages.rstindex 9132a746..32d6c4c3 100644--- a/Documentation/operate/run/deliver-packages.rst+++ b/Documentation/operate/run/deliver-packages.rst@@ -255,9 +255,9 @@ Install a package.. code-block:: consoletarget# shirudo upatch list- upatches (/var/lib/shirudo/upatches):- loaded type kind payload-sha256 name- yes load bpf 8aee7072a1a15e4d.. shirudo-test-basic+ Archived upatches (/var/lib/shirudo/upatches):+ NAME LOADED TYPE KIND PAYLOAD+ shirudo-test-basic yes load bpf 8aee7072a1a15e4d..This target holds one upatch, loaded by hand. A package's upatchesappear the same way, one line each.diff --git a/Documentation/operate/run/read-status.rst b/Documentation/operate/run/read-status.rstindex eebe37b1..e35576e5 100644--- a/Documentation/operate/run/read-status.rst+++ b/Documentation/operate/run/read-status.rst@@ -34,39 +34,126 @@ Print the report.. code-block:: console- target# shirudo status--2. To add this boot's eventlog to the report, print it with- ``--include-eventlog``:+ target# shirudo status --show-full+ Host: docs+ Roles: target+ Mode: production+ Status: ok+ Version ID: d0d7aa800303439023907d1979d917d46a21bec21f816689c138728a28e84af9++ Conditions:+ TYPE STATUS DETAIL+ LsmAttached OK lsm/bpf link present and pinned+ KeyringSealed OK bpf serial 272801410, dm-verity serial 799624487, pins match+ ChainIntact OK live register equals the eventlog replay+ UpatchesMeasured OK every pinned or archived upatch is in this boot's records+ TpmMeasured OK NV index 0x01818E00 readable+ ConfigActive OK config 6d5ed552f448.. is active++ Tamper attempts (this boot):+ LoadNotLoader 15 program load that is not a signed loader+ MapCreate 1 map creation by another executable+ BpfCommand 8 detach, update, delete or unclassified bpf() command+ BpffsUmount 1 unmount of the private bpffs+ SealWrite 1 write open of a sealed file+ SealPtrace 7 ptrace of a shirudo task+ SealEntry 2 entry into a sealed directory, or a sealed inode linked++ Loaded upatches (1):+ NAME LOCATION MAPS STATUS AGE+ shirudo-test-basic fentry/do_nanosleep 0 success 1s++ Keyring (.bpf):+ Serial: 272801410+ Frozen serial: 272801410 (matches)+ Certificates: 2 trusted, 0 revoked, 0 unvouched, 2 in the bpf keyring+ a8be2bb837b0f052f7652f9edf446594a5465eed614d939964ddfcc96e61ba7f+ CN=shirudo, ML-DSA-87, issued 2026-11-03+ key 465853497 shirudo: 30dee65057025367c4c384928bcf1e4cd8fe0265 (frozen)+ 6bd6b1a28b631295a013102d358d371d52ab1c894587aedceaf02e472c88f858 (primary)+ CN=shirudo, ML-DSA-87, issued 2026-11-03+ key 91435879 shirudo: 7fa1d435249690766f8b1397122775d26f1ed92e (frozen)++ Keyring (.dm-verity):+ Serial: 799624487+ Frozen serial: 799624487 (matches)+ Certificates: 1 trusted, 1 in the dm-verity keyring+ 6bd6b1a28b631295a013102d358d371d52ab1c894587aedceaf02e472c88f858 (config)+ CN=shirudo, ML-DSA-87, issued 2026-11-03+ key 403194297 shirudo: 7fa1d435249690766f8b1397122775d26f1ed92e (frozen)++ TPM measurement:+ TPM: reachable (device:/dev/tpmrm0)+ NV index: 0x01818E00 (anchored in PCR 9)+ Chain: 7f63313a31ac8ddd3a6a16fce2038322c9c782d5787155d2dc18dfa582dff548+ Register name: 000b21eb0d45ac9ee1bb0a87dbb069120e3b8cb251b3d40cc2a86a307ab73f728789+ Anchored: yes, name on record+ PCR before init: 0000000000000000000000000000000000000000000000000000000000000000+ Phase at init: 0000000000000000000000000000000000000000000000000000000000000000 (PCR 11)+ Bound in: initrd+ Chain vs eventlog: matches+ Eventlog: /var/lib/shirudo/eventlog (2 entries, 2324 bytes)++ Eventlog:+ TIME TYPE DIGEST DETAIL+ 2026-11-03T14:53:17Z init 377ce174fb1f set_digest=e3b0c44298fc..+ 2026-11-03T14:54:33Z upatch_load d979b373d4e5 shirudo-test-basic payload=8aee7072a1a1..++ Assets (/var/lib/shirudo):+ keys/cert.der present+ keys/signing_key.pem absent+ eventlog present (2324 bytes)+ upatches/ 1 archived+ incoming/ empty+ bpffs/ mounted++ System:+ OS: Ubuntu 26.04.1 LTS+ Kernel: 7.3.0-bpf-next++ Kernel version: #1 SMP PREEMPT Tue Nov 3 13:54:40 UTC 2026+ Kernel build ID: 132d1451aab18a693c59d5b9519d25a06f2236bf+ Architecture: x86_64+ CPUs: 4+ Memory: 314M/3.85G+ Disk: 1.99G/6.61G+ Uptime: 0d 0h 1m+ Machine ID: 6bae4cfbc0ed04ed63cc4cf8cb0a1b6c+ Boot ID: 82639935-1127-4dab-91b5-f818eabc7f13++2. The report folds the sections whose condition is ``OK``: the+ keyrings, the TPM measurement and the assets. To print them all, and+ the system and eventlog sections with them:.. code-block:: console- target# shirudo status --include-eventlog+ target# shirudo status --show-full-:doc:`/reference/cli/status` lists the other sections you can add-(``--include-system``, ``--include-kernellog``, ``--include-modules``,-``--show-full``).+:doc:`/reference/cli/status` lists the options, ``--include-system`` and+``--include-eventlog`` among them.Read the report----------------This is the report of a healthy production target with one upatch-loaded, captured from the test VM:+This is the full report of a healthy production target with one upatch+loaded, captured from the test VM with ``--show-full``. Without the+option the report ends after the loaded upatches and names the folded+sections, the keyrings, the TPM measurement and the assets, on its last+line; a section unfolds on its own when its condition is not ``OK``... code-block:: consoletarget# shirudo status- Host: docs- Roles: target- Mode: production- Status: ok- Version-ID: 447b34bc8bc5547334ced4c737f987a9d3f8f03e332cf234626f0b81b5955064+ Host: docs+ Roles: target+ Mode: production+ Status: ok+ Version ID: 447b34bc8bc5547334ced4c737f987a9d3f8f03e332cf234626f0b81b5955064Conditions:TYPE STATUS DETAILLsmAttached OK lsm/bpf link present and pinned- KeyringSealed OK bpf serial=130847582, dm-verity serial=962472513, pins match- ChainIntact OK live register == eventlog replay+ KeyringSealed OK bpf serial 130847582, dm-verity serial 962472513, pins match+ ChainIntact OK live register equals the eventlog replayUpatchesMeasured OK every pinned or archived upatch is in this boot's recordsTpmMeasured OK NV index 0x01818E00 readableConfigActive OK config dc90bacc356f.. is active@@ -96,21 +183,21 @@ loaded, captured from the test VM:CN=shirudo, ML-DSA-87, issued 2026-10-29key 200951639 shirudo: 6ec99b4c3d1c51e461ce1299fae6ab87d212ce9c (frozen)- upatches loaded (1):+ Loaded upatches (1):NAME LOCATION MAPS STATUS AGEshirudo-test-basic fentry/do_nanosleep 0 success 2s- TPM Measurement:- TPM: reachable (device:/dev/tpmrm0)- NV index: 0x01818E00 (anchored in PCR 9)- Chain: 0307d216caac3067fe645d4a548b25ac5ed0f1e8cf5ae3b189feaefc47e81a84- Register name: 000b9b7b0f925415fdf0d5676369f8cc9146b9e3142537148b31e79dbffcc96e72f8- Anchored: yes (name on record)- PCR before init: 0000000000000000000000000000000000000000000000000000000000000000- Phase at init: 0000000000000000000000000000000000000000000000000000000000000000 (PCR 11)- Bound in: initrd- Chain vs eventlog: matches- Eventlog: /var/lib/shirudo/eventlog (2 entries, 2324 bytes)+ TPM measurement:+ TPM: reachable (device:/dev/tpmrm0)+ NV index: 0x01818E00 (anchored in PCR 9)+ Chain: 0307d216caac3067fe645d4a548b25ac5ed0f1e8cf5ae3b189feaefc47e81a84+ Register name: 000b9b7b0f925415fdf0d5676369f8cc9146b9e3142537148b31e79dbffcc96e72f8+ Anchored: yes (name on record)+ PCR before init: 0000000000000000000000000000000000000000000000000000000000000000+ Phase at init: 0000000000000000000000000000000000000000000000000000000000000000 (PCR 11)+ Bound in: initrd+ Chain vs eventlog: matches+ Eventlog: /var/lib/shirudo/eventlog (2 entries, 2324 bytes)Assets (/var/lib/shirudo):keys/cert.der present@@ -146,7 +233,7 @@ HeaderThe verdict, followed by the reason in parentheses when it is not``ok``. :ref:`status-verdicts` explains each verdict.-``Version-ID``+``Version ID``The identifier of the shirudo build that runs. Compare it with thebuild you deployed, see :doc:`/operate/maintain/upgrade`.@@ -163,8 +250,8 @@ verdict is derived from them.* - Condition- What it checks, and the details other than ``OK``* - ``LsmAttached``- - The ``lsm/bpf`` link is pinned. ``ALERT`` ``lsm/bpf absent --- enforcement OFF`` means enforcement did not come up this boot.+ - The ``lsm/bpf`` link is pinned. ``ALERT`` ``lsm/bpf link absent,+ enforcement off`` means enforcement did not come up this boot.* - ``KeyringSealed``- The live ``.bpf`` and ``.dm-verity`` keyrings are the ones``init`` sealed and recorded in the frozen identity map, they@@ -176,7 +263,7 @@ verdict is derived from them.* - ``ChainIntact``- The live register is the NV index ``init`` bound this boot, wasbound once, and equals this boot's eventlog records replayed.- ``ALERT`` ``live register != eventlog replay (tamper?)``. ``WARN``+ ``ALERT`` ``live register differs from the eventlog replay``. ``WARN````no register bound this boot (init incomplete)`` or ``no TPManswered, no register to replay``.* - ``UpatchesMeasured``@@ -221,7 +308,7 @@ roots, read the same way.``Frozen serial``The serial ``init`` recorded when it sealed the keyring, followed by- ``(matches)``, ``(MISMATCH -- swapped?)`` or ``(GONE -- removed?)``.+ ``(matches)``, ``(swapped)`` or ``(gone)``.``Certificates``The certificates the keyring should hold, and how many keys it@@ -254,15 +341,15 @@ roots, read the same way.trusts every key such a link reaches, so ``KeyringSealed`` is``ALERT`` and the verdict ``tampered``.-upatches loaded+Loaded upatches~~~~~~~~~~~~~~~One row per upatch pinned in the private bpffs: its name, the attachlocation resolved from kernel BTF, its number of maps, ``success`` and-the time since it was loaded. ``upatches loaded (0):`` with no rows+the time since it was loaded. ``Loaded upatches (0):`` with no rowsmeans nothing is loaded.-TPM Measurement+TPM measurement~~~~~~~~~~~~~~~``TPM``@@ -299,10 +386,10 @@ TPM Measurement``Init records``Printed only when the register was bound more than once for this TPM- reset: ``<n> for this TPM reset (REBOUND after init; tamper?)``.+ reset: ``<n> for this TPM reset, rebound after init``.``Chain vs eventlog``- ``matches``, ``MISMATCH (tamper?)`` or ``n/a`` when there is no+ ``matches``, ``MISMATCH`` or ``n/a`` when there is noregister to compare.``Eventlog``@@ -335,18 +422,18 @@ Eventlog~~~~~~~~With ``--include-eventlog`` the report adds every record of the-eventlog, of all boots, between the ``TPM Measurement`` and ``Assets``+eventlog, of all boots, between the ``TPM measurement`` and ``Assets``sections. This target recorded its boot, then one load and one unload:.. code-block:: consoletarget# shirudo status --include-eventlog...- Eventlog (audit trail):+ Eventlog:TIME TYPE DIGEST DETAIL- 2026-10-29T16:17:38Z init cb206abf8e51 set_digest=e3b0c44298fc..- 2026-10-29T16:21:19Z upatch_load d979b373d4e5 shirudo-test-basic payload=8aee7072a1a1..- 2026-10-29T16:21:20Z upatch_unload 26dae981e9bb shirudo-test-basic payload=8aee7072a1a1..+ 2026-11-03T14:53:17Z init 377ce174fb1f set_digest=e3b0c44298fc..+ 2026-11-03T14:54:33Z upatch_load d979b373d4e5 shirudo-test-basic payload=8aee7072a1a1..+ 2026-11-03T14:54:35Z upatch_unload 26dae981e9bb shirudo-test-basic payload=8aee7072a1a1.....The ``init`` record comes from the initrd run. Every later record is a@@ -410,20 +497,20 @@ The register does not replay from the eventlog:.. code-block:: text- Status: tampered (live register != eventlog replay)+ Status: tampered (live register differs from the eventlog replay)...- ChainIntact ALERT live register != eventlog replay (tamper?)+ ChainIntact ALERT live register differs from the eventlog replaySomething extended or replaced the register without a matching eventlogrecord, the eventlog of this boot was altered or hidden, or the index is-not the one ``init`` bound. The ``TPM Measurement`` section shows which+not the one ``init`` bound. The ``TPM measurement`` section shows whichlines disagree.A upatch is pinned or archived without a record:.. code-block:: text- Status: tampered (a upatch is pinned or archived without a record of this boot)+ Status: tampered (a upatch is pinned or archived without a record of this boot)...UpatchesMeasured ALERT 1 pinned or archived without a record of this boot: <name>@@ -440,17 +527,17 @@ The live keyring is not the one ``init`` sealed:.. code-block:: text- Status: tampered (keyring serial swap detected)+ Status: tampered (keyring serial swap detected)...- KeyringSealed ALERT pin serial=<pinned> != live serial=<live> (swapped?)+ KeyringSealed ALERT pinned serial <pinned>, live serial <live>: swappedThe keyring ``init`` sealed is gone:.. code-block:: text- Status: tampered (the keyring init froze is gone)+ Status: tampered (the keyring init froze is gone)...- KeyringSealed ALERT pin serial=<pinned>, the BPF keyring is gone (removed?)+ KeyringSealed ALERT pinned serial <pinned>, the .bpf keyring is goneThe same for ``.dm-verity`` reads ``dm-verity keyring serial swapdetected`` or ``the dm-verity keyring init froze is gone``.@@ -460,7 +547,7 @@ for signatures from then on:.. code-block:: text- Status: tampered (a keyring holds a link init did not freeze)+ Status: tampered (a keyring holds a link init did not freeze)...KeyringSealed ALERT the dm-verity keyring holds 1 link init did not freeze@@ -472,21 +559,19 @@ The config cannot be verified against its records:.. code-block:: text- Status: tampered (the selected config cannot be verified against its records)+ Status: tampered (the selected config cannot be verified against its records)...- ConfigActive ALERT the config PCR, activation records and mounted config disagree (tamper?)+ ConfigActive ALERT the config PCR, activation records and mounted config disagreeThe detail of ``ConfigActive`` names the cause:-- ``the config PCR, activation records and mounted config disagree- (tamper?)``: the config PCR does not hold the value the activation+- ``the config PCR, activation records and mounted config disagree``: the config PCR does not hold the value the activationrecords predict. Something extended the PCR after this boot's configmeasurement. Software that measures into the same PCR causes thistoo, see :doc:`/operate/plan/hardening` for the PCR choice.-- ``the config activation record does not belong to this TPM boot- (tamper?)``: the TPM was reset since the config was measured, for+- ``the config activation record does not belong to this TPM boot``: the TPM was reset since the config was measured, forexample by a resume from hibernation.-- ``the mounted config does not match the selected root (tamper?)``: the+- ``the mounted config does not match the selected root``: theconfig image mounted at ``/run/shirudo/config`` is not the one therecords select.@@ -505,9 +590,9 @@ journal and the state of this boot are the evidence. Follow.. code-block:: text- Status: lsm-off (LSM not attached -- enforcement OFF)+ Status: lsm-off (LSM not attached, enforcement off)...- LsmAttached ALERT lsm/bpf absent -- enforcement OFF+ LsmAttached ALERT lsm/bpf link absent, enforcement offEnforcement is not up. Root can load BPF, and the seal on shirudo'sstate is not enforced. A failure of ``init`` in the initrd does not stop@@ -532,7 +617,7 @@ in this state. So does a target booted without the shirudo initrd... code-block:: text- Status: reboot-pending (a config activation is pending until the next reboot)+ Status: reboot-pending (a config activation is pending until the next reboot)...ConfigActive WARN the activation of config <root>.. is pending until the next reboot@@ -568,7 +653,7 @@ its own... code-block:: text- Status: degraded (no register bound this boot)+ Status: degraded (no register bound this boot)...ChainIntact WARN no register bound this boot (init incomplete)UpatchesMeasured WARN no record of this boot to check the pins againstdiff --git a/Documentation/operate/troubleshoot/bug-report.rst b/Documentation/operate/troubleshoot/bug-report.rstindex db6d950a..8a1ea684 100644--- a/Documentation/operate/troubleshoot/bug-report.rst+++ b/Documentation/operate/troubleshoot/bug-report.rst@@ -51,8 +51,7 @@ Collect on the target.. code-block:: console- target# shirudo status --json --include-system --include-eventlog \- > bug/status.json+ target# shirudo status --json --show-full > bug/status.jsonThe ``system`` block holds the kernel release, version and build ID,and every ``CONFIG_*`` value from ``/boot/config-<release>`` when thatdiff --git a/Documentation/operate/troubleshoot/troubleshooting.rst b/Documentation/operate/troubleshoot/troubleshooting.rstindex f523a749..a7383ad7 100644--- a/Documentation/operate/troubleshoot/troubleshooting.rst+++ b/Documentation/operate/troubleshoot/troubleshooting.rst@@ -34,13 +34,13 @@ Before you beginRoles: targetMode: productionStatus: ok- Version-ID: 447b34bc8bc5547334ced4c737f987a9d3f8f03e332cf234626f0b81b5955064+ Version ID: 447b34bc8bc5547334ced4c737f987a9d3f8f03e332cf234626f0b81b5955064Conditions:TYPE STATUS DETAILLsmAttached OK lsm/bpf link present and pinned- KeyringSealed OK bpf serial=130847582, dm-verity serial=962472513, pins match- ChainIntact OK live register == eventlog replay+ KeyringSealed OK bpf serial 130847582, dm-verity serial 962472513, pins match+ ChainIntact OK live register equals the eventlog replayTpmMeasured OK NV index 0x01818E00 readableConfigActive OK config dc90bacc356f.. is active...@@ -477,18 +477,18 @@ Meaning.. code-block:: consoletarget# shirudo init --check-only- pre-flight checks:- root OK- bpf_lsm_active OK- bpffs_supported OK- signed_loader_kernel_abi OK- cert_on_disk OK- cert_algorithm OK- cert_kernel_support OK- kernel_keyring OK- embedded_loader OK- tpm2_reachable OK: TCTI override: device:/dev/tpmrm0- 10/10 passed (0 failed)+ Pre-flight checks:+ OK root+ OK bpf_lsm_active+ OK bpffs_supported+ OK signed_loader_kernel_abi+ OK cert_on_disk+ OK cert_algorithm+ OK cert_kernel_support+ OK kernel_keyring+ OK embedded_loader+ OK tpm2_reachable: TCTI from the config: device:/dev/tpmrm0+ 10 of 10 passedCausesThe check names the requirement that is missing: root, the BPF LSMdiff --git a/Documentation/reference/cheat-sheet.rst b/Documentation/reference/cheat-sheet.rstindex 34afd234..1e8eb57e 100644--- a/Documentation/reference/cheat-sheet.rst+++ b/Documentation/reference/cheat-sheet.rst@@ -116,7 +116,7 @@ Add the last 50 kernel log lines with :doc:`cli/status`:.. code-block:: console- target# shirudo status --include-kernellog=50+ target# shirudo status --show-fullPrint the effective configuration with :doc:`cli/config`:diff --git a/Documentation/reference/cli/attest-challenge.rst b/Documentation/reference/cli/attest-challenge.rstindex c434a2ea..d1c3ad29 100644--- a/Documentation/reference/cli/attest-challenge.rst+++ b/Documentation/reference/cli/attest-challenge.rst@@ -96,7 +96,7 @@ Exit status* - 0- The challenge was written.* - 1- - A check failed (``verdict: FAIL``), or the challenge could not be+ - A check failed (``verdict: fail``), or the challenge could not bewritten.* - 2- ``--evidence`` or ``--out`` missing, an unknown option or invaliddiff --git a/Documentation/reference/cli/attest-predict.rst b/Documentation/reference/cli/attest-predict.rstindex 8fa5c515..68e5ccc9 100644--- a/Documentation/reference/cli/attest-predict.rst+++ b/Documentation/reference/cli/attest-predict.rst@@ -122,6 +122,10 @@ Options* - ``--event``- ``<event>``, see above- An event after boot. Repeatable, applied in order.+ * - ``--json``+ - none+ - Print the values as one JSON object with ``schema`` (1) and the+ keys above.* - ``--bind-pcr``- ``9=<value>`` or ``11=<value>``- PCR values the register was bound under. Give both.diff --git a/Documentation/reference/cli/attest-verify.rst b/Documentation/reference/cli/attest-verify.rstindex 27b92689..977cdef0 100644--- a/Documentation/reference/cli/attest-verify.rst+++ b/Documentation/reference/cli/attest-verify.rst@@ -38,7 +38,7 @@ Description-----------``verify`` prints one line per check, ``ok:``, ``FAIL:`` or ``note:``,-followed by ``verdict: ok`` or ``verdict: FAIL``. It checks:+followed by ``verdict: ok`` or ``verdict: fail``. It checks:- the nonce, in the document, the quote and the register certification- the attestation key: restricted, fixed to its TPM, its name matching its@@ -128,6 +128,11 @@ Options* - ``--strict-anchor``- none- Require PCR 9 to hold only the anchor.+ * - ``--json``+ - none+ - Print one JSON object: ``schema`` (1), ``verdict`` (``ok`` or+ ``fail``) and ``checks``, a list of ``result`` (``ok``, ``fail``+ or ``note``) and ``text``.* - ``--require-initrd``- none- Fail unless ``init`` bound the register from the initrd.@@ -144,7 +149,7 @@ Exit status* - 0- ``verdict: ok``.* - 1- - ``verdict: FAIL``.+ - ``verdict: fail``.* - 2- A usage error or an invalid value, ``--evidence`` or ``--nonce``missing, an option that needs another, an unreadable evidence file@@ -159,37 +164,37 @@ attestation key pinned:.. code-block:: consoleoperator$ shirudo attest verify --evidence=ev.json --nonce=$NONCE --ak-name=<ak-name> --expect-chain=<register>- ok: nonce matches the request- ok: attestation key: restricted, fixed to this TPM- ok: attestation key: name matches its public area- ok: attestation key: the pinned key- ok: endorsement key: name matches its public area- ok: endorsement key: TCG default template under the endorsement policy- ok: quote: ECDSA signature by the attestation key- ok: quote: signed by the key as an endorsement primary- ok: quote: carries the nonce- ok: quote: covers the PCRs the document lists- ok: quote: PCR digest matches the listed values- ok: register: ECDSA signature by the attestation key- ok: register: signed by the key as an endorsement primary- ok: register: carries the nonce- ok: register: certification names the listed index- ok: register: certified contents match the listed value- ok: quote and certification are of one TPM reset- ok: config: config root history matches the quoted PCR- note: config root has no operator approval; use --expect-config-root with --expect-config-pcr- note: config records a selection; direct TPM writer protection is deferred- ok: eventlog: this boot has an init record- ok: register: the document names index 0x01818E00 and PCRs 9 and 11- ok: register: public area is bound to PCRs 9 and 11 as recorded- note: binding: made in the initrd- ok: eventlog: one init record for this TPM reset (1 this boot)- ok: register: init record is of the TPM's current reset count- ok: eventlog: 2 records replay to the certified value- ok: anchor: record digest matches the index name- ok: anchor: PCR 9 equals the recorded value extended by the anchor- ok: state: register equals the expected value- note: event after boot: upatch_load basic+ OK nonce matches the request+ OK attestation key: restricted, fixed to this TPM+ OK attestation key: name matches its public area+ OK attestation key: the pinned key+ OK endorsement key: name matches its public area+ OK endorsement key: TCG default template under the endorsement policy+ OK quote: ECDSA signature by the attestation key+ OK quote: signed by the key as an endorsement primary+ OK quote: carries the nonce+ OK quote: covers the PCRs the document lists+ OK quote: PCR digest matches the listed values+ OK register: ECDSA signature by the attestation key+ OK register: signed by the key as an endorsement primary+ OK register: carries the nonce+ OK register: certification names the listed index+ OK register: certified contents match the listed value+ OK quote and certification are of one TPM reset+ OK config: config root history matches the quoted PCR+ note config root has no operator approval; use --expect-config-root with --expect-config-pcr+ note config records a selection; direct TPM writer protection is deferred+ OK eventlog: this boot has an init record+ OK register: the document names index 0x01818E00 and PCRs 9 and 11+ OK register: public area is bound to PCRs 9 and 11 as recorded+ note binding: made in the initrd+ OK eventlog: one init record for this TPM reset (1 this boot)+ OK register: init record is of the TPM's current reset count+ OK eventlog: 2 records replay to the certified value+ OK anchor: record digest matches the index name+ OK anchor: PCR 9 equals the recorded value extended by the anchor+ OK state: register equals the expected value+ note event after boot: upatch_load basicverdict: ok``$NONCE`` holds the nonce given to ``shirudo attest``, ``<ak-name>`` the@@ -208,17 +213,17 @@ after boot:.. code-block:: none- ok: binding: made while the initrd ran- ok: eventlog: one init record for this TPM reset (1 this boot)- ok: register: init record is of the TPM's current reset count- ok: eventlog: 3 records replay to the certified value- ok: anchor: record digest matches the index name- ok: anchor: PCR 9 equals the recorded value extended by the anchor- FAIL: state: init event covers the expected certificate, set and tree root- FAIL: state: 2 events after boot change the register- note: event after boot: upatch_load shirudo-test-basic- note: event after boot: upatch_unload shirudo-test-basic- verdict: FAIL+ OK binding: made while the initrd ran+ OK eventlog: one init record for this TPM reset (1 this boot)+ OK register: init record is of the TPM's current reset count+ OK eventlog: 3 records replay to the certified value+ OK anchor: record digest matches the index name+ OK anchor: PCR 9 equals the recorded value extended by the anchor+ FAIL state: init event covers the expected certificate, set and tree root+ FAIL state: 2 events after boot change the register+ note event after boot: upatch_load shirudo-test-basic+ note event after boot: upatch_unload shirudo-test-basic+ verdict: failThe first ``FAIL`` line says that the target enrolls a certificate setother than the one given: that target enrolls two certificates and thediff --git a/Documentation/reference/cli/bpm.rst b/Documentation/reference/cli/bpm.rstindex 2da5de41..06398964 100644--- a/Documentation/reference/cli/bpm.rst+++ b/Documentation/reference/cli/bpm.rst@@ -22,7 +22,7 @@ Usage.. code-block:: noneshirudo bpm config register add <source> oci://<registry> (--key-file <certificate> | --key-file=<certificate>)- shirudo bpm config register list+ shirudo bpm config register list [--json]shirudo bpm config register (remove | rm) <source>shirudo bpm config update --base-package <package> --version <version>[-f <beefile> | --file <beefile>]@@ -31,7 +31,7 @@ Usageshirudo bpm tree sync [--dry-run] [--report <path> | --report=<path>]shirudo bpm tree append <package> oci://<registry>/<repository> [<append-options>]shirudo bpm key (add | fingerprint) <certificate | package | oci-reference>- shirudo bpm key list+ shirudo bpm key list [--json]shirudo bpm pull oci://<registry>/<repository>:<tag>shirudo bpm info <package>shirudo bpm info upatches <package> [--all]@@ -44,7 +44,7 @@ Usageshirudo bpm install <source>/<name>[@<version>]shirudo bpm install oci://<registry>/<repository>:<tag>shirudo bpm upgrade- shirudo bpm list+ shirudo bpm list [--json]shirudo bpm uninstall <name>shirudo bpm --list-cmds@@ -236,7 +236,10 @@ keyrefuses with ``EPERM``. On a target with a config image ``add`` isrefused.- ``key list`` prints the fingerprints of the certificates in- ``/var/lib/shirudo/keys``.+ ``/var/lib/shirudo/keys``, as a list under a heading or, with+ ``--json``, as one object with ``schema`` and ``fingerprints``.+ ``list`` and ``config register list`` take ``--json`` the same way,+ with ``packages`` (``name``, ``version``, ``source``) and ``sources``.``key add`` with an ``oci://`` reference installs the certificate theregistry serves. Run ``key fingerprint`` on the same reference first and@@ -391,6 +394,8 @@ packages:target# shirudo bpm repo updatetarget# shirudo bpm install example/[email protected]target# shirudo bpm list+ Installed packages:+ nonePreview a tree sync:diff --git a/Documentation/reference/cli/image.rst b/Documentation/reference/cli/image.rstindex a0c2f4e1..6f3c307a 100644--- a/Documentation/reference/cli/image.rst+++ b/Documentation/reference/cli/image.rst@@ -27,7 +27,7 @@ Usage[--salt <salt>]shirudo image verify <prefix> --cert <certificate>shirudo image update <prefix>- shirudo image status+ shirudo image status [--json]shirudo image --list-cmdsThe subcommand names must be spelled out. ``image`` without a subcommand@@ -207,7 +207,13 @@ Show the active selection:.. code-block:: consoletarget# shirudo image status- {"root_hash":"12dbf3c750834908c0f6510481e35fbb0cc76cf6b1896de524304535e63aff0f","pcr":14,"sequence":1,"reset_count":1,"restart_count":0,"pending":false,"consistent":true}+ Config root hash: 6d5ed552f4487728d1ccec8604ddb44b66b18e3430614c20bb4d284995f99f63+ PCR: 14+ Sequence: 1+ TPM reset count: 1+ Restart count: 0+ Pending: no+ Consistent: yesRelated-------diff --git a/Documentation/reference/cli/init.rst b/Documentation/reference/cli/init.rstindex 4f0c7640..8eb591c6 100644--- a/Documentation/reference/cli/init.rst+++ b/Documentation/reference/cli/init.rst@@ -25,7 +25,7 @@ Usage.. code-block:: none- shirudo init [--check-only]+ shirudo init [--check-only [--json]]Description-----------@@ -126,6 +126,12 @@ Options- none- off- Run and print the pre-flight checks, then exit.+ * - ``--json``+ - none+ - off+ - With ``--check-only``, print the checks as one JSON object:+ ``schema`` (1), ``passed``, ``failed`` and ``checks``, a list of+ ``name``, ``ok`` and ``detail``.Exit status-----------@@ -168,18 +174,18 @@ Run the pre-flight checks on a target:.. code-block:: consoletarget# shirudo init --check-only- pre-flight checks:- root OK- bpf_lsm_active OK- bpffs_supported OK- signed_loader_kernel_abi OK- cert_on_disk OK- cert_algorithm OK- cert_kernel_support OK- kernel_keyring OK- embedded_loader OK- tpm2_reachable OK: TCTI override: device:/dev/tpmrm0- 10/10 passed (0 failed)+ Pre-flight checks:+ OK root+ OK bpf_lsm_active+ OK bpffs_supported+ OK signed_loader_kernel_abi+ OK cert_on_disk+ OK cert_algorithm+ OK cert_kernel_support+ OK kernel_keyring+ OK embedded_loader+ OK tpm2_reachable: TCTI from the config: device:/dev/tpmrm0+ 10 of 10 passedRelated-------diff --git a/Documentation/reference/cli/keys.rst b/Documentation/reference/cli/keys.rstindex c5b0e680..447b5a47 100644--- a/Documentation/reference/cli/keys.rst+++ b/Documentation/reference/cli/keys.rst@@ -20,7 +20,7 @@ Usage.. code-block:: none- shirudo keys [--keys-dir <dir> | --keys-dir=<dir>]+ shirudo keys [--keys-dir <dir> | --keys-dir=<dir>] [--json]shirudo keys add <certificate> (--vouch <vouch> | --vouch=<vouch>)[--keys-dir <dir> | --keys-dir=<dir>]shirudo keys vouch <certificate> [-o <vouch>]@@ -121,6 +121,15 @@ Options- ``<dir>``, next argument or after ``=``- ``$SHIRUDO_KEYS_DIR``, else ``/var/lib/shirudo/keys``- Display, ``add`` and ``vouch``: the keys directory.+ * - ``--json``+ - none+ - off+ - Print the key material as one JSON object: ``schema`` (1),+ ``cert`` and ``signing_key`` (objects, or ``null`` when absent),+ ``trusted_set`` (a list of ``fingerprint``, ``sha256``,+ ``primary`` and ``voucher``) and ``keyrings`` (``.bpf`` and+ ``.dm-verity``, each with ``present``, ``serial``,+ ``frozen_serial`` and ``members``).* - ``--vouch``- ``<vouch>``, next argument or after ``=``- none, required@@ -186,13 +195,36 @@ Show the key material on a target:.. code-block:: consoletarget# shirudo keys- Cert (/run/shirudo/runtime/keys/cert.der):+ Certificate (/run/shirudo/runtime/keys/cert.der):Subject: /CN=shirudoIssuer: /CN=shirudo (self-signed)- Public-key: ML-DSA-87- Fingerprint: SHA256:75171e034357238625311a1c810f7466835ac1dfbc73e9fbd383523439b24125- SPKI fingerprint: SHA256:7773eae1c45bc435d9591068da9c318afacfe486007f5386a70ade477f670d69- Issued: 2026-10-29T21:50:28Z+ Public key: ML-DSA-87+ Fingerprint: SHA256:c00c2d9a30c11dd98bb53200ac79c744b063a50489e5780968ea97bcb5745eb1+ SPKI fingerprint: SHA256:6bd6b1a28b631295a013102d358d371d52ab1c894587aedceaf02e472c88f858+ Issued: 2026-11-03T14:52:11Z++ Signing key (/run/shirudo/runtime/keys/signing_key.pem):+ Present: no, a target holds no private key++ Trusted set (2 members, 0 revoked, 0 unvouched):+ a8be2bb837b0f052f7652f9edf446594a5465eed614d939964ddfcc96e61ba7f+ sha256 79b04130628135a03630a0ed9e92a574f8701847404ec281469348a09b9b3b45+ vouched by 6bd6b1a28b631295a013102d358d371d52ab1c894587aedceaf02e472c88f858+ 6bd6b1a28b631295a013102d358d371d52ab1c894587aedceaf02e472c88f858 (primary)+ sha256 c00c2d9a30c11dd98bb53200ac79c744b063a50489e5780968ea97bcb5745eb1++ Keyring (.bpf):+ Serial: 272801410+ Frozen serial: 272801410 (matches)+ Members (2):+ serial=465853497 type=asymmetric shirudo: 30dee65057025367c4c384928bcf1e4cd8fe0265 (frozen)+ serial=91435879 type=asymmetric shirudo: 7fa1d435249690766f8b1397122775d26f1ed92e (frozen)++ Keyring (.dm-verity):+ Serial: 799624487+ Frozen serial: 799624487 (matches)+ Members (1):+ serial=403194297 type=asymmetric shirudo: 7fa1d435249690766f8b1397122775d26f1ed92e (frozen)Signing key (/run/shirudo/runtime/keys/signing_key.pem):Present: no (target host -- private key lives on the operator)diff --git a/Documentation/reference/cli/status.rst b/Documentation/reference/cli/status.rstindex 05817612..da4d9424 100644--- a/Documentation/reference/cli/status.rst+++ b/Documentation/reference/cli/status.rst@@ -21,9 +21,8 @@ Usage.. code-block:: none- shirudo status [--json] [--otel] [--include-system] [--include-eventlog]- [--include-kernellog | --include-kernellog=<lines>]- [--include-modules] [--show-full]+ shirudo status [--json | --otel] [--check] [--show-full]+ [--include-system] [--include-eventlog]Description-----------@@ -112,26 +111,23 @@ Options- none- off- Add the eventlog entries.- * - ``--include-kernellog``- - ``<lines>``, 1 to 100, after ``=``- - 10- - Add the last lines of the kernel ring buffer.- * - ``--include-modules``+ * - ``--check``- none- off- - Add the 10 most recently loaded kernel modules.+ - Exit 1 when the verdict is ``tampered``.* - ``--show-full``- none- off- - Turn on every ``--include-*`` option and print the module- dependency tree.+ - Print the folded sections, the keyrings, the TPM measurement and+ the assets, whatever their conditions say, and turn on+ ``--include-system`` and ``--include-eventlog``.Exit status------------``status`` exits with 0 whatever the verdict, ``tampered`` included.-Monitoring must read ``.status`` and the conditions from the JSON-document.+``status`` exits with 0 whatever the verdict, ``tampered`` included,+unless ``--check`` is given, which exits 1 for ``tampered``. Monitoring+reads ``.status`` and the conditions from the JSON document... list-table:::header-rows: 1@@ -146,8 +142,8 @@ document.request failed. With ``--json``: the document does not fit theoutput buffer. Also an allocation failure.* - 2- - An unknown option, a ``--include-kernellog`` value outside 1 to- 100, or with ``--otel`` an invalid ``map_export`` configuration.+ - An unknown option, or with ``--otel`` an invalid ``map_export``+ configuration.Files and environment---------------------@@ -170,17 +166,41 @@ Show the state of a target:.. code-block:: consoletarget# shirudo status- Host: docs- Roles: target- Mode: production- Status: ok- Version-ID: 447b34bc8bc5547334ced4c737f987a9d3f8f03e332cf234626f0b81b5955064+ Host: docs+ Roles: target+ Mode: production+ Status: ok+ Version ID: d0d7aa800303439023907d1979d917d46a21bec21f816689c138728a28e84af9++ Conditions:+ TYPE STATUS DETAIL+ LsmAttached OK lsm/bpf link present and pinned+ KeyringSealed OK bpf serial 272801410, dm-verity serial 799624487, pins match+ ChainIntact OK live register equals the eventlog replay+ UpatchesMeasured OK every pinned or archived upatch is in this boot's records+ TpmMeasured OK NV index 0x01818E00 readable+ ConfigActive OK config 6d5ed552f448.. is active++ Tamper attempts (this boot):+ LoadNotLoader 15 program load that is not a signed loader+ MapCreate 1 map creation by another executable+ BpfCommand 8 detach, update, delete or unclassified bpf() command+ BpffsUmount 1 unmount of the private bpffs+ SealWrite 1 write open of a sealed file+ SealPtrace 7 ptrace of a shirudo task+ SealEntry 2 entry into a sealed directory, or a sealed inode linked++ Loaded upatches (1):+ NAME LOCATION MAPS STATUS AGE+ shirudo-test-basic fentry/do_nanosleep 0 success 1s++ Folded: keyrings, TPM measurement, assets (--show-full)Conditions:TYPE STATUS DETAILLsmAttached OK lsm/bpf link present and pinned- KeyringSealed OK bpf serial=130847582, dm-verity serial=962472513, pins match- ChainIntact OK live register == eventlog replay+ KeyringSealed OK bpf serial 130847582, dm-verity serial 962472513, pins match+ ChainIntact OK live register equals the eventlog replayUpatchesMeasured OK every pinned or archived upatch is in this boot's recordsTpmMeasured OK NV index 0x01818E00 readableConfigActive OK config dc90bacc356f.. is active@@ -210,21 +230,21 @@ Show the state of a target:CN=shirudo, ML-DSA-87, issued 2026-10-29key 200951639 shirudo: 6ec99b4c3d1c51e461ce1299fae6ab87d212ce9c (frozen)- upatches loaded (1):+ Loaded upatches (1):NAME LOCATION MAPS STATUS AGEshirudo-test-basic fentry/do_nanosleep 0 success 2s- TPM Measurement:- TPM: reachable (device:/dev/tpmrm0)- NV index: 0x01818E00 (anchored in PCR 9)- Chain: 0307d216caac3067fe645d4a548b25ac5ed0f1e8cf5ae3b189feaefc47e81a84- Register name: 000b9b7b0f925415fdf0d5676369f8cc9146b9e3142537148b31e79dbffcc96e72f8- Anchored: yes (name on record)- PCR before init: 0000000000000000000000000000000000000000000000000000000000000000- Phase at init: 0000000000000000000000000000000000000000000000000000000000000000 (PCR 11)- Bound in: initrd- Chain vs eventlog: matches- Eventlog: /var/lib/shirudo/eventlog (2 entries, 2324 bytes)+ TPM measurement:+ TPM: reachable (device:/dev/tpmrm0)+ NV index: 0x01818E00 (anchored in PCR 9)+ Chain: 0307d216caac3067fe645d4a548b25ac5ed0f1e8cf5ae3b189feaefc47e81a84+ Register name: 000b9b7b0f925415fdf0d5676369f8cc9146b9e3142537148b31e79dbffcc96e72f8+ Anchored: yes (name on record)+ PCR before init: 0000000000000000000000000000000000000000000000000000000000000000+ Phase at init: 0000000000000000000000000000000000000000000000000000000000000000 (PCR 11)+ Bound in: initrd+ Chain vs eventlog: matches+ Eventlog: /var/lib/shirudo/eventlog (2 entries, 2324 bytes)Assets (/var/lib/shirudo):keys/cert.der present@@ -251,11 +271,11 @@ The eventlog section of that report:.. code-block:: none- Eventlog (audit trail):+ Eventlog:TIME TYPE DIGEST DETAIL- 2026-10-29T16:17:38Z init cb206abf8e51 set_digest=e3b0c44298fc..- 2026-10-29T16:21:19Z upatch_load d979b373d4e5 shirudo-test-basic payload=8aee7072a1a1..- 2026-10-29T16:21:20Z upatch_unload 26dae981e9bb shirudo-test-basic payload=8aee7072a1a1..+ 2026-11-03T14:53:17Z init 377ce174fb1f set_digest=e3b0c44298fc..+ 2026-11-03T14:54:33Z upatch_load d979b373d4e5 shirudo-test-basic payload=8aee7072a1a1..+ 2026-11-03T14:54:35Z upatch_unload 26dae981e9bb shirudo-test-basic payload=8aee7072a1a1..Related-------diff --git a/Documentation/reference/cli/upatch-get.rst b/Documentation/reference/cli/upatch-get.rstindex 3e1f8ff6..7258b15b 100644--- a/Documentation/reference/cli/upatch-get.rst+++ b/Documentation/reference/cli/upatch-get.rst@@ -88,12 +88,17 @@ Describe a loaded upatch:.. code-block:: consoletarget# shirudo upatch get shirudo-test-basic- upatch: shirudo-test-basic- Location: fentry/do_nanosleep- Prog id: 65- Loaded at: 2026-10-29T16:21:18Z (1s ago)- Payload: 8aee7072a1a15e4dddc93ad6b253a0e2e70ad6cdf767442aa8a1c1997bc3069f (signature-bound)- Maps (0):+ Name: shirudo-test-basic+ Location: fentry/do_nanosleep+ Program ID: 72+ Loaded at: 2026-11-03T14:54:33Z (1s ago)+ Payload sha256: 8aee7072a1a15e4dddc93ad6b253a0e2e70ad6cdf767442aa8a1c1997bc3069f (signature-bound)+ Maps:++ Source (kernel BTF line_info):++ <checkout>/testing/fixtures/basic.bpf.c:+ 9: int BPF_PROG(shirudo_test_basic)Source (kernel BTF line_info):diff --git a/Documentation/reference/cli/upatch-list.rst b/Documentation/reference/cli/upatch-list.rstindex 152ed5e9..80614324 100644--- a/Documentation/reference/cli/upatch-list.rst+++ b/Documentation/reference/cli/upatch-list.rst@@ -29,13 +29,13 @@ Description``init`` restores at boot, and the pin directories under``/run/shirudo/bpffs/upatches/``:-- one row per archived artifact, with ``loaded`` ``yes`` or ``no``, its- type (``load`` or ``unload``), its payload kind, the first 16- hexadecimal characters of its payload digest and its name+- one row per archived artifact: its name, ``LOADED`` ``yes`` or+ ``no``, its type (``load`` or ``unload``), its payload kind and the+ first 16 hexadecimal characters of its payload digest- one row per pinned upatch without an archive copy, marked- ``(orphan: no persisted .upatch, will not survive reboot)``+ ``not archived, gone at reboot``-An archived artifact that cannot be read is listed as ``(unreadable)``.+An archived artifact that cannot be read is listed as ``unreadable``.Options-------@@ -52,8 +52,8 @@ Options- none- off- Print one JSON object: ``schema`` (1) and ``upatches``, a list of- ``name``, ``type``, ``payload_type``, ``loaded``, ``persisted`` and- ``payload_sha256``. An orphan has ``type`` and+ ``name``, ``type``, ``payload_type``, ``loaded``, ``archived`` and+ ``payload_sha256``. A upatch without an archive has ``type`` and``payload_sha256`` ``null`` and no ``payload_type``.Exit status@@ -80,17 +80,17 @@ List the upatches of a target with one loaded upatch:.. code-block:: consoletarget# shirudo upatch list- upatches (/var/lib/shirudo/upatches):- loaded type kind payload-sha256 name- yes load bpf 46f3d9f5f6568bdd.. basic+ Archived upatches (/var/lib/shirudo/upatches):+ NAME LOADED TYPE KIND PAYLOAD+ shirudo-test-basic yes load bpf 8aee7072a1a15e4d..The same target after the unload:.. code-block:: consoletarget# shirudo upatch list- upatches (/var/lib/shirudo/upatches):- (none persisted)+ Archived upatches (/var/lib/shirudo/upatches):+ noneRelated-------diff --git a/Documentation/reference/cli/upatch-load.rst b/Documentation/reference/cli/upatch-load.rstindex a053f349..5ad5d39e 100644--- a/Documentation/reference/cli/upatch-load.rst+++ b/Documentation/reference/cli/upatch-load.rst@@ -205,13 +205,11 @@ Load an artifact and print the report:.. code-block:: consoletarget# shirudo upatch load --report=- shirudo-test-basic.upatch- loaded signed loader: prog_fd=10 keyring=420195959 sig=4853B insns=124 data=2400B- loader ok, retval=0 (maps=0 progs=1)- attached + pinned prog 0 (raw_tracepoint) -> /run/shirudo/bpffs/upatches/shirudo-test-basic/link- upatch load: name=shirudo-test-basic keyring=420195959 progs=1- upatch load: chain extended, value=c50b22ac27c5bb6a90ee5ff9b440fbbd5bb60b84a2aa7b395daec3f330886fcd- upatch load measured: name=shirudo-test-basic chain=c50b22ac27c5bb6a90ee5ff9b440fbbd5bb60b84a2aa7b395daec3f330886fcd- {"schema":1,"result":"ok","op":"upatch_load","phase":"done","errno":null,"errno_name":null,"category":"ok","message":"","verifier_log":"","loader_return":0,"upatch":{"path":"shirudo-test-basic.upatch","name":"shirudo-test-basic","payload_sha256":"8aee7072a1a15e4dddc93ad6b253a0e2e70ad6cdf767442aa8a1c1997bc3069f"},"kernel":{"release":"7.3.0-bpf-next+"},"tpm":{"nv_index":"0x01818E00","chain_after":"c50b22ac27c5bb6a90ee5ff9b440fbbd5bb60b84a2aa7b395daec3f330886fcd"}}+ upatch load: signed loader accepted, keyring 272801410, 124 instructions+ upatch load: loader ran, 0 maps and 1 programs+ upatch load: program 0 (raw_tracepoint) pinned at /run/shirudo/bpffs/upatches/shirudo-test-basic/link+ upatch load: shirudo-test-basic loaded, 1 programs, keyring 272801410+ upatch load: shirudo-test-basic measured, register 7f63313a31ac8ddd3a6a16fce2038322c9c782d5787155d2dc18dfa582dff548Load only when the register holds the value you predicted:diff --git a/Documentation/reference/cli/upatch-unload.rst b/Documentation/reference/cli/upatch-unload.rstindex 05a19498..81142a2e 100644--- a/Documentation/reference/cli/upatch-unload.rst+++ b/Documentation/reference/cli/upatch-unload.rst@@ -139,20 +139,19 @@ Unload with a directive bound to the loaded payload:.. code-block:: console- target# shirudo upatch unload basic.unload.upatch- loaded signed loader: prog_fd=10 keyring=531121468 sig=4853B insns=165 data=2808B- upatch unload: payload matches for 'basic'- upatch unload: chain extended, value=fe7bd139c02aca0d6e5efc3940c1cd902adbe676b7875be4c73c878b3f5212b8- upatch unload measured: name=basic chain=fe7bd139c02aca0d6e5efc3940c1cd902adbe676b7875be4c73c878b3f5212b8- upatch unload: detached + unpinned basic+ target# shirudo upatch unload shirudo-test-basic.unload.upatch+ upatch unload: signed loader accepted, keyring 272801410, 165 instructions+ upatch unload: shirudo-test-basic carries the directive's payload+ upatch unload: shirudo-test-basic measured, register 256f5ad373d8728c777455949bef6ee362c2460c06740ac971f7fba5b19315cc+ upatch unload: shirudo-test-basic detached and unpinnedA directive that expects a different payload is refused:.. code-block:: consoletarget# shirudo upatch unload --report=- shirudo-test-basic-mismatch.unload.upatch- loaded signed loader: prog_fd=10 keyring=420195959 sig=4853B insns=165 data=2808B- upatch unload: payload_mismatch -- the upatch loaded under 'shirudo-test-basic' is not what the directive expects; refusing+ upatch unload: signed loader accepted, keyring 272801410, 165 instructions+ upatch unload: payload_mismatch, the upatch loaded under 'shirudo-test-basic' is not what the directive expects; refusedupatch unload failed: name=shirudo-test-basic phase=pin category=payload_mismatch err=1 (Operation not permitted) message=loaded payload does not match directiveThe report of that refusal carries ``"phase":"pin"``,diff --git a/Documentation/reference/failure-categories.rst b/Documentation/reference/failure-categories.rstindex a06e21be..14ae5195 100644--- a/Documentation/reference/failure-categories.rst+++ b/Documentation/reference/failure-categories.rst@@ -330,14 +330,14 @@ every verdict, ``tampered`` included. Parse ``.status`` ofis refused or the output cannot be written; 2 for a usage error oran unreadable challenge.* - ``attest verify``- - 0 for ``verdict: ok``; 1 for ``verdict: FAIL``; 2 for a usage+ - 0 for ``verdict: ok``; 1 for ``verdict: fail``; 2 for a usageerror, an unreadable evidence file or a file that is not anevidence document.* - ``attest predict``- 0; 1 when the write policy cannot be computed; 2 for a usage erroror invalid input.* - ``attest challenge``- - 0; 1 for ``verdict: FAIL`` or a write error; 2 for a usage error,+ - 0; 1 for ``verdict: fail`` or a write error; 2 for a usage error,an unreadable evidence file or evidence without an endorsement key.* - ``keys``- 0; 1 when no key material or no ``.bpf`` keyring is found; 2 for adiff --git a/Documentation/reference/files.rst b/Documentation/reference/files.rstindex 3744447d..c3238a6c 100644--- a/Documentation/reference/files.rst+++ b/Documentation/reference/files.rst@@ -477,16 +477,12 @@ Kernel and system interfaces- Attaching kprobe and kretprobe programs.* - ``/sys/fs/cgroup``- Attaching ``cgroup_skb`` programs at the root cgroup.- * - ``/proc/modules``, ``/sys/module/``- - ``status --include-modules``.* - ``/sys/kernel/notes``, ``/boot/config-<release>``,``/proc/config.gz``- Kernel build ID and configuration, matched by tree selectors.* - ``/etc/os-release``, ``/etc/machine-id``, ``/proc/meminfo``,``/proc/uptime``- ``status --include-system``.- * - ``/dev/kmsg``- - ``status --include-kernellog``.* - ``/etc/initrd-release``- Whether ``init`` runs in the initrd.diff --git a/Documentation/reference/formats/eventlog.rst b/Documentation/reference/formats/eventlog.rstindex 2c66149d..3bdafe23 100644--- a/Documentation/reference/formats/eventlog.rst+++ b/Documentation/reference/formats/eventlog.rst@@ -304,7 +304,7 @@ one load and one unload prints the eventlog as a table (excerpt):.. code-block:: text- Eventlog (audit trail):+ Eventlog:TIME TYPE DIGEST DETAIL2026-10-29T16:17:38Z init cb206abf8e51 set_digest=e3b0c44298fc..2026-10-29T16:21:19Z upatch_load d979b373d4e5 shirudo-test-basic payload=8aee7072a1a1..diff --git a/Documentation/reference/formats/status-json.rst b/Documentation/reference/formats/status-json.rstindex 1ec868c6..3c602ff6 100644--- a/Documentation/reference/formats/status-json.rst+++ b/Documentation/reference/formats/status-json.rst@@ -42,6 +42,9 @@ determined, as noted.- string- The binary's ``SHIRUDO_VERSION_ID``, as``shirudo version --version-id`` prints it.+ * - ``host``+ - string+ - The host name.* - ``is_target``- boolean- ``true`` when the certificate is present, the LSM link is@@ -52,9 +55,13 @@ determined, as noted.* - ``status``- string- The verdict, see `Verdicts`_.+ * - ``reason``+ - string or ``null``+ - The reason the human report prints after the verdict, ``null``+ for ``ok``.* - ``conditions``- array of object- - Five conditions, each with ``type``, ``status`` and ``detail``,+ - Six conditions, each with ``type``, ``status`` and ``detail``,see `Conditions`_.* - ``lsm_attached``- boolean@@ -136,12 +143,6 @@ determined, as noted.* - ``upatch_tree``- object- The upatch tree, see `upatch_tree`_.- * - ``kernel_log``- - array of object- - Only with ``--include-kernellog``, see `Optional blocks`_.- * - ``boot_at``, ``modules``- - string, array of object- - Only with ``--include-modules``, see `Optional blocks`_.Verdicts--------@@ -195,27 +196,27 @@ its details that applies, in the order listed.- ``lsm/bpf link present and pinned``* -- ``ALERT``- - ``lsm/bpf absent -- enforcement OFF``+ - ``lsm/bpf link absent, enforcement off``* - ``KeyringSealed``- ``ALERT``- - ``pin serial=<serial>, the BPF keyring is gone (removed?)``+ - ``pinned serial <serial>, the .bpf keyring is gone``* -- ``WARN``- - ``shirudo keyring absent (not init'd?)``+ - ``.bpf keyring absent before init``* -- ``ALERT``- - ``pin serial=<serial> != live serial=<serial> (swapped?)``+ - ``pinned serial <serial>, live serial <serial>: swapped``* -- ``ALERT``- ``the BPF keyring holds <n> link(s) init did not freeze``* -- ``ALERT``- - ``dm-verity pin serial=<serial>, the dm-verity keyring is gone- (removed?)``+ - ``dm-verity pinned serial <serial>, the dm-verity keyring is+ gone``* -- ``ALERT``- - ``dm-verity pin serial=<serial> != live serial=<serial>- (swapped?)``+ - ``dm-verity pinned serial <serial>, live serial <serial>:+ swapped``* -- ``ALERT``- ``the dm-verity keyring holds <n> link(s) init did not freeze``@@ -224,10 +225,10 @@ its details that applies, in the order listed.- ``the config key init froze is gone from the dm-verity keyring``* -- ``OK``- - ``bpf serial=<serial>, dm-verity serial=<serial>, pins match``+ - ``bpf serial <serial>, dm-verity serial <serial>, pins match``* - ``ChainIntact``- ``OK``- - ``live register == eventlog replay``+ - ``live register equals the eventlog replay``* -- ``WARN``- ``no register bound this boot (init incomplete)``@@ -236,7 +237,7 @@ its details that applies, in the order listed.- ``no TPM answered, no register to replay``* -- ``ALERT``- - ``live register != eventlog replay (tamper?)``+ - ``live register differs from the eventlog replay``* - ``UpatchesMeasured``- ``OK``- ``every pinned or archived upatch is in this boot's records``@@ -263,22 +264,22 @@ its details that applies, in the order listed.- ``config <root>.. is active``* -- ``WARN``- - ``no config activation state (init not run?)``+ - ``no config activation state before init``* -- ``WARN``- ``the activation of config <root>.. is pending until the nextreboot``* -- ``ALERT``- - ``the config activation record does not belong to this TPM boot- (tamper?)``+ - ``the config activation record does not belong to this TPM+ boot``* -- ``ALERT``- - ``the mounted config does not match the selected root (tamper?)``+ - ``the mounted config does not match the selected root``* -- ``ALERT``- - ``the config PCR, activation records and mounted config disagree- (tamper?)``+ - ``the config PCR, activation records and mounted config+ disagree``Keyrings--------@@ -585,7 +586,7 @@ upatch_treeOptional blocks----------------``--show-full`` turns on every block below.+``--show-full`` turns on both blocks below... list-table:::header-rows: 1@@ -609,13 +610,6 @@ Optional blocksand ``digest``, plus ``set_digest`` for ``init`` and ``upatch``(``name``, ``payload_sha256``) for upatch events. A line thatdoes not parse gives ``{"type": "unparseable"}``.- * - ``--include-kernellog[=<n>]``- - ``kernel_log``: the last ``<n>`` kernel log records, 1 to 100,- default 10, each with ``ts`` (ISO 8601 UTC) and ``msg``.- * - ``--include-modules``- - ``boot_at`` (boot time, ISO 8601 UTC) and ``modules``: each- loaded module with ``name``, ``size``, ``refcount``,- ``loaded_at``, ``since_boot_sec`` (or ``null``) and ``deps``.``status`` sizes its output buffer from the options, the eventlog sizeand the number of loaded upatches, at most 8 MiB. A document that does@@ -696,10 +690,12 @@ indented here:{"schema": 1,- "version_id": "447b34bc8bc5547334ced4c737f987a9d3f8f03e332cf234626f0b81b5955064",+ "version_id": "d0d7aa800303439023907d1979d917d46a21bec21f816689c138728a28e84af9",+ "host": "docs","is_target": true,"is_operator": false,"status": "ok",+ "reason": null,"conditions": [{"type": "LsmAttached",@@ -709,12 +705,12 @@ indented here:{"type": "KeyringSealed","status": "OK",- "detail": "bpf serial=130847582, dm-verity serial=962472513, pins match"+ "detail": "bpf serial 272801410, dm-verity serial 799624487, pins match"},{"type": "ChainIntact","status": "OK",- "detail": "live register == eventlog replay"+ "detail": "live register equals the eventlog replay"},{"type": "UpatchesMeasured",@@ -729,27 +725,27 @@ indented here:{"type": "ConfigActive","status": "OK",- "detail": "config dc90bacc356f.. is active"+ "detail": "config 6d5ed552f448.. is active"}],"lsm_attached": true,"mode": "production","keyring_mode": "bpf","keyring_present": true,- "keyring_serial": 130847582,- "keyring_serial_pinned": 130847582,+ "keyring_serial": 272801410,+ "keyring_serial_pinned": 272801410,"keyring_serial_matches": true,"cert_present": true,"certs": [{- "sha256": "08915eb1c67b2446e3708d766f0c5acb5d6ef2f71606cd27a28ce7a1f8c22815",- "fingerprint": "d1bc43c91b9dabf4cd6f3ddf08a177927b3dac8ca833ddc496167253761b4497",- "primary": true+ "sha256": "79b04130628135a03630a0ed9e92a574f8701847404ec281469348a09b9b3b45",+ "fingerprint": "a8be2bb837b0f052f7652f9edf446594a5465eed614d939964ddfcc96e61ba7f",+ "primary": false},{- "sha256": "f2b0444aa3873b394afda3d222a20dc6506ebfb33e07ac17a7e2069bdabb3126",- "fingerprint": "c1c30b07f86808e81ae1c0458c926f00b85bcc815d371d23d7683903f2d3266e",- "primary": false+ "sha256": "c00c2d9a30c11dd98bb53200ac79c744b063a50489e5780968ea97bcb5745eb1",+ "fingerprint": "6bd6b1a28b631295a013102d358d371d52ab1c894587aedceaf02e472c88f858",+ "primary": true}],"certs_revoked": 0,@@ -757,30 +753,30 @@ indented here:"certs_enrolled": 2,"bpf_keyring": {"present": true,- "serial": 130847582,- "serial_pinned": 130847582,+ "serial": 272801410,+ "serial_pinned": 272801410,"serial_matches": true,"certs": [{- "sha256": "08915eb1c67b2446e3708d766f0c5acb5d6ef2f71606cd27a28ce7a1f8c22815",- "fingerprint": "d1bc43c91b9dabf4cd6f3ddf08a177927b3dac8ca833ddc496167253761b4497",- "primary": true,+ "sha256": "79b04130628135a03630a0ed9e92a574f8701847404ec281469348a09b9b3b45",+ "fingerprint": "a8be2bb837b0f052f7652f9edf446594a5465eed614d939964ddfcc96e61ba7f",+ "primary": false,"subject": "CN=shirudo","algorithm": "ML-DSA-87",- "not_before": "2026-10-29",- "key_serial": 199275792,- "key_description": "shirudo: 6ec99b4c3d1c51e461ce1299fae6ab87d212ce9c",+ "not_before": "2026-11-03",+ "key_serial": 465853497,+ "key_description": "shirudo: 30dee65057025367c4c384928bcf1e4cd8fe0265","frozen": true},{- "sha256": "f2b0444aa3873b394afda3d222a20dc6506ebfb33e07ac17a7e2069bdabb3126",- "fingerprint": "c1c30b07f86808e81ae1c0458c926f00b85bcc815d371d23d7683903f2d3266e",- "primary": false,+ "sha256": "c00c2d9a30c11dd98bb53200ac79c744b063a50489e5780968ea97bcb5745eb1",+ "fingerprint": "6bd6b1a28b631295a013102d358d371d52ab1c894587aedceaf02e472c88f858",+ "primary": true,"subject": "CN=shirudo","algorithm": "ML-DSA-87",- "not_before": "2026-10-29",- "key_serial": 106884895,- "key_description": "shirudo: c350bd270c426c5760b202062e15e274ea30f45d",+ "not_before": "2026-11-03",+ "key_serial": 91435879,+ "key_description": "shirudo: 7fa1d435249690766f8b1397122775d26f1ed92e","frozen": true}],@@ -788,19 +784,19 @@ indented here:},"dm_verity_keyring": {"present": true,- "serial": 962472513,- "serial_pinned": 962472513,+ "serial": 799624487,+ "serial_pinned": 799624487,"serial_matches": true,"certs": [{- "sha256": "08915eb1c67b2446e3708d766f0c5acb5d6ef2f71606cd27a28ce7a1f8c22815",- "fingerprint": "d1bc43c91b9dabf4cd6f3ddf08a177927b3dac8ca833ddc496167253761b4497",+ "sha256": "c00c2d9a30c11dd98bb53200ac79c744b063a50489e5780968ea97bcb5745eb1",+ "fingerprint": "6bd6b1a28b631295a013102d358d371d52ab1c894587aedceaf02e472c88f858","config": true,"subject": "CN=shirudo","algorithm": "ML-DSA-87",- "not_before": "2026-10-29",- "key_serial": 200951639,- "key_description": "shirudo: 6ec99b4c3d1c51e461ce1299fae6ab87d212ce9c",+ "not_before": "2026-11-03",+ "key_serial": 403194297,+ "key_description": "shirudo: 7fa1d435249690766f8b1397122775d26f1ed92e","frozen": true}],@@ -813,8 +809,8 @@ indented here:"location": "fentry/do_nanosleep","status": "success","n_maps": 0,- "loaded_at": "2026-10-29T21:29:10Z",- "age_sec": 2,+ "loaded_at": "2026-11-03T14:54:33Z",+ "age_sec": 1,"payload_sha256": "8aee7072a1a15e4dddc93ad6b253a0e2e70ad6cdf767442aa8a1c1997bc3069f"}],@@ -829,30 +825,57 @@ indented here:"bpffs_mounted": true},"tamper_attempts": {- "total": 39,+ "total": 35,"counters": {- "LoadNotLoader": 21, "LoadUnsigned": 0, "LoadUnverified": 0, "LoadKeyringKind": 0,- "LoadKeyring": 0, "MapCreate": 1, "MapWrite": 0, "MapFdWrite": 0,- "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,- "SealXattr": 0, "SealLabel": 0, "SealPtrace": 7, "SealPerf": 0,- "ExecTraced": 0, "SealEntry": 0, "PerfAttach": 0, "PinEntry": 0,- "SealCopyUp": 0, "Kexec": 0, "TpmExtend": 0, "ObjGet": 0,+ "LoadNotLoader": 15,+ "LoadUnsigned": 0,+ "LoadUnverified": 0,+ "LoadKeyringKind": 0,+ "LoadKeyring": 0,+ "MapCreate": 1,+ "MapWrite": 0,+ "MapFdWrite": 0,+ "ProgRun": 0,+ "ProgAttach": 0,+ "ObjPin": 0,+ "BpfCommand": 8,+ "ExeIdentity": 0,+ "KeyringWrite": 0,+ "PinUnlink": 0,+ "PinRename": 0,+ "PinXattr": 0,+ "BpffsUmount": 1,+ "BpffsUmountAbove": 0,+ "BpffsMount": 0,+ "SealWrite": 1,+ "SealUnlink": 0,+ "SealRename": 0,+ "SealSetattr": 0,+ "SealXattr": 0,+ "SealLabel": 0,+ "SealPtrace": 7,+ "SealPerf": 0,+ "ExecTraced": 0,+ "SealEntry": 2,+ "PerfAttach": 0,+ "PinEntry": 0,+ "SealCopyUp": 0,+ "Kexec": 0,+ "TpmExtend": 0,+ "ObjGet": 0,"SealSignal": 0}},"config": {- "root_hash": "dc90bacc356f04c2e34a2f3c00c13c2a555c7cc5ee7cdc57fd568f2b44910c99",+ "root_hash": "6d5ed552f4487728d1ccec8604ddb44b66b18e3430614c20bb4d284995f99f63","activation_pending": false,"error": null},"tpm": {"reachable": true,"nv_index": "0x01818E00",- "chain": "0307d216caac3067fe645d4a548b25ac5ed0f1e8cf5ae3b189feaefc47e81a84",- "nv_name": "000b9b7b0f925415fdf0d5676369f8cc9146b9e3142537148b31e79dbffcc96e72f8",+ "chain": "7f63313a31ac8ddd3a6a16fce2038322c9c782d5787155d2dc18dfa582dff548",+ "nv_name": "000b21eb0d45ac9ee1bb0a87dbb069120e3b8cb251b3d40cc2a86a307ab73f728789","register_bound": true,"register_anchored": true,"init_records": 1,diff --git a/Documentation/security/threat-model.rst b/Documentation/security/threat-model.rstindex bdfea6b6..087f25a7 100644--- a/Documentation/security/threat-model.rst+++ b/Documentation/security/threat-model.rst@@ -1081,7 +1081,7 @@ document can carry a software key's signatures (U1).:Adversary: ADV-B and ADV-C:Enforced at: no hook; the TPM signs and the verifier checks-:Refusal: ``verdict: FAIL`` from ``shirudo attest verify``, with the+:Refusal: ``verdict: fail`` from ``shirudo attest verify``, with thefailed check named:Counters: none:Tests: ``t4003``, ``t4004``, ``t4102``diff --git a/Documentation/start/guides/attest-target.rst b/Documentation/start/guides/attest-target.rstindex a19e7231..a88052a0 100644--- a/Documentation/start/guides/attest-target.rst+++ b/Documentation/start/guides/attest-target.rst@@ -91,10 +91,10 @@ Challenge the attestation key.. code-block:: consoleoperator$ shirudo attest challenge --evidence="$RESULT/first.json" --ak-name="$AK" --trust-presented-ek --out="$RESULT/challenge.json"- ok: attestation key: the pinned key- ok: endorsement key: name matches its public area- ok: endorsement key: TCG default template under the endorsement policy- note: no endorsement certificate: the endorsement key is trusted as presented+ OK attestation key: the pinned key+ OK endorsement key: name matches its public area+ OK endorsement key: TCG default template under the endorsement policy+ note no endorsement certificate: the endorsement key is trusted as presentedchallenge: build/test-vm/vms/quickstart/result/challenge.jsoncredential: b17d3f29447eaf539bcffa2556b010082a7a10e2b7ab60746c485d176b7a40cc@@ -159,22 +159,22 @@ Verify the enrollment.. code-block:: consoleoperator$ shirudo attest verify --evidence="$RESULT/enrolled.json" --nonce="$NONCE2" --ak-name="$AK" --ek-name="$EK" --expect-credential="$CRED" --cert="$KEYS/cert.der" --cert="$OWN" --allow-runtime-events- ok: nonce matches the request- ok: attestation key: restricted, fixed to this TPM- ok: attestation key: name matches its public area- ok: attestation key: the pinned key- ok: endorsement key: name matches its public area- ok: endorsement key: TCG default template under the endorsement policy- ok: endorsement key: the pinned key- ok: attestation key: activated the credential made for it under the endorsement key+ OK nonce matches the request+ OK attestation key: restricted, fixed to this TPM+ OK attestation key: name matches its public area+ OK attestation key: the pinned key+ OK endorsement key: name matches its public area+ OK endorsement key: TCG default template under the endorsement policy+ OK endorsement key: the pinned key+ OK attestation key: activated the credential made for it under the endorsement key...- ok: eventlog: 7 records replay to the certified value- ok: anchor: record digest matches the index name- ok: anchor: PCR 9 equals the recorded value extended by the anchor- ok: state: init event covers the expected certificate, set and tree root- ok: state: 6 events after boot change the register- note: event after boot: upatch_load basic- note: event after boot: upatch_unload basic+ OK eventlog: 7 records replay to the certified value+ OK anchor: record digest matches the index name+ OK anchor: PCR 9 equals the recorded value extended by the anchor+ OK state: init event covers the expected certificate, set and tree root+ OK state: 6 events after boot change the register+ note event after boot: upatch_load basic+ note event after boot: upatch_unload basic...verdict: ok@@ -211,7 +211,7 @@ Predict the registerinit_event: 1014642f2d76b1eb10b4872c4299a70e191be0eb2958de65a7098bfe92a93124register_at_boot: 33ec2c3ed20693c2e40131e693a11b169b91efd8f7438f86313c915e512121e5- Verifying against that set fails with ``FAIL: state: init event+ Verifying against that set fails with ``FAIL state: init eventcovers the expected certificate, set and tree root``.2. Add the events since boot, in their order:@@ -252,14 +252,14 @@ Verify evidence.. code-block:: consoleoperator$ shirudo attest verify --evidence="$RESULT/ev.json" --nonce="$NONCE3" --ak-name="$AK" --expect-chain=<register-after-events>- ok: nonce matches the request+ OK nonce matches the request...- ok: eventlog: 7 records replay to the certified value- ok: anchor: record digest matches the index name- ok: anchor: PCR 9 equals the recorded value extended by the anchor- ok: state: register equals the expected value- note: event after boot: upatch_load basic- note: event after boot: upatch_unload basic+ OK eventlog: 7 records replay to the certified value+ OK anchor: record digest matches the index name+ OK anchor: PCR 9 equals the recorded value extended by the anchor+ OK state: register equals the expected value+ note event after boot: upatch_load basic+ note event after boot: upatch_unload basic...verdict: ok@@ -274,9 +274,9 @@ still reports ``verdict: ok``:operator$ shirudo attest verify --evidence="$RESULT/ev.json" --nonce="$NONCE3" --ak-name="$AK"...- ok: anchor: PCR 9 equals the recorded value extended by the anchor- note: no expected state given; the register value is 52764aa4e68b762c7e5bbacf1261bd3242b44a0b66876f34c89c5b8d57da7177- note: event after boot: upatch_load basic+ OK anchor: PCR 9 equals the recorded value extended by the anchor+ note no expected state given; the register value is 52764aa4e68b762c7e5bbacf1261bd3242b44a0b66876f34c89c5b8d57da7177+ note event after boot: upatch_load basic...verdict: okdiff --git a/Documentation/start/guides/first-upatch.rst b/Documentation/start/guides/first-upatch.rstindex df58dcc0..75d2a245 100644--- a/Documentation/start/guides/first-upatch.rst+++ b/Documentation/start/guides/first-upatch.rst@@ -160,7 +160,7 @@ Load it and read the map.. code-block:: consoletarget# shirudo upatch map sleep-count calls- upatch: sleep-count+ Name: sleep-countMap: callsType: arrayMax entries: 1diff --git a/Documentation/start/guides/publish-package.rst b/Documentation/start/guides/publish-package.rstindex 70865489..34ccdb9b 100644--- a/Documentation/start/guides/publish-package.rst+++ b/Documentation/start/guides/publish-package.rst@@ -170,9 +170,9 @@ none, so here the target installs by direct reference... code-block:: consoletarget# shirudo upatch list- upatches (/var/lib/shirudo/upatches):- loaded type kind payload-sha256 name- yes load bpf 109848737a32f431.. hello+ Archived upatches (/var/lib/shirudo/upatches):+ NAME LOADED TYPE KIND PAYLOAD+ hello yes load bpf 109848737a32f431..Remove it---------diff --git a/Documentation/start/quickstart.rst b/Documentation/start/quickstart.rstindex 8dc7f86f..356e9405 100644--- a/Documentation/start/quickstart.rst+++ b/Documentation/start/quickstart.rst@@ -148,17 +148,40 @@ Check enforcement.. code-block:: consoletarget# shirudo status- Host: quickstart- Roles: target- Mode: production- Status: ok- Version-ID: 447b34bc8bc5547334ced4c737f987a9d3f8f03e332cf234626f0b81b5955064+ Host: quickstart+ Roles: target+ Mode: production+ Status: ok+ Version ID: d0d7aa800303439023907d1979d917d46a21bec21f816689c138728a28e84af9++ Conditions:+ TYPE STATUS DETAIL+ LsmAttached OK lsm/bpf link present and pinned+ KeyringSealed OK bpf serial 272801410, dm-verity serial 799624487, pins match+ ChainIntact OK live register equals the eventlog replay+ UpatchesMeasured OK every pinned or archived upatch is in this boot's records+ TpmMeasured OK NV index 0x01818E00 readable+ ConfigActive OK config 6d5ed552f448.. is active++ Tamper attempts (this boot):+ LoadNotLoader 15 program load that is not a signed loader+ MapCreate 1 map creation by another executable+ BpfCommand 8 detach, update, delete or unclassified bpf() command+ BpffsUmount 1 unmount of the private bpffs+ SealWrite 1 write open of a sealed file+ SealPtrace 7 ptrace of a shirudo task+ SealEntry 2 entry into a sealed directory, or a sealed inode linked++ Loaded upatches (0):+ none++ Folded: keyrings, TPM measurement, assets (--show-full)Conditions:TYPE STATUS DETAILLsmAttached OK lsm/bpf link present and pinned- KeyringSealed OK bpf serial=130847582, dm-verity serial=962472513, pins match- ChainIntact OK live register == eventlog replay+ KeyringSealed OK bpf serial 130847582, dm-verity serial 962472513, pins match+ ChainIntact OK live register equals the eventlog replayTpmMeasured OK NV index 0x01818E00 readableConfigActive OK config dc90bacc356f.. is active@@ -187,19 +210,19 @@ Check enforcementCN=shirudo, ML-DSA-87, issued 2026-10-29key 200951639 shirudo: 6ec99b4c3d1c51e461ce1299fae6ab87d212ce9c (frozen)- upatches loaded (0):+ Loaded upatches (0):- TPM Measurement:- TPM: reachable (device:/dev/tpmrm0)- NV index: 0x01818E00 (anchored in PCR 9)- Chain: dc21c3dabcd2fd0a751c7146ad71c595f2386a4406feb64c3d6e2bd65c5bc706- Register name: 000b9b7b0f925415fdf0d5676369f8cc9146b9e3142537148b31e79dbffcc96e72f8- Anchored: yes (name on record)- PCR before init: 0000000000000000000000000000000000000000000000000000000000000000- Phase at init: 0000000000000000000000000000000000000000000000000000000000000000 (PCR 11)- Bound in: initrd- Chain vs eventlog: matches- Eventlog: /var/lib/shirudo/eventlog (1 entries, 1975 bytes)+ TPM measurement:+ TPM: reachable (device:/dev/tpmrm0)+ NV index: 0x01818E00 (anchored in PCR 9)+ Chain: dc21c3dabcd2fd0a751c7146ad71c595f2386a4406feb64c3d6e2bd65c5bc706+ Register name: 000b9b7b0f925415fdf0d5676369f8cc9146b9e3142537148b31e79dbffcc96e72f8+ Anchored: yes (name on record)+ PCR before init: 0000000000000000000000000000000000000000000000000000000000000000+ Phase at init: 0000000000000000000000000000000000000000000000000000000000000000 (PCR 11)+ Bound in: initrd+ Chain vs eventlog: matches+ Eventlog: /var/lib/shirudo/eventlog (1 entries, 1975 bytes)Assets (/var/lib/shirudo):keys/cert.der present@@ -343,12 +366,11 @@ Load it.. code-block:: consoletarget# shirudo upatch load basic.upatch- loaded signed loader: prog_fd=10 keyring=531121468 sig=4853B insns=124 data=2456B- loader ok, retval=0 (maps=0 progs=1)- attached + pinned prog 0 (raw_tracepoint) -> /run/shirudo/bpffs/upatches/basic/link- upatch load: name=basic keyring=531121468 progs=1- upatch load: chain extended, value=ff0eb201e073fdeeba80a4b268f039bea58ec6dd2998e6651c4834ee99f3e103- upatch load measured: name=basic chain=ff0eb201e073fdeeba80a4b268f039bea58ec6dd2998e6651c4834ee99f3e103+ upatch load: signed loader accepted, keyring 272801410, 124 instructions+ upatch load: loader ran, 0 maps and 1 programs+ upatch load: program 0 (raw_tracepoint) pinned at /run/shirudo/bpffs/upatches/basic/link+ upatch load: basic loaded, 1 programs, keyring 272801410+ upatch load: basic measured, register 7f63313a31ac8ddd3a6a16fce2038322c9c782d5787155d2dc18dfa582dff548The kernel checked the loader's signature against the ``.bpf`` keyring(the serial from the status report) before it accepted the load. The@@ -362,9 +384,9 @@ Load it.. code-block:: consoletarget# shirudo upatch list- upatches (/var/lib/shirudo/upatches):- loaded type kind payload-sha256 name- yes load bpf 46f3d9f5f6568bdd.. basic+ Archived upatches (/var/lib/shirudo/upatches):+ NAME LOADED TYPE KIND PAYLOAD+ basic yes load bpf 8aee7072a1a15e4d..The target keeps a copy of the artifact and loads it again at the nextboot.@@ -373,17 +395,24 @@ Load it.. code-block:: console- target# shirudo status+ target# shirudo status --show-full...- upatches loaded (1):+ Loaded upatches (1):NAME LOCATION MAPS STATUS AGE- basic fentry/do_nanosleep 0 success 0s+ basic fentry/do_nanosleep 0 success 1s++ TPM measurement:+ ...+ Chain: 7f63313a31ac8ddd3a6a16fce2038322c9c782d5787155d2dc18dfa582dff548+ ...+ Eventlog: /var/lib/shirudo/eventlog (2 entries, 2324 bytes)+ ...- TPM Measurement:+ TPM measurement:...- Chain: ff0eb201e073fdeeba80a4b268f039bea58ec6dd2998e6651c4834ee99f3e103+ Chain: ff0eb201e073fdeeba80a4b268f039bea58ec6dd2998e6651c4834ee99f3e103...- Eventlog: /var/lib/shirudo/eventlog (2 entries, 2311 bytes)+ Eventlog: /var/lib/shirudo/eventlog (2 entries, 2311 bytes)...The register moved from its boot value to the value the load printed,@@ -446,32 +475,32 @@ nothing but the evidence, your certificates and your artifacts... code-block:: consoleoperator$ shirudo attest verify --evidence="$EV" --nonce="$NONCE" --ak-name="$(jq -r .ak.name "$EV")" --expect-chain=<register-after-events>- ok: nonce matches the request- ok: attestation key: restricted, fixed to this TPM- ok: attestation key: name matches its public area- ok: attestation key: the pinned key+ OK nonce matches the request+ OK attestation key: restricted, fixed to this TPM+ OK attestation key: name matches its public area+ OK attestation key: the pinned key...- ok: quote: ECDSA signature by the attestation key+ OK quote: ECDSA signature by the attestation key...- ok: register: certified contents match the listed value- ok: quote and certification are of one TPM reset- ok: config: config root history matches the quoted PCR- note: config root has no operator approval; use --expect-config-root with --expect-config-pcr- note: config records a selection; direct TPM writer protection is deferred- ok: eventlog: this boot has an init record+ OK register: certified contents match the listed value+ OK quote and certification are of one TPM reset+ OK config: config root history matches the quoted PCR+ note config root has no operator approval; use --expect-config-root with --expect-config-pcr+ note config records a selection; direct TPM writer protection is deferred+ OK eventlog: this boot has an init record...- ok: eventlog: 2 records replay to the certified value- ok: anchor: record digest matches the index name- ok: anchor: PCR 9 equals the recorded value extended by the anchor- ok: state: register equals the expected value- note: event after boot: upatch_load basic+ OK eventlog: 2 records replay to the certified value+ OK anchor: record digest matches the index name+ OK anchor: PCR 9 equals the recorded value extended by the anchor+ OK state: register equals the expected value+ note event after boot: upatch_load basicverdict: ok``<register-after-events>`` is the last line of the prediction. Thechecks prove that the target's TPM signed the evidence for your nonce,that the eventlog replays to the register value the TPM certified, andthat this value is the one you predicted. The command exits with 0 on- ``verdict: ok`` and with 1 on ``verdict: FAIL``. The notes name checks+ ``verdict: ok`` and with 1 on ``verdict: fail``. The notes name checksthis page leaves out, such as the approved config image.:doc:`/operate/run/attest` covers them.@@ -488,11 +517,10 @@ Unload it.. code-block:: consoletarget# shirudo upatch unload basic.unload.upatch- loaded signed loader: prog_fd=10 keyring=531121468 sig=4853B insns=165 data=2808B- upatch unload: payload matches for 'basic'- upatch unload: chain extended, value=fe7bd139c02aca0d6e5efc3940c1cd902adbe676b7875be4c73c878b3f5212b8- upatch unload measured: name=basic chain=fe7bd139c02aca0d6e5efc3940c1cd902adbe676b7875be4c73c878b3f5212b8- upatch unload: detached + unpinned basic+ upatch unload: signed loader accepted, keyring 272801410, 165 instructions+ upatch unload: basic carries the directive's payload+ upatch unload: basic measured, register 256f5ad373d8728c777455949bef6ee362c2460c06740ac971f7fba5b19315cc+ upatch unload: basic detached and unpinnedThe target ran the signed directive, checked that the loaded payload isthe one it names, measured the unload, then detached the program.@@ -502,8 +530,8 @@ Unload it.. code-block:: consoletarget# shirudo upatch list- upatches (/var/lib/shirudo/upatches):- (none persisted)+ Archived upatches (/var/lib/shirudo/upatches):+ noneThe register did not return to its boot value. It moved forward to athird value, and the eventlog records the boot, the load and thediff --git a/Documentation/upatches/learn/kernel-fix-tutorial.rst b/Documentation/upatches/learn/kernel-fix-tutorial.rstindex 7677abf3..c22946bd 100644--- a/Documentation/upatches/learn/kernel-fix-tutorial.rst+++ b/Documentation/upatches/learn/kernel-fix-tutorial.rst@@ -279,12 +279,12 @@ Check where the kernel attached it and read the counters:.. code-block:: consoletarget# shirudo-runtime upatch get cve-2026-63984-rpl- upatch: cve-2026-63984-rpl- Location: fentry/ipv6_rpl_srh_decompress- Prog id: 77- Loaded at: <time> (12s ago)- Payload: f3e2894d7c20d90e759b9d716849fc2acf01ff5de2ad8565b1e0f0320ef9e711 (signature-bound)- Maps (2): activity, hits+ Name: cve-2026-63984-rpl+ Location: fentry/ipv6_rpl_srh_decompress+ Program ID: 77+ Loaded at: <time> (12s ago)+ Payload sha256: f3e2894d7c20d90e759b9d716849fc2acf01ff5de2ad8565b1e0f0320ef9e711 (signature-bound)+ Maps: activity, hitsSource (kernel BTF line_info):@@ -308,7 +308,7 @@ Read one map:.. code-block:: consoletarget# shirudo-runtime upatch map cve-2026-63984-rpl hits- upatch: cve-2026-63984-rpl+ Name: cve-2026-63984-rplMap: hitsType: percpu_array (64 CPUs)Max entries: 1diff --git a/Makefile.shirudo b/Makefile.shirudoindex 4e0dc3b4..f31e6ab5 100644--- a/Makefile.shirudo+++ b/Makefile.shirudo@@ -269,8 +269,6 @@ UTIL_SRCS := \util/timefmt.c \util/conditions.c \util/format.c \- util/kmsg.c \- util/kmodules.c \util/seal.c \util/serializer.c \util/upatch_maps.c \@@ -1019,8 +1017,7 @@ testing/fuzz/fuzz-eventlog: testing/fuzz/fuzz-eventlog.c $(FUZZ_BASE) \util/eventlog.c util/timefmt.c $(FUZZ_SEAL) \util/io.c util/crypto_openssl.c testing/fuzz/chain.ctesting/fuzz/fuzz-kernel: testing/fuzz/fuzz-kernel.c $(FUZZ_BASE) \- util/kmsg.c util/kmodules.c util/kernel_build_id.c \- util/format.c util/timefmt.c+ util/kernel_build_id.ctesting/fuzz/fuzz-elf: testing/fuzz/fuzz-elf.c $(FUZZ_BASE) \util/elf_target.c $(LIBBPF_A)testing/fuzz/fuzz-elf: FUZZ_CFLAGS += $(LIBELF_CFLAGS)@@ -1069,7 +1066,6 @@ testing/fuzz/fuzz-oci-http: FUZZ_INCLUDED := util/bpm_oci.ctesting/fuzz/fuzz-tree-state testing/fuzz/fuzz-kconfig: \FUZZ_INCLUDED := util/bpm_tree_state.ctesting/fuzz/fuzz-otel: FUZZ_INCLUDED := util/upatch_maps_otel.c-testing/fuzz/fuzz-kernel: FUZZ_INCLUDED := util/kmsg.ctesting/fuzz/fuzz-serializer: FUZZ_INCLUDED := util/upatch_maps.ctesting/fuzz/fuzz-decoder: FUZZ_INCLUDED := util/upatch_decode.cdiff --git a/builtin-attest.c b/builtin-attest.cindex a21c593a..ef018d50 100644--- a/builtin-attest.c+++ b/builtin-attest.c@@ -65,6 +65,7 @@ static const struct help_item verify_options[] = {{ "--expect-config-pcr=<n>", "reserved config PCR number" },{ "--expect-pcr=<n>=<hex>", "a PCR value the quote must carry (repeatable)" },{ "--allow-runtime-events", "accept loads, unloads and revocations after boot" },+ { "--json", "print the checks and the verdict as JSON" },{ "--strict-anchor", "require the anchoring PCR to hold only the anchor" },{ "--expect-credential=<hex>", "the credential the challenge given to the target carried" },{ "--ek-name=<hex>", "the endorsement key name pinned at enrollment" },@@ -89,6 +90,7 @@ static const struct help_item predict_options[] = {{ "--event=<kind>:<name>=<hex>","a load, unload, tree:<seq> or revoke:<fingerprint> event after boot" },{ "--bind-pcr=<n>=<hex>", "PCR 9 and 11 values at binding, for the register name" },+ { "--json", "print the values as JSON" },{ "--writer-public=<hex>", "init record's 384-byte RSA modulus (with --bind-pcr)" },};@@ -291,8 +293,24 @@ static int apply_event(const char *spec, __u8 chain[32])return 0;}+struct predict_out {+ bool json;+ struct json_emit e;+};++static void predict_kv(struct predict_out *po, const char *key,+ const char *value)+{+ if (po->json)+ json_kv_string(&po->e, key, value);+ else+ printf("%s: %s\n", key, value);+}+static int cmd_attest_predict(int argc, const char **argv){+ struct predict_out po = { .e = { .cap = 4096 } };+ char pcr_key[32];__u8 writer_public[TPM_NV_RSA_BYTES];__u8 cert_sha[32], tree_root[32] = {}, set_digest[32], init[32];__u8 cert_shas[KEYS_MAX][32];@@ -342,6 +360,8 @@ static int cmd_attest_predict(int argc, const char **argv)goto out;}have_writer = true;+ } else if (!strcmp(a, "--json")) {+ po.json = true;} else if (!strncmp(a, "--bind-pcr=", 11)) {const char *value = NULL;int slot = -1;@@ -371,6 +391,15 @@ static int cmd_attest_predict(int argc, const char **argv)pr_err("attest predict: --cert is required");goto out;}+ if (po.json) {+ po.e.buf = xmalloc(po.e.cap);+ if (!po.e.buf) {+ ret = 1;+ goto out;+ }+ json_obj_open(&po.e);+ json_kv_int(&po.e, "schema", 1);+ }if (keys_anchor_digest(cert_shas, n_certs, cert_sha) ||chain_init_event(cert_sha, m.set, m.n, tree_root, set_digest,init)) {@@ -378,12 +407,12 @@ static int cmd_attest_predict(int argc, const char **argv)goto out;}hex_encode(set_digest, 32, hex);- printf("set_digest: %s\n", hex);+ predict_kv(&po, "set_digest", hex);hex_encode(init, 32, hex);- printf("init_event: %s\n", hex);+ predict_kv(&po, "init_event", hex);chain_fold(chain, init);hex_encode(chain, 32, hex);- printf("register_at_boot: %s\n", hex);+ predict_kv(&po, "register_at_boot", hex);for (i = 0; i < n_events; i++) {if (apply_event(events[i], chain)) {pr_err("attest predict: bad --event '%s'", events[i]);@@ -392,7 +421,7 @@ static int cmd_attest_predict(int argc, const char **argv)}if (n_events) {hex_encode(chain, 32, hex);- printf("register_after_events: %s\n", hex);+ predict_kv(&po, "register_after_events", hex);}if (have_bind[0] && have_bind[1]) {__u8 branch_written[32], branch_init[32], policy[32];@@ -416,30 +445,97 @@ static int cmd_attest_predict(int argc, const char **argv)goto out;}hex_encode(name, sizeof(name), hex);- printf("register_name: %s\n", hex);+ predict_kv(&po, "register_name", hex);if (chain_anchor(name, anchor, sizeof(anchor))) {pr_err("attest predict: the anchor does not fit");goto out;}- printf("anchor: %s\n", anchor);+ predict_kv(&po, "anchor", anchor);if (sha256_calc(anchor, strlen(anchor), anchor_digest)) {pr_err("attest predict: cannot hash the anchor");goto out;}chain_fold(bind[0], anchor_digest);hex_encode(bind[0], 32, hex);- printf("pcr%u_after_anchor: %s\n", CHAIN_PCR, hex);+ if (strsprintf(pcr_key, sizeof(pcr_key), "pcr%u_after_anchor",+ CHAIN_PCR) >= 0)+ predict_kv(&po, pcr_key, hex);} else if (have_bind[0] || have_bind[1] || have_writer) {pr_err("attest predict: --bind-pcr needs both %u and %u",CHAIN_PCR, CHAIN_PHASE_PCR);goto out;}ret = 0;+ if (po.json) {+ json_obj_close(&po.e);+ if (po.e.err) {+ pr_err("attest predict: json encode failed");+ ret = 1;+ } else {+ puts(po.e.buf);+ }+ }out:+ xfree(po.e.buf, po.e.cap);xfree(m.set, ATTEST_MEMBERS_MAX * sizeof(*m.set));return ret;}+/*+ * The report is one check or note per line, OK, FAIL or note then the+ * text, which the JSON form carries as an array of objects.+ */+static int report_emit_json(const char *report, const char *verdict)+{+ char *buf = xmalloc(ATTEST_REPORT_MAX * 2);+ struct json_emit e = { .buf = buf, .cap = ATTEST_REPORT_MAX * 2 };+ const char *line = report;+ int ret = 0;++ if (!buf)+ return 1;+ json_obj_open(&e);+ json_kv_int(&e, "schema", 1);+ json_kv_string(&e, "verdict", verdict);+ json_arr_open(&e, "checks");+ while (*line) {+ const char *nl = strchr(line, '\n');+ size_t len = nl ? (size_t)(nl - line) : strlen(line);+ char text[ATTEST_REPORT_MAX];+ const char *kind = NULL;++ if (len > 8 && !strncmp(line, " OK ", 8))+ kind = "ok";+ else if (len > 8 && !strncmp(line, " FAIL ", 8))+ kind = "fail";+ else if (len > 8 && !strncmp(line, " note ", 8))+ kind = "note";+ if (kind) {+ size_t n = min(len - 8, sizeof(text) - 1);++ memcpy(text, line + 8, n);+ text[n] = '\0';+ json_obj_open(&e);+ json_kv_string(&e, "result", kind);+ json_kv_string(&e, "text", text);+ json_obj_close(&e);+ }+ if (!nl)+ break;+ line = nl + 1;+ }+ json_arr_close(&e);+ json_obj_close(&e);+ if (e.err) {+ pr_err("attest: json encode failed");+ ret = 1;+ } else {+ puts(buf);+ }+ xfree(buf, ATTEST_REPORT_MAX * 2);+ return ret;+}+static int read_evidence(const char *path, char **out, size_t *len){struct stat st;@@ -479,6 +575,7 @@ static int read_evidence(const char *path, char **out, size_t *len)static int cmd_attest_verify(int argc, const char **argv){+ bool json = false;struct attest_expect x = {};__u8 nonce[ATTEST_NONCE_MAX], cert_sha[32], set_digest[32];__u8 cert_shas[KEYS_MAX][32];@@ -570,6 +667,8 @@ static int cmd_attest_verify(int argc, const char **argv)parse_hex32("--expect-pcr value", value, x.pcrs[n]))goto out;x.pcr_expect_mask |= 1u << n;+ } else if (!strcmp(a, "--json")) {+ json = true;} else if (!strcmp(a, "--allow-runtime-events")) {x.allow_runtime_events = true;} else if (!strcmp(a, "--strict-anchor")) {@@ -652,17 +751,20 @@ static int cmd_attest_verify(int argc, const char **argv)goto out;err = attest_verify(evidence, evidence_len, &x, report,ATTEST_REPORT_MAX);- fputs(report, stdout);if (err == -EINVAL) {+ if (!json)+ fputs(report, stdout);pr_err("attest verify: %s is not a shirudo evidence document",evidence_path);ret = 2;- } else if (err) {- printf("verdict: FAIL\n");- ret = 1;+ } else if (json) {+ ret = report_emit_json(report, err ? "fail" : "ok");+ if (!ret && err)+ ret = 1;} else {- printf("verdict: ok\n");- ret = 0;+ fputs(report, stdout);+ printf("verdict: %s\n", err ? "fail" : "ok");+ ret = err ? 1 : 0;}out:xfree(evidence, evidence ? evidence_len + 1 : 0);@@ -737,7 +839,7 @@ static int cmd_attest_challenge(int argc, const char **argv)goto out;}if (err) {- printf("verdict: FAIL\n");+ printf("verdict: fail\n");ret = 1;goto out;}diff --git a/builtin-bpm.c b/builtin-bpm.cindex 4a55aad6..c3673233 100644--- a/builtin-bpm.c+++ b/builtin-bpm.c@@ -841,7 +841,7 @@ static int key_fingerprint_compare(const void *a, const void *b)return strcmp(*(char * const *)a, *(char * const *)b);}-static int list_keys(void)+static int list_keys(bool json){char **fingerprints = NULL;size_t count = 0, cap = 0;@@ -850,9 +850,9 @@ static int list_keys(void)int ret = 0;dir = opendir(KEYS_DIR);- if (!dir)- return errno == ENOENT ? 0 : -errno;- for (;;) {+ if (!dir && errno != ENOENT)+ return -errno;+ while (dir) {char path[PATH_MAX], hex[65], **next;struct stat st;bool valid = true;@@ -892,12 +892,32 @@ static int list_keys(void)}count++;}- closedir(dir);- if (!ret && count) {+ if (dir)+ closedir(dir);+ if (!ret && count)qsort(fingerprints, count, sizeof(*fingerprints),key_fingerprint_compare);+ if (!ret && json) {+ char buf[8192];+ struct json_emit e = { .buf = buf, .cap = sizeof(buf) };++ json_obj_open(&e);+ json_kv_int(&e, "schema", 1);+ json_arr_open(&e, "fingerprints");for (size_t i = 0; i < count; i++)- puts(fingerprints[i]);+ json_str(&e, fingerprints[i]);+ json_arr_close(&e);+ json_obj_close(&e);+ if (e.err)+ ret = e.err;+ else+ puts(buf);+ } else if (!ret) {+ printf("Package certificates:\n");+ if (!count)+ printf(" none\n");+ for (size_t i = 0; i < count; i++)+ printf(" %s\n", fingerprints[i]);}for (size_t i = 0; i < count; i++)xstrfree(fingerprints[i]);@@ -1478,18 +1498,47 @@ static int cmd_bpm_config(int argc, const char **argv)if (argc < 3)return 2;if (!strcmp(argv[2], "list")) {+ bool json = argc == 4 && !strcmp(argv[3], "--json");+ char buf[8192];+ struct json_emit je = { .buf = buf, .cap = sizeof(buf) };DIR *d = registries_opendir();struct dirent *e;+ size_t count = 0;- if (!d)- return errno == ENOENT ? 0 : 1;- while ((e = readdir(d))) {+ if (argc != 3 && !json)+ return 2;+ if (json) {+ json_obj_open(&je);+ json_kv_int(&je, "schema", 1);+ json_arr_open(&je, "sources");+ } else {+ printf("Registered sources:\n");+ }+ while (d && (e = readdir(d))) {size_t n = strlen(e->d_name);+ char name[NAME_MAX + 1];- if (n > 5 && !strcmp(e->d_name + n - 5, ".conf"))- printf("%.*s\n", (int)(n - 5), e->d_name);+ if (n <= 5 || strcmp(e->d_name + n - 5, ".conf") ||+ strsprintf(name, sizeof(name), "%.*s",+ (int)(n - 5), e->d_name) < 0)+ continue;+ if (json)+ json_str(&je, name);+ else+ printf(" %s\n", name);+ count++;+ }+ if (d)+ closedir(d);+ if (json) {+ json_arr_close(&je);+ json_obj_close(&je);+ if (je.err)+ return 1;+ puts(buf);+ } else if (!count) {+ printf(" none\n");}- closedir(d);return 0;}if (image_config_active() &&@@ -2524,7 +2573,8 @@ static int cmd_bpm_key(int argc, const char **argv)print_help(&bpm_key_help);return 0;}- if ((!strcmp(sub, "list") && argc != 2) ||+ if ((!strcmp(sub, "list") && argc != 2 &&+ !(argc == 3 && !strcmp(argv[2], "--json"))) ||(strcmp(sub, "list") && argc != 3)) {print_help(&bpm_key_help);return 2;@@ -2535,7 +2585,7 @@ static int cmd_bpm_key(int argc, const char **argv)return 1;}if (!strcmp(sub, "list")) {- ret = list_keys();+ ret = list_keys(argc == 3);return ret ? bpm_fail("key list", ret) : 0;}if (curl_global_init(CURL_GLOBAL_DEFAULT) != CURLE_OK)@@ -2876,20 +2926,58 @@ int cmd_bpm(int argc, const char **argv)if (!strcmp(sub, "install") && argc == 3)return with_tables(bpm_install, argv[2], "install");if (!strcmp(sub, "list")) {+ bool json = argc == 3 && !strcmp(argv[2], "--json");struct bpm_state_entry *state;int n_state, ret;- if (argc != 2) {- fprintf(stderr, "usage: shirudo bpm list\n");+ if (argc != 2 && !json) {+ fprintf(stderr, "usage: shirudo bpm list [--json]\n");return argc == 3 && is_help(argv[2]) ? 0 : 2;}state = xcalloc(BPM_MAX_STATE, sizeof(*state));if (!state)return bpm_fail("list", -ENOMEM);ret = state_read(state, &n_state);- for (int i = 0; !ret && i < n_state; i++)- printf("%s %s %s\n", state[i].name, state[i].version,- state[i].source);+ if (!ret && json) {+ size_t cap = 256 + (size_t)n_state * 3 * BPM_MAX_NAME;+ char *buf = xmalloc(cap);+ struct json_emit e = { .buf = buf, .cap = cap };++ if (!buf) {+ ret = -ENOMEM;+ } else {+ json_obj_open(&e);+ json_kv_int(&e, "schema", 1);+ json_arr_open(&e, "packages");+ for (int i = 0; i < n_state; i++) {+ json_obj_open(&e);+ json_kv_string(&e, "name",+ state[i].name);+ json_kv_string(&e, "version",+ state[i].version);+ json_kv_string(&e, "source",+ state[i].source);+ json_obj_close(&e);+ }+ json_arr_close(&e);+ json_obj_close(&e);+ if (e.err)+ ret = e.err;+ else+ puts(buf);+ xfree(buf, cap);+ }+ } else if (!ret) {+ printf("Installed packages:\n");+ if (!n_state)+ printf(" none\n");+ else+ printf(" %-24s %-12s %s\n", "NAME",+ "VERSION", "SOURCE");+ for (int i = 0; i < n_state; i++)+ printf(" %-24s %-12s %s\n", state[i].name,+ state[i].version, state[i].source);+ }xfree(state, BPM_MAX_STATE * sizeof(*state));return ret ? bpm_fail("list", ret) : 0;}diff --git a/builtin-config.c b/builtin-config.cindex b4a28e7a..daa8eddf 100644--- a/builtin-config.c+++ b/builtin-config.c@@ -108,7 +108,7 @@ int cmd_config(int argc, const char **argv)image_mode ? "runtime image" :env && *env ? "$SHIRUDO_TPM_TCTI" : CONF_PATH);} else {- printf("# tpm.tcti = (unset -- using device:/dev/tpmrm0)\n\n");+ printf("# tpm.tcti = (unset, using device:/dev/tpmrm0)\n\n");}printf("# Exact DNS hosts that may use classical TLS key exchange.\n"diff --git a/builtin-genkey.c b/builtin-genkey.cindex e2bdae5a..cccbaba0 100644--- a/builtin-genkey.c+++ b/builtin-genkey.c@@ -371,7 +371,7 @@ static int replace_pair(const char *pkey_new, const char *pkey_path,static const struct help_item genkey_options[] = {{ "--force, -f", "overwrite an existing key/cert (refused otherwise)" },- { "--keys-dir <dir>", "write signing_key.pem + cert.der under <dir> "+ { "--keys-dir <dir>", "write signing_key.pem and cert.der under <dir> ""instead of the default" },};@@ -382,7 +382,7 @@ static const struct help_section genkey_help_sections[] = {static const struct help genkey_help = {.usage = "shirudo genkey [--force] [--keys-dir <dir>]",- .summary = "Generate a self-signed X.509 cert + ML-DSA-87 (FIPS 204) "+ .summary = "Generate a self-signed X.509 certificate and an ML-DSA-87 (FIPS 204) ""private key\nfor signing .upatch loader bytes. ""Operator-only; needs OpenSSL >= 3.5.",.sections = genkey_help_sections,diff --git a/builtin-image.c b/builtin-image.cindex 6e61e5a8..01858d90 100644--- a/builtin-image.c+++ b/builtin-image.c@@ -17,7 +17,7 @@ static void image_help(void)"usage: shirudo image build [image builder options]\n"" shirudo image verify <prefix> --cert <certificate>\n"" shirudo image update <prefix-or-https-prefix>\n"- " shirudo image status\n");+ " shirudo image status [--json]\n");}int cmd_image(int argc, const char **argv)@@ -51,8 +51,13 @@ int cmd_image(int argc, const char **argv)}if (!strcmp(argv[1], "update") && argc == 3) {ret = image_update(argv[2]);- } else if (!strcmp(argv[1], "status") && argc == 2) {- ret = image_status();+ } else if (!strcmp(argv[1], "status") &&+ (argc == 2 || (argc == 3 && !strcmp(argv[2], "--json")))) {+ ret = image_status(argc == 3);+ if (ret == -ENODEV) {+ pr_err("image status: no config activation state on this host");+ return 1;+ }} else {image_help();return 2;diff --git a/builtin-init.c b/builtin-init.cindex 1bc0b1ae..c4eced17 100644--- a/builtin-init.c+++ b/builtin-init.c@@ -63,18 +63,45 @@ static void print_preflight(const struct preflight_result *r){int i;- printf("pre-flight checks:\n");+ printf("Pre-flight checks:\n");for (i = 0; i < r->n; i++) {const struct preflight_check *c = &r->checks[i];- printf(" %-22s %s%s%s\n",- c->name,- c->ok ? "OK" : "FAIL",- c->detail[0] ? ": " : "",- c->detail);+ printf(" %-4s %s%s%s\n", c->ok ? "OK" : "FAIL", c->name,+ c->detail[0] ? ": " : "", c->detail);}- printf("%d/%d passed (%d failed)\n",- r->n - r->n_failed, r->n, r->n_failed);+ printf("%d of %d passed\n", r->n - r->n_failed, r->n);+}++static int print_preflight_json(const struct preflight_result *r)+{+ char buf[8192];+ struct json_emit e = { .buf = buf, .cap = sizeof(buf) };+ int i;++ json_obj_open(&e);+ json_kv_int(&e, "schema", 1);+ json_kv_int(&e, "passed", r->n - r->n_failed);+ json_kv_int(&e, "failed", r->n_failed);+ json_arr_open(&e, "checks");+ for (i = 0; i < r->n; i++) {+ const struct preflight_check *c = &r->checks[i];++ json_obj_open(&e);+ json_kv_string(&e, "name", c->name);+ json_kv_bool(&e, "ok", c->ok);+ if (c->detail[0])+ json_kv_string(&e, "detail", c->detail);+ else+ json_kv_null(&e, "detail");+ json_obj_close(&e);+ }+ json_arr_close(&e);+ json_obj_close(&e);+ if (e.err)+ return e.err;+ puts(buf);+ return 0;}static struct trusted_set enrolled;@@ -845,7 +872,7 @@ static int init_lsm(void)goto out;}- pr_info("%s + seal attached: lsm/bpf gate live, writable state sealed",+ pr_info("%s and seal attached: lsm/bpf gate live, writable state sealed",blob->name);err = 0;out:@@ -1243,8 +1270,8 @@ static int chain_extend_init(struct measured_upatch *set, size_t n)return ret;}if (ret) {- pr_err("tpm: register extend failed -- chain NOT advanced "- "while LSM active (tpm_error); operator must "+ pr_err("tpm: register extend failed, the chain did not advance "+ "while the LSM is active (tpm_error); the operator must ""reconcile");return ret;}@@ -1257,8 +1284,8 @@ static int chain_extend_init(struct measured_upatch *set, size_t n)ret = append_init_event(set, n, cert_sha, set_digest, tree_root,init_digest, &info);if (ret) {- pr_err("eventlog: append failed after extend -- chain/log "- "desync; operator must reconcile");+ pr_err("eventlog: append failed after the extend: register and "+ "log disagree; the operator must reconcile");return ret;}@@ -1280,6 +1307,7 @@ static int chain_extend_init(struct measured_upatch *set, size_t n)static const struct help_item init_options[] = {{ "--check-only", "run the pre-flight only; never touch kernel state" },+ { "--json", "with --check-only, print the checks as JSON" },};static const struct help_section init_help_sections[] = {@@ -1288,7 +1316,7 @@ static const struct help_section init_help_sections[] = {};static const struct help init_help = {- .usage = "shirudo init [--check-only]",+ .usage = "shirudo init [--check-only [--json]]",.summary = "Bootstrap enforcement on this target. Idempotent; safe ""to re-run.\nThe pinned link survives the process exit.",.sections = init_help_sections,@@ -1451,8 +1479,8 @@ static int run_init(void)ret = chain_extend_init(set, n);xfree(set, n * sizeof(*set));if (ret) {- pr_err("init: incomplete -- LSM active and upatches "- "loaded, but TPM register not advanced");+ pr_err("init: incomplete: LSM active and upatches loaded, but "+ "the TPM register did not advance");return init_phase_error(ret, "binding the TPM register");}@@ -1467,7 +1495,7 @@ static int run_init(void)int cmd_init(int argc, const char **argv){struct preflight_result res;- bool check_only = false;+ bool check_only = false, json = false;int i, ret;for (i = 1; i < argc; i++) {@@ -1477,6 +1505,10 @@ int cmd_init(int argc, const char **argv)check_only = true;continue;}+ if (strcmp(a, "--json") == 0) {+ json = true;+ continue;+ }if (is_help(a)) {print_help(&init_help);return 0;@@ -1492,11 +1524,20 @@ int cmd_init(int argc, const char **argv)pr_err("init: authenticated image settings: %s", strerror(-ret));return 1;}+ if (json && !check_only) {+ pr_err("init: --json takes --check-only");+ return 2;+ }preflight_run(&res);- print_preflight(&res);+ if (json) {+ if (print_preflight_json(&res))+ return 1;+ } else {+ print_preflight(&res);+ }if (res.n_failed > 0) {- pr_err("init: pre-flight failed (%d/%d checks)",+ pr_err("init: pre-flight failed, %d of %d checks",res.n_failed, res.n);return 1;}diff --git a/builtin-keys.c b/builtin-keys.cindex 176165a0..ae3ff5be 100644--- a/builtin-keys.c+++ b/builtin-keys.c@@ -154,6 +154,9 @@ out:return ret;}+/* Set while keys prints JSON: every printer below emits into it instead. */+static struct json_emit *keys_json;+static void print_fpr(const char *label, const __u8 *fpr){printf(" %-22s SHA256:", label);@@ -197,13 +200,39 @@ static int dump_operator_cert(X509 *cert, const char *cert_path,asn1_time_to_iso(nb, nb_s, sizeof(nb_s));self_signed = (X509_NAME_cmp(subj, iss) == 0);- printf("Cert (%s):\n", cert_path);+ if (keys_json) {+ char hex[65];++ json_obj_open_key(keys_json, "cert");+ json_kv_string(keys_json, "path", cert_path);+ json_kv_string(keys_json, "subject", subj_s);+ json_kv_string(keys_json, "issuer", iss_s);+ json_kv_bool(keys_json, "self_signed", self_signed);+ if (pub) {+ format_pkey_algorithm(pub, alg_s, sizeof(alg_s));+ json_kv_string(keys_json, "algorithm", alg_s);+ } else {+ json_kv_null(keys_json, "algorithm");+ }+ if (compute_cert_fpr(cert, fpr) == 0) {+ hex_encode(fpr, SHA256_DIGEST_LENGTH, hex);+ json_kv_string(keys_json, "fingerprint", hex);+ } else {+ json_kv_null(keys_json, "fingerprint");+ }+ hex_encode(cert_spki_fpr, SHA256_DIGEST_LENGTH, hex);+ json_kv_string(keys_json, "spki_fingerprint", hex);+ json_kv_string(keys_json, "not_before", nb_s);+ json_obj_close(keys_json);+ return 0;+ }+ printf("Certificate (%s):\n", cert_path);printf(" %-22s %s\n", "Subject:", subj_s);printf(" %-22s %s%s\n", "Issuer:", iss_s,self_signed ? " (self-signed)" : "");if (pub) {format_pkey_algorithm(pub, alg_s, sizeof(alg_s));- printf(" %-22s %s\n", "Public-key:", alg_s);+ printf(" %-22s %s\n", "Public key:", alg_s);}if (compute_cert_fpr(cert, fpr) == 0)print_fpr("Fingerprint:", fpr);@@ -216,42 +245,60 @@ static int dump_signing_key(const char *pkey_path,const __u8 cert_spki_fpr[SHA256_DIGEST_LENGTH]){__u8 fpr_priv[SHA256_DIGEST_LENGTH];- char alg_s[64];+ char alg_s[64], hex[65];EVP_PKEY *priv;+ bool matches;int ret = 0;if (!path_exists(pkey_path)) {+ if (keys_json) {+ json_obj_open_key(keys_json, "signing_key");+ json_kv_string(keys_json, "path", pkey_path);+ json_kv_bool(keys_json, "present", false);+ json_obj_close(keys_json);+ return 0;+ }printf("Signing key (%s):\n", pkey_path);printf(" %-22s %s\n", "Present:",- "no (target host -- private key lives on the operator)");+ "no, a target holds no private key");return 0;}priv = read_priv_pem(pkey_path);if (!priv)return -1;-- printf("Signing key (%s):\n", pkey_path);- printf(" %-22s %s\n", "Present:", "yes");format_pkey_algorithm(priv, alg_s, sizeof(alg_s));- printf(" %-22s %s\n", "Algorithm:", alg_s);-+ if (keys_json) {+ json_obj_open_key(keys_json, "signing_key");+ json_kv_string(keys_json, "path", pkey_path);+ json_kv_bool(keys_json, "present", true);+ json_kv_string(keys_json, "algorithm", alg_s);+ } else {+ printf("Signing key (%s):\n", pkey_path);+ printf(" %-22s %s\n", "Present:", "yes");+ printf(" %-22s %s\n", "Algorithm:", alg_s);+ }if (compute_spki_fpr(priv, fpr_priv) != 0) {ret = -1;goto out;}- print_fpr("SPKI fingerprint:", fpr_priv);-- if (memcmp(fpr_priv, cert_spki_fpr, SHA256_DIGEST_LENGTH) == 0) {- printf(" %-22s %s\n", "Cert match:",- "OK (signing key matches cert)");+ matches = memcmp(fpr_priv, cert_spki_fpr, SHA256_DIGEST_LENGTH) == 0;+ if (keys_json) {+ hex_encode(fpr_priv, SHA256_DIGEST_LENGTH, hex);+ json_kv_string(keys_json, "spki_fingerprint", hex);+ json_kv_bool(keys_json, "matches_cert", matches);} else {- printf(" %-22s %s\n", "Cert match:",- "MISMATCH (private key does NOT match cert)");+ print_fpr("SPKI fingerprint:", fpr_priv);+ printf(" %-22s %s\n", "Matches cert:", matches ? "yes" :+ "no, the private key is not the certificate's");+ }+ if (!matches) {pr_warn("keys: private key and cert have different public keys");ret = -1;}out:+ if (keys_json)+ json_obj_close(keys_json);EVP_PKEY_free(priv);return ret;}@@ -280,7 +327,8 @@ static int keys_dump_disk_material(const char *cert_path,ret = dump_operator_cert(cert, cert_path, cert_spki_fpr);if (ret == 0) {- printf("\n");+ if (!keys_json)+ printf("\n");ret = dump_signing_key(pkey_path, cert_spki_fpr);}X509_free(cert);@@ -321,13 +369,53 @@ static int keys_list_keyring(key_serial_t ring, const struct keys_anchor *a,size_t n = 0, i;int ret;+ if (keys_json) {+ json_obj_open(keys_json);+ json_kv_string(keys_json, "name", a->label);+ json_kv_bool(keys_json, "present", true);+ json_kv_int(keys_json, "serial", ring);+ if (frozen)+ json_kv_int(keys_json, "frozen_serial", a->frozen);+ else+ json_kv_null(keys_json, "frozen_serial");+ ret = keyring_links(ring, &links, &n);+ json_arr_open(keys_json, "members");+ for (i = 0; !ret && i < n; i++) {+ const struct keyring_link *l = &links[i];++ json_obj_open(keys_json);+ json_kv_int(keys_json, "serial", l->serial);+ if (l->err) {+ json_kv_null(keys_json, "type");+ json_kv_null(keys_json, "description");+ } else {+ json_kv_string(keys_json, "type", l->type);+ json_kv_string(keys_json, "description",+ l->description);+ }+ if (frozen)+ json_kv_bool(keys_json, "frozen",+ keys_anchor_holds(a, l->serial));+ else+ json_kv_null(keys_json, "frozen");+ json_obj_close(keys_json);+ }+ json_arr_close(keys_json);+ json_obj_close(keys_json);+ if (ret) {+ pr_err("keyring list: %s", strerror(-ret));+ return 1;+ }+ xfree(links, n * sizeof(*links));+ return 0;+ }printf("Keyring (%s):\n", a->label);printf(" %-22s %d\n", "Serial:", (int)ring);if (frozen) {printf(" %-22s %d (%s)\n", "Frozen serial:", (int)a->frozen,- a->frozen == ring ? "matches" : "MISMATCH");+ a->frozen == ring ? "matches" : "swapped");if (a->frozen != ring)- pr_warn("%s keyring serial %d != frozen %d (swap?)",+ pr_warn("%s keyring serial %d is not the frozen %d: swapped",a->label, (int)ring, (int)a->frozen);} else if (!id_rc || id_rc == -ENOENT) {printf(" %-22s %s\n", "Frozen serial:", "(none this boot)");@@ -355,7 +443,7 @@ static int keys_list_keyring(key_serial_t ring, const struct keys_anchor *a,print_safe(l->description);if (frozen)printf(" (%s)", keys_anchor_holds(a, l->serial) ?- "frozen" : "NOT frozen");+ "frozen" : "not frozen");printf("\n");}xfree(links, n * sizeof(*links));@@ -365,19 +453,40 @@ static int keys_list_keyring(key_serial_t ring, const struct keys_anchor *a,static void keyring_absent(const struct keys_anchor *a, key_serial_t ret,int id_rc){- printf("Keyring (%s):\n", a->label);+ char reason[128];++ int n;+if (ret != (key_serial_t)-ENOKEY)- printf(" %-22s lookup error: %s\n", "Present:",- strerror(-ret));+ n = strsprintf(reason, sizeof(reason), "lookup error: %s",+ strerror(-ret));else if (!id_rc && a->frozen > 0)- printf(" %-22s no (gone: init froze serial %d this boot)\n",- "Present:", (int)a->frozen);+ n = strsprintf(reason, sizeof(reason),+ "gone, init froze serial %d this boot",+ (int)a->frozen);else if (!id_rc || id_rc == -ENOENT)- printf(" %-22s %s\n", "Present:",- "no (operator host, or `shirudo init` not yet run)");+ n = strscpy(reason, "absent before init", sizeof(reason));else- printf(" %-22s unknown (frozen identity unreadable: %s)\n",- "Present:", strerror(-id_rc));+ n = strsprintf(reason, sizeof(reason),+ "frozen identity unreadable: %s",+ strerror(-id_rc));+ if (n < 0)+ strscpy(reason, "?", sizeof(reason));+ if (keys_json) {+ json_obj_open(keys_json);+ json_kv_string(keys_json, "name", a->label);+ json_kv_bool(keys_json, "present", false);+ json_kv_null(keys_json, "serial");+ if (!id_rc && a->frozen > 0)+ json_kv_int(keys_json, "frozen_serial", a->frozen);+ else+ json_kv_null(keys_json, "frozen_serial");+ json_kv_string(keys_json, "reason", reason);+ json_obj_close(keys_json);+ return;+ }+ printf("Keyring (%s):\n", a->label);+ printf(" %-22s no, %s\n", "Present:", reason);}static const struct help_item keys_subcmds[] = {@@ -387,7 +496,8 @@ static const struct help_item keys_subcmds[] = {};static const struct help_item keys_options[] = {- { "--keys-dir <dir>", "read signing_key.pem + cert.der from <dir>" },+ { "--keys-dir <dir>", "read signing_key.pem and cert.der from <dir>" },+ { "--json", "print the key material as JSON" },};static const struct help_section keys_help_sections[] = {@@ -397,7 +507,7 @@ static const struct help_section keys_help_sections[] = {};static const struct help keys_help = {- .usage = "shirudo keys [--keys-dir <dir>]\n"+ .usage = "shirudo keys [--keys-dir <dir>] [--json]\n"" shirudo keys add <cert.der> --vouch <file>\n"" shirudo keys revoke <fingerprint> [--promote <fp>]\n"" shirudo keys vouch <cert.der> [-o <file>]",@@ -440,7 +550,7 @@ static const struct help keys_add_help = {static const struct help_item keys_vouch_options[] = {{ "-o <file>", "where to write the vouch (default <cert.der>.vouch)" },- { "--keys-dir <dir>", "read signing_key.pem + cert.der from <dir>" },+ { "--keys-dir <dir>", "read signing_key.pem and cert.der from <dir>" },{ "--key <pem>", "the signing key (overrides --keys-dir)" },{ "--cert <der>", "the signing certificate (overrides --keys-dir)" },};@@ -705,8 +815,8 @@ static int measure_revoke_locked(const struct trusted_cert *c,hex_encode(c->sha256, 32, sha_hex);ret = append_key_event("key_revoke", fp_hex, sha_hex, event);if (ret) {- pr_err("keys revoke: eventlog append failed after extend -- "- "chain/log desync; operator must reconcile");+ pr_err("keys revoke: eventlog append failed after the extend: "+ "register and log disagree; the operator must reconcile");return ret;}hex_encode(chain, 32, chain_hex);@@ -879,12 +989,13 @@ int cmd_keys(int argc, const char **argv)static int keys_show(int argc, const char **argv){const char *keys_dir_arg = NULL;+ struct json_emit je = { .cap = 65536 };struct identity id = {};struct trusted_set set;const char *keys_dir;char pkey_path[PATH_MAX];char cert_path[PATH_MAX];- bool shown = false;+ bool shown = false, json = false, have_set = false;int ret = 0, id_rc;for (int i = 1; i < argc; i++) {@@ -893,6 +1004,8 @@ static int keys_show(int argc, const char **argv)keys_dir_arg = argv[++i];} else if (strncmp(argv[i], "--keys-dir=", 11) == 0) {keys_dir_arg = argv[i] + 11;+ } else if (strcmp(argv[i], "--json") == 0) {+ json = true;} else if (is_help(argv[i])) {print_help(&keys_help);return 0;@@ -924,33 +1037,64 @@ static int keys_show(int argc, const char **argv)* rather than picking one mode: the on-disk cert + signing key,* then the kernel keyring once `shirudo init` has populated one.*/+ if (json) {+ je.buf = xmalloc(je.cap);+ if (!je.buf)+ return 1;+ keys_json = &je;+ json_obj_open(&je);+ json_kv_int(&je, "schema", 1);+ }if (path_exists(cert_path)) {if (keys_dump_disk_material(cert_path, pkey_path))ret = 1;shown = true;+ } else if (json) {+ json_kv_null(&je, "cert");+ json_kv_null(&je, "signing_key");}- if (keys_load(keys_dir, NULL, true, &set) == 0 &&- (set.n > 1 || set.n_revoked || set.n_unvouched)) {+ have_set = keys_load(keys_dir, NULL, true, &set) == 0;+ if (json)+ json_arr_open(&je, "trusted_set");+ if (have_set && (json || set.n > 1 || set.n_revoked ||+ set.n_unvouched)) {size_t i;- printf("%sTrusted set (%zu member%s, %zu revoked, "- "%zu unvouched):\n", shown ? "\n" : "", set.n,- set.n == 1 ? "" : "s", set.n_revoked, set.n_unvouched);+ if (!json)+ printf("%sTrusted set (%zu member%s, %zu revoked, "+ "%zu unvouched):\n", shown ? "\n" : "", set.n,+ set.n == 1 ? "" : "s", set.n_revoked,+ set.n_unvouched);for (i = 0; i < set.n; i++) {- char fp[65], sha[65];+ char fp[65], sha[65], voucher[65];hex_encode(set.certs[i].fingerprint, 32, fp);hex_encode(set.certs[i].sha256, 32, sha);+ hex_encode(set.certs[i].voucher, 32, voucher);+ if (json) {+ json_obj_open(&je);+ json_kv_string(&je, "fingerprint", fp);+ json_kv_string(&je, "sha256", sha);+ json_kv_bool(&je, "primary",+ set.certs[i].primary);+ if (set.certs[i].primary)+ json_kv_null(&je, "voucher");+ else+ json_kv_string(&je, "voucher", voucher);+ json_obj_close(&je);+ continue;+ }printf(" %s%s\n sha256 %s\n", fp,set.certs[i].primary ? " (primary)" : "", sha);- if (set.certs[i].primary)- continue;- hex_encode(set.certs[i].voucher, 32, fp);- printf(" vouched by %s\n", fp);+ if (!set.certs[i].primary)+ printf(" vouched by %s\n", voucher);}- shown = true;+ if (!json)+ shown = true;}+ if (json)+ json_arr_close(&je);id_rc = identity_read(&id);{@@ -964,35 +1108,50 @@ static int keys_show(int argc, const char **argv)};size_t i;+ if (json)+ json_arr_open(&je, "keyrings");for (i = 0; i < ARRAY_SIZE(anchors); i++) {const struct keys_anchor *a = &anchors[i];key_serial_t ring = id_rc ? -ENOKEY : a->serial();if (ring >= 0) {- if (shown)+ if (shown && !json)printf("\n");if (keys_list_keyring(ring, a, id_rc))ret = 1;shown = true;} else if (ring == -ENOKEY && id_rc) {- if (shown) {- printf("\n");+ if (shown || json) {+ if (!json)+ printf("\n");keyring_absent(a, ring, id_rc);}} else {- if (shown)+ if (shown && !json)printf("\n");keyring_absent(a, ring, id_rc);shown = true;ret = 1;}}+ if (json)+ json_arr_close(&je);+ }+ if (json) {+ json_obj_close(&je);+ keys_json = NULL;+ if (je.err) {+ pr_err("keys: json encode failed");+ ret = 1;+ } else {+ puts(je.buf);+ }+ xfree(je.buf, je.cap);}-if (!shown) {pr_err("no shirudo key material on this host: no %s and no "- "\"%s\" kernel keyring -- run `shirudo genkey` "- "(operator) or `shirudo init` (target)",+ "%s kernel keyring; run shirudo genkey on an operator "+ "or shirudo init on a target",cert_path, ".bpf");ret = 1;}diff --git a/builtin-status.c b/builtin-status.cindex 1bff679b..44923b3b 100644--- a/builtin-status.c+++ b/builtin-status.c@@ -37,7 +37,6 @@#include "util/crypto.h"#include "util/eventlog.h"-#define KERNEL_LOG_MAX 100#include "util/help.h"#include "util/io.h"#include "util/json.h"@@ -50,8 +49,6 @@#include "util/malloc.h"#include "util/paths.h"#include "util/initrd.h"-#include "util/kmodules.h"-#include "util/kmsg.h"#include "util/format.h"#include "util/sysinfo.h"#include "util/timefmt.h"@@ -281,7 +278,7 @@ static void print_eventlog_table(void)if (read_file(eventlog_path(), JSON_MAX_BYTES,&buf, &len) != 0)return;- printf("\nEventlog (audit trail):\n");+ printf("\nEventlog:\n");printf(" %-20s %-13s %-13s %s\n", "TIME", "TYPE", "DIGEST","DETAIL");for (line = strtok_r(buf, "\n", &save); line;@@ -303,17 +300,17 @@ static void print_eventlog_table(void)static void print_system_human(const struct sysinfo *si){- printf("\nSystem Info:\n");- printf(" %-16s %s\n", "OS:", si->os_pretty);- printf(" %-16s %s\n", "Kernel:", si->kernel_release);+ printf("\nSystem:\n");+ printf(" %-22s %s\n", "OS:", si->os_pretty);+ printf(" %-22s %s\n", "Kernel:", si->kernel_release);if (si->kernel_version[0])- printf(" %-16s %s\n", "Kernel Version:", si->kernel_version);+ printf(" %-22s %s\n", "Kernel version:", si->kernel_version);if (si->kernel_build_id[0])- printf(" %-16s %s\n", "Kernel Build ID:",+ printf(" %-22s %s\n", "Kernel build ID:",si->kernel_build_id);- printf(" %-16s %s\n", "Architecture:", si->machine);+ printf(" %-22s %s\n", "Architecture:", si->machine);if (si->nproc > 0)- printf(" %-16s %ld\n", "CPUs:", si->nproc);+ printf(" %-22s %ld\n", "CPUs:", si->nproc);if (si->mem_total_kb > 0) {char tot[16], used[16];@@ -324,9 +321,9 @@ static void print_system_human(const struct sysinfo *si)human_size((__u64)(si->mem_total_kb -si->mem_avail_kb) * 1024,used, sizeof(used));- printf(" %-16s %s/%s\n", "Memory:", used, tot);+ printf(" %-22s %s/%s\n", "Memory:", used, tot);} else {- printf(" %-16s %s\n", "Memory:", tot);+ printf(" %-22s %s\n", "Memory:", tot);}}if (si->disk_total_kb > 0) {@@ -336,47 +333,28 @@ static void print_system_human(const struct sysinfo *si)tot, sizeof(tot));human_size((__u64)si->disk_used_kb * 1024,used, sizeof(used));- printf(" %-16s %s/%s\n", "Disk:", used, tot);+ printf(" %-22s %s/%s\n", "Disk:", used, tot);}if (si->uptime_sec >= 0)- printf(" %-16s %ldd %ldh %ldm\n", "Uptime:",+ printf(" %-22s %ldd %ldh %ldm\n", "Uptime:",si->uptime_sec / 86400,(si->uptime_sec % 86400) / 3600,(si->uptime_sec % 3600) / 60);- if (si->hostname[0])- printf(" %-16s %s\n", "Hostname:", si->hostname);if (si->machine_id[0])- printf(" %-16s %s\n", "Machine ID:", si->machine_id);+ printf(" %-22s %s\n", "Machine ID:", si->machine_id);if (si->boot_id[0])- printf(" %-16s %s\n", "Boot ID:", si->boot_id);-}--static void print_kernel_config_entry(void *ctx, const char *key,- const char *value)-{- printf(" %s=%s\n", key, value);-}--static void print_kernel_config_human(const struct sysinfo *si)-{- printf(" Kernel Config:\n");- if (sysinfo_kernel_config_foreach(si->kernel_release,- print_kernel_config_entry,- NULL) < 0)- printf(" (unavailable)\n");+ printf(" %-22s %s\n", "Boot ID:", si->boot_id);}static const struct help_item status_options[] = {- { "--json", "machine-readable JSON output" },- { "--otel", "export the status report as an OTLP log" },- { "--include-system", "add a `system` block (hostname, kernel, arch, cpus, ...)" },- { "--include-eventlog", "dump eventlog entries" },- { "--include-kernellog[=N]", "last N lines of the kernel ring buffer "- "(default 10, max 100)" },- { "--include-modules",- "loaded kernel modules (10 most recent; --show-full for tree)" },- { "--show-full", "opt into a full dump: implies every --include-* flag and "- "expands the loaded-modules dependency tree" },+ { "--json", "print the report as one JSON document" },+ { "--otel", "send the JSON report as an OTLP keepalive log" },+ { "--check", "exit 1 when the verdict is tampered" },+ { "--show-full", "print every section, folded or not, and the "+ "system and eventlog sections" },+ { "--include-system", "add the system section: OS, kernel, machine, "+ "memory, disk, uptime" },+ { "--include-eventlog", "add this boot's eventlog records" },};static const struct help_section status_help_sections[] = {@@ -385,12 +363,15 @@ static const struct help_section status_help_sections[] = {};static const struct help status_help = {- .usage = "shirudo status [--json] [--otel] "- "[--include-system] [--include-eventlog]\n"- " [--include-kernellog[=N]] "- "[--include-modules] [--show-full]",- .summary = "Local readiness + state report. Auto-detects target "- "vs operator role.\nSafe to run before `shirudo init`.",+ .usage = "shirudo status [--json | --otel] [--check] "+ "[--show-full]\n"+ " [--include-system] "+ "[--include-eventlog]",+ .summary = "Report the state of this host: the verdict, the "+ "conditions behind it, the\ntamper counters and the "+ "loaded upatches. A section whose condition is not OK\n"+ "unfolds below them. Safe to run before init, on a target "+ "or an operator host.",.sections = status_help_sections,.n_sections = ARRAY_SIZE(status_help_sections),};@@ -792,7 +773,7 @@ static void print_link(const struct status_keyring *k, size_t i,(int)l->serial);print_safe(l->description);}- printf(" (%s)\n", k->state[i].frozen ? "frozen" : "NOT frozen");+ printf(" (%s)\n", k->state[i].frozen ? "frozen" : "not frozen");}static void print_keyring_certs(const struct status_keyring *k,@@ -840,9 +821,7 @@ 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)");+ printf(" %-22s %s\n", "Serial:", "absent before init");else if (k->serial == -ENOKEY)printf(" %-22s %s\n", "Serial:", "absent");else@@ -855,11 +834,8 @@ static void print_keyring_serials(const struct status_keyring *k)strerror(-k->pinned));elseprintf(" %-22s %lld%s\n", "Frozen serial:",- (__s64)k->pinned, k->serial < 0 ?- " (GONE -- removed?)" :- k->serial == k->pinned ?- " (matches)" :- " (MISMATCH -- swapped?)");+ (__s64)k->pinned, k->serial < 0 ? " (gone)" :+ k->serial == k->pinned ? " (matches)" : " (swapped)");if (k->links_rc && k->serial >= 0)printf(" %-22s unreadable: %s\n", "Links:",strerror(-k->links_rc));@@ -870,9 +846,9 @@ int cmd_status(int argc, const char **argv)bool json = false;bool json_stdout = false, otel = false;bool include_system = false, include_eventlog = false;- bool include_kernel_log = false, include_modules = false;- bool show_full = false;- __u32 kernel_log_lines = 10;+ bool show_full = false, check = false;+ char hostname[256] = "?";+ char reason[160];bool lsm_attached, keyring_present, is_operator, cert_present, is_target;key_serial_t keyring_serial, keyring_pinned;const char *keyring_mode, *mode;@@ -920,23 +896,8 @@ int cmd_status(int argc, const char **argv)include_system = true;} else if (strcmp(argv[i], "--include-eventlog") == 0) {include_eventlog = true;- } else if (strcmp(argv[i], "--include-kernellog") == 0) {- include_kernel_log = true;- } else if (strncmp(argv[i], "--include-kernellog=", 20) == 0) {- const char *n = argv[i] + 20;- __u64 v;-- if (parse_u64(n, strlen(n), KERNEL_LOG_MAX, &v) ||- v < 1) {- fprintf(stderr, "status: --include-kernellog=N "- "must be 1..%d\n",- KERNEL_LOG_MAX);- return 2;- }- include_kernel_log = true;- kernel_log_lines = (__u32)v;- } else if (strcmp(argv[i], "--include-modules") == 0) {- include_modules = true;+ } else if (strcmp(argv[i], "--check") == 0) {+ check = true;} else if (strcmp(argv[i], "--show-full") == 0) {show_full = true;} else if (is_help(argv[i])) {@@ -971,19 +932,15 @@ int cmd_status(int argc, const char **argv)status_otel_endpoint_configured(&otel_cfg);}- /*- * --show-full is the one-switch verbose mode: every section the- * --include-* flags can opt into, plus the modules dep-tree. Stack- * it on first so any individual --include-* already given is a no-op.- */if (show_full) {include_system = true;include_eventlog = true;- include_kernel_log = true;- include_modules = true;}if (include_system)sysinfo_gather(&sysi);+ if (gethostname(hostname, sizeof(hostname)))+ strscpy(hostname, "?", sizeof(hostname));+ hostname[sizeof(hostname) - 1] = '\0';fd = bpf_obj_get(LSM_LINK_PIN);lsm_attached = fd >= 0;@@ -1120,10 +1077,6 @@ int cmd_status(int argc, const char **argv)(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)- json_cap += (size_t)kernel_log_lines * 1024 + 4096;- if (include_modules)- json_cap += 64 * 1024;if (include_system)json_cap += 1024 * 1024;if (json_cap > JSON_MAX_BYTES)@@ -1139,6 +1092,7 @@ int cmd_status(int argc, const char **argv)json_obj_open(&e);json_kv_int(&e, "schema", 1);json_kv_string(&e, "version_id", shirudo_version_id);+ json_kv_string(&e, "host", hostname);json_kv_bool(&e, "is_target", is_target);json_kv_bool(&e, "is_operator", is_operator);{@@ -1148,6 +1102,11 @@ int cmd_status(int argc, const char **argv)otel_status = status_verdict(&cin);json_kv_string(&e, "status",otel_status);+ status_reason(&cin, reason, sizeof(reason));+ if (reason[0])+ json_kv_string(&e, "reason", reason);+ else+ json_kv_null(&e, "reason");nc = conditions(&cin, conds,ARRAY_SIZE(conds));json_arr_open(&e, "conditions");@@ -1319,83 +1278,6 @@ int cmd_status(int argc, const char **argv)json_obj_close(&e);tree_emit_status(&e);}- if (include_kernel_log) {- size_t bytes = (size_t)kernel_log_lines *- sizeof(struct kmsg_record);- struct kmsg_record *recs = xmalloc(bytes);- int nr = recs ? kmsg_tail(recs, kernel_log_lines)- : -ENOMEM;- int j;-- json_arr_open(&e, "kernel_log");- for (j = 0; j < nr; j++) {- json_obj_open(&e);- json_kv_string(&e, "ts", recs[j].ts);- json_kv_string(&e, "msg", recs[j].msg);- json_obj_close(&e);- }- json_arr_close(&e);- xfree(recs, bytes);- }- if (include_modules) {- struct kmod_set ks = {};- int mrc = kmodules_read(&ks);- struct timespec rt = {}, bt = {};- __s64 boot_sec = 0;- char boot_iso[32] = "";- size_t mi;-- if (clock_gettime(CLOCK_REALTIME, &rt) == 0 &&- clock_gettime(CLOCK_BOOTTIME, &bt) == 0) {- boot_sec = (__s64)rt.tv_sec - bt.tv_sec;- iso8601((time_t)boot_sec, boot_iso,- sizeof(boot_iso));- }- json_kv_string(&e, "boot_at",- boot_iso[0] ? boot_iso : "");- json_arr_open(&e, "modules");- if (mrc == 0) {- for (mi = 0; mi < ks.n; mi++) {- const struct kmod *m =- &ks.mods[mi];- time_t at = m->loaded_at_sec;- char iso[32] = "";- __u16 di;-- if (at > 0)- iso8601(at, iso,- sizeof(iso));- json_obj_open(&e);- json_kv_string(&e, "name",- m->name);- json_kv_int(&e, "size",- (__s64)m->size);- json_kv_int(&e, "refcount",- m->refcount);- json_kv_string(&e, "loaded_at",- iso);- if (boot_sec > 0 &&- m->loaded_at_sec >= boot_sec)- json_kv_int(&e,- "since_boot_sec",- m->loaded_at_sec - boot_sec);- else- json_kv_null(&e,- "since_boot_sec");- json_arr_open(&e, "deps");- for (di = 0; di < m->n_deps; di++) {- size_t dk = ks.deps[m->deps_off- + di];- json_str(&e,- ks.mods[dk].name);- }- json_arr_close(&e);- json_obj_close(&e);- }- }- json_arr_close(&e);- kmodules_free(&ks);- }json_obj_close(&e);if (e.err) {@@ -1439,40 +1321,49 @@ int cmd_status(int argc, const char **argv)} else {struct condition conds[CONDITIONS_MAX];struct upatch_table_row *rows = NULL;+ bool keyrings_open, tpm_open;+ const char *folded[3];size_t n_rows = 0;- size_t nc;- char hostname[256] = "?";- char reason[160];+ size_t nc, ci, nf = 0;const char *verdict;verdict = status_verdict(&cin);status_reason(&cin, reason, sizeof(reason));nc = conditions(&cin, conds, ARRAY_SIZE(conds));n_rows = build_upatches_table(ups, n_ups, &rows);- if (gethostname(hostname, sizeof(hostname)))- strscpy(hostname, "?", sizeof(hostname));- hostname[sizeof(hostname) - 1] = '\0';-- printf("Host: %s\n", hostname);- printf("Roles: %s\n",+ /*+ * A section a condition vouches for says nothing the+ * condition did not: it unfolds when that condition is not+ * OK on a target, or on request.+ */+ keyrings_open = show_full;+ tpm_open = show_full;+ for (ci = 0; is_target && ci < nc; ci++) {+ if (!strcmp(conds[ci].status, "OK"))+ continue;+ if (!strcmp(conds[ci].type, "KeyringSealed"))+ keyrings_open = true;+ else if (!strcmp(conds[ci].type, "ChainIntact") ||+ !strcmp(conds[ci].type, "TpmMeasured"))+ tpm_open = true;+ }+ printf("%-22s %s\n", "Host:", hostname);+ printf("%-22s %s\n", "Roles:",roles_str(is_target, is_operator));- printf("Mode: %s\n", mode);+ printf("%-22s %s\n", "Mode:", mode);if (reason[0])- printf("Status: %s (%s)\n", verdict,+ printf("%-22s %s (%s)\n", "Status:", verdict,reason);else- printf("Status: %s\n", verdict);- printf("Version-ID: %s\n", shirudo_version_id);-+ printf("%-22s %s\n", "Status:", verdict);+ printf("%-22s %s\n", "Version ID:", shirudo_version_id);printf("\n");conditions_print(conds, nc);-printf("\nTamper attempts (this boot):\n");if (tamper_rc == -ENOENT)- printf(" (none recorded: init has not pinned the counters "- "this boot)\n");+ printf(" none recorded before init\n");else if (tamper_rc)- printf(" (unavailable: %s)\n", strerror(-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++) {@@ -1482,177 +1373,135 @@ int cmd_status(int argc, const char **argv)(__u64)tamper.count[i],tamper_meaning(i));}-- printf("\nKeyring (.bpf):\n");- print_keyring_serials(&bpf);- if (certs_rc == 0) {- printf(" %-22s %zu trusted, %zu revoked, %zu "- "unvouched", "Certificates:", certs.n,- certs.n_revoked, certs.n_unvouched);- if (certs_enrolled >= 0)- printf(", %d in the bpf keyring",- certs_enrolled);- printf("\n");- 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);- print_kernel_config_human(&sysi);- }-upatch_table_print(rows, n_rows);xfree(rows, n_rows * sizeof(*rows));rows = NULL;-- {- printf("\nTPM Measurement:\n");- printf(" %-18s %s (%s)\n", "TPM:",- cst.tpm ? "reachable" : "NOT reachable", tcti);- printf(" %-18s %s (anchored in PCR %u)\n", "NV index:",+ if (keyrings_open) {+ printf("\nKeyring (.bpf):\n");+ print_keyring_serials(&bpf);+ if (certs_rc == 0) {+ printf(" %-22s %zu trusted, %zu revoked, %zu "+ "unvouched", "Certificates:", certs.n,+ certs.n_revoked, certs.n_unvouched);+ if (certs_enrolled >= 0)+ printf(", %d in the bpf keyring",+ certs_enrolled);+ printf("\n");+ 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);+ } else {+ folded[nf++] = "keyrings";+ }+ if (tpm_open) {+ printf("\nTPM measurement:\n");+ printf(" %-22s %s (%s)\n", "TPM:",+ cst.tpm ? "reachable" : "not reachable", tcti);+ printf(" %-22s %s (anchored in PCR %u)\n", "NV index:",nv_index, CHAIN_PCR);if (chain_rc == 0) {- printf(" %-18s %s\n", "Chain:", chain_hex);- printf(" %-18s %s\n", "Register name:",+ printf(" %-22s %s\n", "Chain:", chain_hex);+ printf(" %-22s %s\n", "Register name:",name_hex);- printf(" %-18s %s\n", "Anchored:",- cst.anchored ? "yes (name on record)" :- "NO (index is not the one init bound)");+ printf(" %-22s %s\n", "Anchored:",+ cst.anchored ? "yes, name on record" :+ "no, the index is not the one init bound");} else if (!cst.tpm) {- printf(" %-18s %s\n", "Chain:",- "unavailable (no TPM answered)");+ printf(" %-22s %s\n", "Chain:",+ "unavailable, no TPM answered");} else if (chain_rc == -ENODEV) {- printf(" %-18s %s\n", "Chain:",- "unavailable (register not bound this "- "boot)");+ printf(" %-22s %s\n", "Chain:",+ "unavailable, register not bound this "+ "boot");} else {- printf(" %-18s unavailable (TPM error: %s)\n",+ printf(" %-22s unavailable, TPM error: %s\n","Chain:", strerror(-chain_rc));}if (cst.logged) {- printf(" %-18s %s\n", "PCR before init:",+ printf(" %-22s %s\n", "PCR before init:",pcr_before_hex);- printf(" %-18s %s (PCR %u)\n", "Phase at init:",+ printf(" %-22s %s (PCR %u)\n", "Phase at init:",phase_before_hex, CHAIN_PHASE_PCR);- printf(" %-18s %s\n", "Bound in:",+ printf(" %-22s %s\n", "Bound in:",cst.init.initrd ? "initrd" :"root file system");}if (cst.rebound)- printf(" %-18s %u for this TPM reset "- "(REBOUND after init; tamper?)\n",+ printf(" %-22s %u for this TPM reset, "+ "rebound after init\n","Init records:",cst.init.records_epoch);- printf(" %-18s %s\n", "Chain vs eventlog:",- match < 0 ? "n/a" :- match ? "matches" : "MISMATCH (tamper?)");+ printf(" %-22s %s\n", "Chain vs eventlog:",+ match < 0 ? "not evaluated" :+ match ? "matches" : "mismatch");if (ev_rc == 0)- printf(" %-18s %s (%ld entries, %ld bytes)\n",+ printf(" %-22s %s (%ld entries, %ld bytes)\n","Eventlog:", eventlog_path(),ev_entries, ev_bytes);else- printf(" %-18s absent\n", "Eventlog:");+ printf(" %-22s absent\n", "Eventlog:");+ } else {+ folded[nf++] = "TPM measurement";}-if (include_eventlog)print_eventlog_table();-- printf("\nAssets (%s):\n", VAR_LIB);- printf(" %-22s %s\n", "keys/cert.der",- assets.cert ? "present" : "absent");- printf(" %-22s %s\n", "keys/signing_key.pem",- assets.signing_key ? "present" : "absent");- if (assets.eventlog)- printf(" %-22s present (%ld bytes)\n", "eventlog",- assets.eventlog_bytes);- else- printf(" %-22s absent\n", "eventlog");- if (assets.n_upatches < 0)- printf(" %-22s absent\n", "upatches/");- else- printf(" %-22s %d .upatch\n", "upatches/",- assets.n_upatches);- if (assets.n_incoming < 0)- printf(" %-22s absent\n", "incoming/");- else if (assets.n_incoming == 0)- printf(" %-22s empty\n", "incoming/");- else- printf(" %-22s %d staged\n", "incoming/",- assets.n_incoming);- printf(" %-22s %s\n", "bpffs/",- assets.bpffs_mounted ? "mounted" : "not mounted");-- if (include_kernel_log) {- size_t bytes = (size_t)kernel_log_lines *- sizeof(struct kmsg_record);- struct kmsg_record *recs = xmalloc(bytes);- int nr = recs ? kmsg_tail(recs, kernel_log_lines)- : -ENOMEM;- int j;-- printf("\nKernel log (last %u lines, newest first):\n",- kernel_log_lines);- if (nr <= 0) {- printf(" (unavailable)\n");- } else {- for (j = nr; j-- > 0;)- printf(" [%s] %s\n", recs[j].ts,- recs[j].msg);- }- xfree(recs, bytes);+ if (show_full) {+ printf("\nAssets (%s):\n", VAR_LIB);+ printf(" %-22s %s\n", "keys/cert.der",+ assets.cert ? "present" : "absent");+ printf(" %-22s %s\n", "keys/signing_key.pem",+ assets.signing_key ? "present" : "absent");+ if (assets.eventlog)+ printf(" %-22s present (%ld bytes)\n",+ "eventlog", assets.eventlog_bytes);+ else+ printf(" %-22s absent\n", "eventlog");+ if (assets.n_upatches < 0)+ printf(" %-22s absent\n", "upatches/");+ else+ printf(" %-22s %d archived\n", "upatches/",+ assets.n_upatches);+ if (assets.n_incoming < 0)+ printf(" %-22s absent\n", "incoming/");+ else if (assets.n_incoming == 0)+ printf(" %-22s empty\n", "incoming/");+ else+ printf(" %-22s %d staged\n", "incoming/",+ assets.n_incoming);+ printf(" %-22s %s\n", "bpffs/",+ assets.bpffs_mounted ? "mounted" :+ "not mounted");+ } else {+ folded[nf++] = "assets";}- if (include_modules) {- struct kmod_set ks = {};- int mrc = kmodules_read(&ks);- struct timespec rt = {}, bt = {};- __s64 boot_sec = 0;- size_t last = 10;- size_t shown = min(ks.n, last);-- if (clock_gettime(CLOCK_REALTIME, &rt) == 0 &&- clock_gettime(CLOCK_BOOTTIME, &bt) == 0)- boot_sec = (__s64)rt.tv_sec - bt.tv_sec;-- if (mrc != 0) {- printf("\nLoaded modules:\n");- printf(" (unavailable: %s)\n", strerror(-mrc));- } else {- printf("\nLoaded modules (total %zu, "- "last %zu loads, newest first):\n",- ks.n, shown);- kmodules_print_recent(&ks, last,- boot_sec);- if (!show_full) {- printf(" (Use --show-full to show "- "all loaded modules in a "- "dependency tree)\n");- } else {- printf("\nDependency tree:\n");- kmodules_print_tree(&ks);- }- }- kmodules_free(&ks);+ if (include_system)+ print_system_human(&sysi);+ if (nf) {+ printf("\nFolded:");+ for (ci = 0; ci < nf; ci++)+ printf("%s %s", ci ? "," : "", folded[ci]);+ printf(" (--show-full)\n");}}-+ if (check && !ret && !strcmp(status_verdict(&cin), "tampered"))+ ret = 1;out:keyring_view_free(&bpf);keyring_view_free(&dmv);diff --git a/builtin-upatch.c b/builtin-upatch.cindex 420b6daf..d86e0557 100644--- a/builtin-upatch.c+++ b/builtin-upatch.c@@ -144,7 +144,7 @@ static int print_sha256_hex(const __u8 hash[32])static const struct help upatch_info_help = {.usage = "shirudo upatch info [--json] <file.upatch>",.summary = "Describe a .upatch file: header, signature, payload "- "digest,\nattach metadata and signed decoders. Offline -- "+ "digest,\nattach metadata and signed decoders. Offline: ""no kernel state\nread, runs on any host. For the program as ""actually loaded\n(authoritative, via kernel BTF line_info) ""use `shirudo upatch get`.",@@ -156,11 +156,9 @@ static const struct help upatch_info_help = {static const struct help upatch_list_help = {.usage = "shirudo upatch list [--json]",- .summary = "List upatches on this host. Shows the persisted set\n"- "(under /var/lib/shirudo/upatches/, survives reboot) "- "alongside the\nbpffs-pinned active set (loaded now). "- "Drift in either direction\n(persisted-but-not-loaded "- "or loaded-but-not-persisted) is flagged.",+ .summary = "List the upatches archived under /var/lib/shirudo/upatches,\n"+ "which init restores at boot, with whether each is loaded now,\n"+ "and any upatch loaded without an archive.",.footer ="Examples:\n"" shirudo upatch list\n"@@ -228,7 +226,7 @@ static const struct help upatch_map_help = {"target kernel. With no positional args, list every ""pinned\nmap across every loaded upatch. With ""<upatch>, list maps\nfor that upatch only. With "- "<upatch> <map>, dump the map's\ncontents -- BTF "+ "<upatch> <map>, dump the map's\ncontents, BTF ""type-aware where the build embedded `-g`. If the ""upatch\npins a serializer for the map, run it and ""print the serialized\npages. With --all, export detailed "@@ -268,7 +266,7 @@ static const struct help upatch_get_help = {" signed loader (authoritative, but sparse),\n"" - every pinned map: BTF key/value type definitions plus\n"" the live key/value contents.\n"- "Read-only; uses only LSM-allowed bpf() ops + xattr / stat.",+ "Read-only; uses only LSM-allowed bpf() ops, xattr and stat.",.sections = upatch_get_sections,.n_sections = ARRAY_SIZE(upatch_get_sections),.footer =@@ -401,7 +399,7 @@ static int cmd_upatch_info(int argc, const char **argv)printf("Type: %s\n", flag_str(&u));printf("Payload type: %s\n", upatch_type_str(&u));printf("Version: %u\n", u.hdr.version);- printf("Payload SHA256: ");+ printf("Payload sha256: ");print_sha256_hex(u.hdr.payload_sha256);printf("\n");printf("File size: %zu bytes\n", u.map_size);@@ -545,12 +543,12 @@ static int cmd_upatch_list(int argc, const char **argv)json_kv_int(&e, "schema", 1);json_arr_open(&e, "upatches");} else {- printf("upatches (%s):\n", UPATCHES_DIR);- if (np == 0)- printf(" (none persisted)\n");+ printf("Archived upatches (%s):\n", UPATCHES_DIR);+ if (np == 0 && na == 0)+ printf(" none\n");else- printf(" %-6s %-6s %-6s %-18s %s\n",- "loaded", "type", "kind", "payload-sha256", "name");+ printf(" %-24s %-6s %-6s %-4s %s\n",+ "NAME", "LOADED", "TYPE", "KIND", "PAYLOAD");}for (i = 0; i < np; i++) {@@ -566,8 +564,9 @@ static int cmd_upatch_list(int argc, const char **argv)continue;if (upatch_open(path, &u) != 0) {if (!json)- printf(" %-6s %-6s %-18s %s\n", "?", "?",- "(unreadable)", persisted[i]->d_name);+ printf(" %-24s %-6s %-6s %-4s %s\n",+ persisted[i]->d_name, "?", "?", "?",+ "unreadable");continue;}memcpy(name, u.hdr.name, sizeof(u.hdr.name));@@ -584,7 +583,7 @@ static int cmd_upatch_list(int argc, const char **argv)json_kv_string(&e, "type", type);json_kv_string(&e, "payload_type", payload_type);json_kv_bool(&e, "loaded", loaded);- json_kv_bool(&e, "persisted", 1);+ json_kv_bool(&e, "archived", 1);json_kv_string(&e, "payload_sha256", payload_hex);json_obj_close(&e);} else {@@ -592,8 +591,8 @@ static int cmd_upatch_list(int argc, const char **argv)memcpy(shown, payload_hex, 16);memcpy(shown + 16, "..", 3);- printf(" %-6s %-6s %-6s %-18s %s\n",- loaded ? "yes" : "no", type, payload_type, shown, name);+ printf(" %-24s %-6s %-6s %-4s %s\n", name,+ loaded ? "yes" : "no", type, payload_type, shown);}}@@ -618,13 +617,12 @@ static int cmd_upatch_list(int argc, const char **argv)json_kv_string(&e, "name", raw_name);json_kv_null(&e, "type");json_kv_bool(&e, "loaded", 1);- json_kv_bool(&e, "persisted", 0);+ json_kv_bool(&e, "archived", 0);json_kv_null(&e, "payload_sha256");json_obj_close(&e);} else {- printf(" %-6s %-6s %-18s %s (orphan: no persisted "- ".upatch, will not survive reboot)\n",- "yes", "?", "-", raw_name);+ printf(" %-24s %-6s %-6s %-4s %s\n", raw_name,+ "yes", "-", "-", "not archived, gone at reboot");}}@@ -1471,7 +1469,7 @@ static int attach_and_pin_progs(const struct loader_ctx *cx,goto out;}made[i] = true;- pr_info("attached + pinned prog %u (%s) -> %s",+ pr_info("upatch load: program %u (%s) pinned at %s",i, attach_kind_name(spec->kind), pin);}if (test_fd >= 0) {@@ -2020,10 +2018,9 @@ static int __upatch_apply(const char *path, bool verify_only,goto out;}- pr_info("loaded signed loader: prog_fd=%d keyring=%d "- "sig=%uB insns=%zu data=%uB",- prog_fd, (int)serial, u.hdr.signature_len, insn_cnt,- u.hdr.data_len);+ pr_info("%s: signed loader accepted, keyring %d, %zu instructions",+ verify_only ? "upatch unload" : "upatch load", (int)serial,+ insn_cnt);if (verify_only) {ret = 0;@@ -2157,7 +2154,7 @@ static int __upatch_apply(const char *path, bool verify_only,goto out;}- pr_info("loader ok, retval=%d (maps=%u progs=%u)", (__s32)retval,+ pr_info("upatch load: loader ran, %u maps and %u programs",u.hdr.nr_maps, u.hdr.nr_progs);/*@@ -2195,8 +2192,8 @@ static int __upatch_apply(const char *path, bool verify_only,set_pin_payload(upatch_name, u.hdr.payload_sha256);apply_policy_labels(&u);- pr_audit("upatch load: name=%s keyring=%d progs=%u", upatch_name,- (int)serial, u.hdr.nr_progs);+ pr_audit("upatch load: %s loaded, %u programs, keyring %d",+ upatch_name, u.hdr.nr_progs, (int)serial);if (rep)rep->loader_return = (__s32)retval;ret = 0;@@ -2248,7 +2245,7 @@ static int upatch_preflight(const char *expect_chain,fd = bpf_obj_get(LSM_LINK_PIN);if (fd < 0) {pr_err("upatch load: pre-flight refused (category: tampered, "- "message: lsm_detached) -- %s not pinned",+ "message: lsm_detached): %s not pinned",LSM_LINK_PIN);return -1;}@@ -2265,7 +2262,7 @@ static int upatch_preflight(const char *expect_chain,ret = chain_read(have);if (ret == -ENODEV) {pr_err("upatch load: pre-flight refused (category: tampered, "- "message: chain_drift) -- register unreadable, cannot "+ "message: chain_drift): register unreadable, cannot ""confirm --expect-chain");return -1;}@@ -2276,8 +2273,8 @@ static int upatch_preflight(const char *expect_chain,if (memneq_explicit(want, have, sizeof(want))) {hex_encode(have, sizeof(have), have_hex);pr_err("upatch load: pre-flight refused (category: tampered, "- "message: chain_drift) -- live chain %s != expected; "- "re-status and re-issue with the refreshed value",+ "message: chain_drift): live register %s is not the "+ "expected one; run status and pass the refreshed value",have_hex);return -1;}@@ -2295,7 +2292,8 @@ static int eventlog_room(struct op_report *rep, const char *op)config_load(&cfg);if (eventlog_would_exceed(cfg.eventlog_max_bytes)) {pr_err("upatch %s: eventlog %s would exceed "- "eventlog.max_bytes=%llu; refusing -- no load, no extend",+ "eventlog.max_bytes %llu; refused, nothing loaded or "+ "extended",op, eventlog_path(), cfg.eventlog_max_bytes);rep_fail(rep, "pre_flight", "eventlog_full", ENOSPC,"eventlog would exceed eventlog.max_bytes");@@ -2314,8 +2312,8 @@ static int version_gate(const char *expect_version_id, bool no_version_check,if (no_version_check || !expect_version_id)return 0;if (strcmp(expect_version_id, shirudo_version_id) != 0) {- pr_err("upatch %s: version mismatch -- operator expects %s, "- "target is %s; redeploy a matching shirudo or pass "+ pr_err("upatch %s: version mismatch, the operator expects %s "+ "and the target is %s; deploy a matching shirudo or pass ""--no-version-check", op, expect_version_id,shirudo_version_id);rep_fail(rep, "pre_flight", "version_mismatch", EPERM,@@ -2393,14 +2391,14 @@ static int upatch_chain_event_locked(const char *tag, const char *type,ret = chain_extend(event, chain);if (ret == -ENODEV) {- pr_err("upatch %s: TPM/register unavailable (category: "- "tpm_error) -- op done but NOT measured; shirudo "- "requires the register init bound this boot", op);+ pr_err("upatch %s: TPM register unavailable (category: "+ "tpm_error): done but not measured; shirudo needs the "+ "register init bound this boot", op);return ret;}if (ret == -EACCES) {pr_err("upatch %s: register is not the one init bound "- "(category: tampered) -- op done but NOT measured; "+ "(category: tampered): done but not measured; the ""operator must reconcile", op);return ret;}@@ -2414,15 +2412,15 @@ static int upatch_chain_event_locked(const char *tag, const char *type,*measured = true;ret = append_upatch_event(type, name, payload, event, reason);if (ret) {- pr_err("upatch %s: eventlog append failed after extend -- "- "chain/log desync; operator must reconcile", op);+ pr_err("upatch %s: eventlog append failed after the extend: "+ "register and log disagree; the operator must reconcile",+ op);return ret;}hex_encode(chain, 32, chain_hex);if (out_chain)memcpy(out_chain, chain_hex, sizeof(chain_hex));- pr_info("upatch %s: chain extended, value=%s", op, chain_hex);- pr_audit("upatch %s measured: name=%s chain=%s", op, name, chain_hex);+ pr_audit("upatch %s: %s measured, register %s", op, name, chain_hex);return 0;}@@ -2446,7 +2444,7 @@ static int upatch_chain_event(const char *tag, const char *type,lock = eventlog_lock();if (lock < 0) {pr_err("upatch %s: cannot take the register lock: %s "- "(category: tpm_error) -- nothing measured", op,+ "(category: tpm_error); nothing measured", op,strerror(-lock));return lock;}@@ -2928,7 +2926,7 @@ static int cmd_upatch_load(int argc, const char **argv)lock = eventlog_lock();if (lock < 0) {pr_err("upatch load: cannot take the register lock: %s "- "(category: tpm_error) -- nothing loaded",+ "(category: tpm_error); nothing loaded",strerror(-lock));rep_fail(&rep, "tpm_extend", "tpm_error", -lock,"cannot take the register lock");@@ -3112,7 +3110,7 @@ static int cmd_upatch_unload(int argc, const char **argv)lock = eventlog_lock();if (lock < 0) {pr_err("upatch unload: cannot take the register lock: %s "- "(category: tpm_error) -- nothing detached",+ "(category: tpm_error); nothing detached",strerror(-lock));rep_fail(&rep, "tpm_extend", "tpm_error", -lock,"cannot take the register lock");@@ -3138,14 +3136,15 @@ static int cmd_upatch_unload(int argc, const char **argv)xrc = get_pin_payload(name, live);if (xrc == 0) {if (memneq_explicit(live, payload, sizeof(payload))) {- pr_err("upatch unload: payload_mismatch -- the "+ pr_err("upatch unload: payload_mismatch, the ""upatch loaded under '%s' is not what the "- "directive expects; refusing", name);+ "directive expects; refused", name);rep_fail(&rep, "pin", "payload_mismatch", EPERM,"loaded payload does not match directive");goto done;}- pr_info("upatch unload: payload matches for '%s'", name);+ pr_info("upatch unload: %s carries the directive's payload",+ name);} else if (xrc != -ENOENT) {pr_err("upatch unload: cannot read the payload ""recorded for '%s': %s; refusing", name,@@ -3194,7 +3193,7 @@ static int cmd_upatch_unload(int argc, const char **argv)"pin removal failed after the event was measured");goto done;}- pr_info("upatch unload: detached + unpinned %s", name);+ pr_info("upatch unload: %s detached and unpinned", name);if (unlink(persisted) != 0 && errno != ENOENT)pr_warn("upatch unload: could not remove %s: %s",@@ -3875,25 +3874,28 @@ static void render_get_text(const struct upatch_get_ctx *c,age_from_ts(c->loaded_at, age, sizeof(age));- printf("upatch: %s\n", c->upatch);- printf("Location: %s\n",+ printf("%-22s %s\n", "Name:", c->upatch);+ printf("%-22s %s\n", "Location:",c->location[0] ? c->location : "?");- printf("Prog id: %u\n", c->prog_id);+ printf("%-22s %u\n", "Program ID:", c->prog_id);if (c->loaded_at[0])- printf("Loaded at: %s%s%s%s\n", c->loaded_at,+ printf("%-22s %s%s%s%s\n", "Loaded at:", c->loaded_at,age[0] ? " (" : "", age, age[0] ? " ago)" : "");if (c->payload[0])- printf("Payload: %s (signature-bound)\n", c->payload);+ printf("%-22s %s (signature-bound)\n", "Payload sha256:",+ c->payload);else- printf("Payload: (unavailable)\n");- printf("Maps (%zu): ", nm);+ printf("%-22s unavailable\n", "Payload sha256:");+ printf("%-22s ", "Maps:");+ if (nm == 0)+ printf("none");for (k = 0; k < nm; k++)printf("%s%s", maps[k].name, k + 1 < nm ? ", " : "");printf("\n");printf("\nSource (kernel BTF line_info):\n\n");if (c->n_ents == 0)- printf(" (no line info -- built without `clang -g`?)\n");+ printf(" no line info: built without clang -g\n");elsedump_line_info_text(c->ents, c->n_ents);@@ -4037,7 +4039,7 @@ static int cmd_upatch_get(int argc, const char **argv)static const struct help_item upatch_subcmds[] = {{ "load", "load a signed .upatch into the target kernel (target-only)" },{ "unload", "apply a signed UNLOAD directive (forward chain extension)" },- { "list", "list persisted + bpffs-pinned upatches on this host" },+ { "list", "list the archived and the loaded upatches on this host" },{ "info", "describe a .upatch file (any host; offline, no kernel state)" },{ "get", "dump source of a loaded upatch from the target kernel (BTF line_info)" },{ "map", "read pinned map contents (target-only; BTF type-aware)" },diff --git a/completion/shirudo.bash b/completion/shirudo.bashindex a2270a32..d511ed4a 100644--- a/completion/shirudo.bash+++ b/completion/shirudo.bash@@ -41,6 +41,8 @@ _shirudo()--cert --salt" -- "$cur") )elif [[ $cur == -* && $sub == verify ]]; thenCOMPREPLY=( $(compgen -W "--cert" -- "$cur") )+ elif [[ $cur == -* && $sub == status ]]; then+ COMPREPLY=( $(compgen -W "--json" -- "$cur") )elseCOMPREPLY=( $(compgen -f -- "$cur") )fi@@ -97,6 +99,10 @@ _shirudo()COMPREPLY=( $(compgen -f -X '!*.bee' -- "$cur") $(compgen -d -- "$cur") )elif [[ $sub == config && ${COMP_WORDS[3]} == register && cword -eq 4 ]]; thenCOMPREPLY=( $(compgen -W "add list remove" -- "$cur") )+ elif [[ $sub == config && ${COMP_WORDS[3]} == register && ${COMP_WORDS[4]} == list ]]; then+ COMPREPLY=( $(compgen -W "--json" -- "$cur") )+ elif [[ ($sub == list || ($sub == key && ${COMP_WORDS[3]} == list)) && $cur == -* ]]; then+ COMPREPLY=( $(compgen -W "--json" -- "$cur") )elif [[ $sub == config && ${COMP_WORDS[3]} == register && ${COMP_WORDS[4]} == add && $cur == -* ]]; thenCOMPREPLY=( $(compgen -W "--key-file=" -- "$cur") )elif [[ $sub == repo && cword -eq 3 ]]; then@@ -172,13 +178,12 @@ _shirudo()fi;;init)- COMPREPLY=( $(compgen -W "--check-only" -- "$cur") )+ COMPREPLY=( $(compgen -W "--check-only --json" -- "$cur") );;status)COMPREPLY=( $(compgen -W "--json \--include-system --include-eventlog \- --include-kernellog --include-modules \- --include-maps --show-full" -- "$cur") )+ --check --show-full" -- "$cur") );;attest)if [[ $cword -eq 2 && $cur != -* ]]; then@@ -187,11 +192,11 @@ _shirudo()COMPREPLY=( $(compgen -W "--evidence= --nonce= --ak-name= \--cert= --upatch= --expect= --tree-root= \--expect-chain= --expect-pcr= --expect-credential= \- --allow-runtime-events --strict-anchor \+ --allow-runtime-events --strict-anchor --json \--expect-config-root= --expect-config-pcr=" -- "$cur") )elif [[ $sub == predict ]]; thenCOMPREPLY=( $(compgen -W "--cert= --upatch= --expect= \- --tree-root= --event=" -- "$cur") )+ --tree-root= --event= --json" -- "$cur") )elif [[ $sub == challenge ]]; thenCOMPREPLY=( $(compgen -W "--evidence= --ek-ca= --out=" \-- "$cur") )@@ -204,7 +209,7 @@ _shirudo()if (( cword == 2 )); thenlocal subssubs=$("$bin" keys --list-cmds 2>/dev/null)- COMPREPLY=( $(compgen -W "$subs --keys-dir=" -- "$cur") )+ COMPREPLY=( $(compgen -W "$subs --keys-dir= --json" -- "$cur") )elif [[ $cur == -* ]]; thencase "$sub" inadd)diff --git a/shirudo.c b/shirudo.cindex 876e4908..4317c13b 100644--- a/shirudo.c+++ b/shirudo.c@@ -39,8 +39,8 @@ static int cmd_help(int argc, const char **argv);* completion, which pulls the list live through --list-cmds.*/static const struct cmd commands[] = {- { "genkey", cmd_genkey, GROUP_OPERATOR, "generate the signing key + cert" },- { "build", cmd_build, GROUP_OPERATOR, "compile + sign a .upatch" },+ { "genkey", cmd_genkey, GROUP_OPERATOR, "create the signing key and certificate" },+ { "build", cmd_build, GROUP_OPERATOR, "compile and sign a .upatch" },{ "image", cmd_image, GROUP_LOCAL,"build, verify and activate dm-verity config images" },@@ -51,7 +51,7 @@ static const struct cmd commands[] = {{ "bpm", cmd_bpm, GROUP_TARGET,"manage signed OCI packages on this target" },- { "status", cmd_status, GROUP_LOCAL, "local readiness + state report" },+ { "status", cmd_status, GROUP_LOCAL, "report the state of this host" },{ "attest", cmd_attest, GROUP_LOCAL,"TPM-signed evidence (target); verify / predict (operator)" },{ "keys", cmd_keys, GROUP_LOCAL, "inspect cert / keyring contents" },diff --git a/testing/functional/image/t5101-verity-boot-signers.py b/testing/functional/image/t5101-verity-boot-signers.pyindex 351d342e..6f8cd631 100644--- a/testing/functional/image/t5101-verity-boot-signers.py+++ b/testing/functional/image/t5101-verity-boot-signers.py@@ -167,7 +167,7 @@ def snapshot(label):for p in sorted(config.JOURNAL.iterdir()) if p.is_file()},"mappings": config.mapping_inventory(),}- status = json.loads(config.run(label + "-status", "image", "status"))+ status = json.loads(config.run(label + "-status", "image", "status", "--json"))require(status["consistent"] and not status["pending"] andstatus["root_hash"] == ROOT and status["pcr"] == 14, status)require("map_export.tenant_id = config-boot-keys\n" in effects["settings"],diff --git a/testing/functional/image/t5102-verity-config.py b/testing/functional/image/t5102-verity-config.pyindex 393d3042..43be47dd 100644--- a/testing/functional/image/t5102-verity-config.py+++ b/testing/functional/image/t5102-verity-config.py@@ -108,7 +108,7 @@ def snapshot(label):for p in sorted(JOURNAL.iterdir()) if p.is_file()},"mappings": mapping_inventory(),}- status = json.loads(run(label + "-status", "image", "status"))+ status = json.loads(run(label + "-status", "image", "status", "--json"))require(status["consistent"] and not status["pending"], status)require(status["pcr"] == 14, status)selected = next((name for name in NAMESdiff --git a/testing/functional/image/t5105-verity-interruption.py b/testing/functional/image/t5105-verity-interruption.pyindex d24093e1..dc045d22 100755--- a/testing/functional/image/t5105-verity-interruption.py+++ b/testing/functional/image/t5105-verity-interruption.py@@ -50,7 +50,7 @@ def main():(RESULTS / "crash.state").write_bytes((config.JOURNAL / "state").read_bytes())(RESULTS / "crash.events").write_bytes((config.JOURNAL / "events").read_bytes())config.require(pcr("crash") == expected, "config PCR did not extend exactly once")- status = json.loads(config.run("pending-status", "image", "status", success=False))+ status = json.loads(config.run("pending-status", "image", "status", "--json", success=False))config.require(status["pending"] and not status["consistent"],"interrupted activation looked healthy")config.run("blocked-update", "image", "update", config.IMAGES / target, success=False)diff --git a/testing/functional/signing/t2001-genkey.sh b/testing/functional/signing/t2001-genkey.shindex 4e2774a1..f6b28afa 100755--- a/testing/functional/signing/t2001-genkey.sh+++ b/testing/functional/signing/t2001-genkey.sh@@ -70,7 +70,7 @@ if [ "$have_mldsa" = 1 ]; thentest_expect_success 'keys reports ML-DSA-87 and a matching key/cert pair' '"$SHIRUDO" keys --keys-dir "$tmp/keys" >"$tmp/keys.out" 2>&1 &&- grep -q "Public-key: *ML-DSA-87" "$tmp/keys.out" &&+ grep -q "Public key: *ML-DSA-87" "$tmp/keys.out" &&grep -q "Algorithm: *ML-DSA-87" "$tmp/keys.out" &&grep -q "Issued: *20[0-9][0-9]-" "$tmp/keys.out" &&! grep -Eq "Valid until|Expires in" "$tmp/keys.out" &&diff --git a/testing/functional/tamperproof/t6004-conditions.sh b/testing/functional/tamperproof/t6004-conditions.shindex 2380c257..3f87a67d 100755--- a/testing/functional/tamperproof/t6004-conditions.sh+++ b/testing/functional/tamperproof/t6004-conditions.sh@@ -19,40 +19,40 @@ 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 bpf serial=100, dm-verity serial=200, pins match"+ 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' 'out=$(./$H 0 none -1 0 none) &&echo "$out" | grep -qx "status=lsm-off" &&- echo "$out" | grep -qx "KeyringSealed WARN shirudo keyring absent (not init'"'"'d?)"+ echo "$out" | grep -qx "KeyringSealed WARN .bpf keyring absent before init"'test_expect_success 'a swapped keyring is tampered' 'out=$(./$H 1 bpf 101 100 match) &&echo "$out" | grep -qx "status=tampered" &&echo "$out" | grep -qx "reason=keyring serial swap detected" &&- echo "$out" | grep -qx "KeyringSealed ALERT pin serial=100 != live serial=101 (swapped?)"+ echo "$out" | grep -qx "KeyringSealed ALERT pinned serial 100, live serial 101: swapped"'test_expect_success 'a frozen bpf keyring that is gone is tampered' 'out=$(./$H 1 bpf -1 100 match) &&echo "$out" | grep -qx "status=tampered" &&- echo "$out" | grep -qx "KeyringSealed ALERT pin serial=100, the BPF keyring is gone (removed?)"+ echo "$out" | grep -qx "KeyringSealed ALERT pinned serial 100, the .bpf keyring is gone"'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?)"+ echo "$out" | grep -qx "KeyringSealed ALERT dm-verity pinned 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?)"+ echo "$out" | grep -qx "KeyringSealed ALERT dm-verity pinned serial 200, the dm-verity keyring is gone"'test_expect_success 'a link init did not freeze is tampered, in either keyring' '@@ -74,7 +74,7 @@ test_expect_success 'a config key that is gone is tampered' '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?)"+ grep -qx "KeyringSealed ALERT pinned serial 100, live serial 101: swapped"'test_expect_success 'with the LSM off a gone keyring is still tampered' '@@ -83,7 +83,7 @@ test_expect_success 'with the LSM off a gone keyring is still tampered' 'test_expect_success 'a register mismatch is the reason given first' './$H 1 bpf -1 200 mismatch |- grep -qx "reason=live register != eventlog replay"+ grep -qx "reason=live register differs from the eventlog replay"'test_expect_success 'no TPM answering is told apart from an unbound register' '@@ -130,7 +130,7 @@ test_expect_success 'pins that cannot be checked are a warning, not a verdict' 'test_expect_success 'a register mismatch is the reason given before the pins' 'SHIRUDO_TEST_PINS=unmeasured:x ./$H 1 bpf 100 100 mismatch |- grep -qx "reason=live register != eventlog replay"+ grep -qx "reason=live register differs from the eventlog replay"'test_expect_success 'an active config is OK' '@@ -151,7 +151,7 @@ test_expect_success 'a config its records cannot vouch for is tampered' 'out=$(SHIRUDO_TEST_CONFIG_STATE=$state ./$H 1 bpf 100 100 match) &&echo "$out" | grep -qx "status=tampered" &&echo "$out" | grep -qx "reason=the selected config cannot be verified against its records" &&- echo "$out" | grep -q "^ConfigActive ALERT .*(tamper?)$" || return 1+ echo "$out" | grep -q "^ConfigActive ALERT " || return 1done'diff --git a/testing/functional/tamperproof/t6108-tamper-counters.sh b/testing/functional/tamperproof/t6108-tamper-counters.shindex 7f3db743..48176af3 100755--- a/testing/functional/tamperproof/t6108-tamper-counters.sh+++ b/testing/functional/tamperproof/t6108-tamper-counters.sh@@ -118,7 +118,8 @@ test_expect_success 'the human report lists the counters that moved' 'grep -q "^ PinRename *[1-9][0-9]* rename of a pin" "$W/status" &&grep -q "^ BpffsUmount *[1-9][0-9]* unmount of the private bpffs" \"$W/status" &&- ! grep -q "^ none$" "$W/status"+ ! sed -n "/^Tamper attempts (this boot):/,/^$/p" "$W/status" |+ grep -q "^ none$"'test_donediff --git a/testing/functional/tamperproof/t6140-status-keyrings.sh b/testing/functional/tamperproof/t6140-status-keyrings.shindex 05d089ac..d0e575fd 100644--- a/testing/functional/tamperproof/t6140-status-keyrings.sh+++ b/testing/functional/tamperproof/t6140-status-keyrings.sh@@ -39,7 +39,7 @@ for key, serial in rings: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" % (+assert sealed["detail"] == "bpf serial %d, dm-verity serial %d, pins match" % (rings[0][1], rings[1][1]), sealedassert d["status"] != "tampered", d["status"]PY@@ -81,14 +81,14 @@ PY'test_expect_success 'the report shows each certificate with its frozen key' '- "$SHIRUDO_BIN" status >"$W/status.txt" &&+ "$SHIRUDO_BIN" status --show-full >"$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"+ ! grep -q "not frozen\|Other links:" "$W/status.txt"'test_donediff --git a/testing/functional/tpm/t4003-register.sh b/testing/functional/tpm/t4003-register.shindex 123e2384..3c51ec1a 100644--- a/testing/functional/tpm/t4003-register.sh+++ b/testing/functional/tpm/t4003-register.sh@@ -139,11 +139,11 @@ test_expect_success 'evidence verifies against the pinned key, the binding and t--expect-bind-pcr=9=$Z --expect-bind-pcr=11=$PHASE \>"$WORK/report" &&grep -qx "verdict: ok" "$WORK/report" &&- grep -q "^ok: register: public area is bound to PCRs 9 and 11" "$WORK/report" &&- grep -q "^ok: binding: PCR 11 held the expected value" "$WORK/report" &&- grep -q "^ok: binding: made while the initrd ran" "$WORK/report" &&- grep -q "^ok: endorsement key: the pinned key" "$WORK/report" &&- ! grep -q "^FAIL" "$WORK/report"+ grep -q "^ OK register: public area is bound to PCRs 9 and 11" "$WORK/report" &&+ grep -q "^ OK binding: PCR 11 held the expected value" "$WORK/report" &&+ grep -q "^ OK binding: made while the initrd ran" "$WORK/report" &&+ grep -q "^ OK endorsement key: the pinned key" "$WORK/report" &&+ ! grep -q "^ FAIL" "$WORK/report"'test_expect_success 'verify computes the state from cert and set, flags runtime events' '@@ -152,8 +152,8 @@ test_expect_success 'verify computes the state from cert and set, flags runtime--ak-name="$(cat "$WORK/ak")" --cert="$WORK/keys/cert.der" \>"$WORK/report3"; rc=$? &&[ "$rc" = 1 ] &&- grep -q "^ok: state: init event covers" "$WORK/report3" &&- grep -q "^FAIL: state: 1 event after boot" "$WORK/report3" &&+ grep -q "^ OK state: init event covers" "$WORK/report3" &&+ grep -q "^ FAIL state: 1 event after boot" "$WORK/report3" &&$S attest verify --evidence="$WORK/evidence.json" --nonce=$nonce \--ak-name="$(cat "$WORK/ak")" --cert="$WORK/keys/cert.der" \--allow-runtime-events | grep -qx "verdict: ok"@@ -176,11 +176,11 @@ test_expect_success 'a wrong nonce, key name, binding value or tampered value fa! $S attest verify --evidence="$WORK/evidence.json" --nonce=$nonce \--ak-name="$ak" --expect-chain="$value" --expect-bind-pcr=11=$Z \>"$WORK/report4b" &&- grep -q "^FAIL: binding: PCR 11 held the expected value" "$WORK/report4b" &&+ grep -q "^ FAIL binding: PCR 11 held the expected value" "$WORK/report4b" &&sed "s/\"value\":\"$value\"/\"value\":\"$Z\"/" "$WORK/evidence.json" >"$WORK/tampered.json" &&! $S attest verify --evidence="$WORK/tampered.json" --nonce=$nonce \--ak-name="$ak" --expect-chain="$value" >"$WORK/report4" &&- grep -q "^FAIL: register: certified contents" "$WORK/report4"+ grep -q "^ FAIL register: certified contents" "$WORK/report4"'# The pre-init fixture uses the kernel writer to certify a substitute@@ -203,9 +203,9 @@ PY--ak-name="$(cat "$WORK/ak")" --ek-name="$(cat "$WORK/ek")" \--cert="$WORK/keys/cert.der" --strict-anchor --require-initrd \>"$WORK/report-forged" &&- grep -q "^FAIL: register: the document names index 0x01818E00 and PCRs 9 and 11" \+ grep -q "^ FAIL register: the document names index 0x01818E00 and PCRs 9 and 11" \"$WORK/report-forged" &&- grep -q "^ok: register: certified contents match the listed value" \+ grep -q "^ OK register: certified contents match the listed value" \"$WORK/report-forged"'@@ -216,9 +216,9 @@ test_expect_success 'an event relabelled after the fact fails although the repla! $S attest verify --evidence="$WORK/relabelled.json" --nonce=$nonce \--ak-name="$(cat "$WORK/ak")" --cert="$WORK/keys/cert.der" \--allow-runtime-events >"$WORK/report-relabelled" &&- grep -q "^ok: eventlog: 2 records replay to the certified value" \+ grep -q "^ OK eventlog: 2 records replay to the certified value" \"$WORK/report-relabelled" &&- grep -q "^FAIL: eventlog: event 1 (upatch_unload foo) digest does not derive from its fields" \+ grep -q "^ FAIL eventlog: event 1 (upatch_unload foo) digest does not derive from its fields" \"$WORK/report-relabelled" &&$S attest verify --evidence="$WORK/evidence.json" --nonce=$nonce \--ak-name="$(cat "$WORK/ak")" --cert="$WORK/keys/cert.der" \@@ -239,23 +239,23 @@ test_expect_success 'a tree operation records its digest as the target writes it--ak-name="$(cat "$WORK/ak")" --cert="$WORK/keys/cert.der" \--allow-runtime-events >"$WORK/report-tree" &&grep -qx "verdict: ok" "$WORK/report-tree" &&- grep -q "^ok: eventlog: 3 records replay to the certified value" "$WORK/report-tree" &&+ grep -q "^ OK eventlog: 3 records replay to the certified value" "$WORK/report-tree" &&! grep -q "does not derive" "$WORK/report-tree"'test_expect_success 'a challenge needs a vouched-for endorsement key' '! $S attest challenge --evidence="$WORK/evidence.json" \--out="$WORK/challenge-none.json" >"$WORK/challenge-none.out" &&- grep -q "^FAIL: no endorsement certificate: pin the key" "$WORK/challenge-none.out" &&+ grep -q "^ FAIL no endorsement certificate: pin the key" "$WORK/challenge-none.out" &&[ ! -e "$WORK/challenge-none.json" ] &&! $S attest challenge --evidence="$WORK/evidence.json" \--ek-name="000b$(py "print(\"00\"*32)")" \--out="$WORK/challenge-wrong.json" >"$WORK/challenge-wrong.out" &&- grep -q "^FAIL: endorsement key: the pinned key" "$WORK/challenge-wrong.out" &&+ grep -q "^ FAIL endorsement key: the pinned key" "$WORK/challenge-wrong.out" &&! $S attest challenge --evidence="$WORK/evidence.json" \--ak-name="000b$(py "print(\"00\"*32)")" --trust-presented-ek \--out="$WORK/challenge-wrong.json" >"$WORK/challenge-wrong2.out" &&- grep -q "^FAIL: attestation key: the pinned key" "$WORK/challenge-wrong2.out"+ grep -q "^ FAIL attestation key: the pinned key" "$WORK/challenge-wrong2.out"'test_expect_success 'a challenge made from the evidence activates on the target' '@@ -263,10 +263,10 @@ test_expect_success 'a challenge made from the evidence activates on the target'$S attest challenge --evidence="$WORK/evidence.json" \--ak-name="$(cat "$WORK/ak")" --ek-name="$(cat "$WORK/ek")" \--out="$WORK/challenge.json" >"$WORK/challenge.out" &&- grep -q "^ok: attestation key: the pinned key" "$WORK/challenge.out" &&- grep -q "^ok: endorsement key: the pinned key" "$WORK/challenge.out" &&- grep -q "^ok: endorsement key: TCG default template" "$WORK/challenge.out" &&- grep -q "^note: no endorsement certificate" "$WORK/challenge.out" &&+ grep -q "^ OK attestation key: the pinned key" "$WORK/challenge.out" &&+ grep -q "^ OK endorsement key: the pinned key" "$WORK/challenge.out" &&+ grep -q "^ OK endorsement key: TCG default template" "$WORK/challenge.out" &&+ grep -q "^ note no endorsement certificate" "$WORK/challenge.out" &&sed -n "s/^credential: //p" "$WORK/challenge.out" >"$WORK/credential" &&[ "$(wc -c <"$WORK/credential")" = 65 ] &&./helper/test-tpm-wire public "$(py "import json; print(json.load(open(\"$WORK/evidence.json\"))[\"ek\"][\"public\"])")" |@@ -278,8 +278,8 @@ test_expect_success 'a challenge made from the evidence activates on the target'--allow-runtime-events \--expect-credential="$(cat "$WORK/credential")" >"$WORK/report-cred" &&grep -qx "verdict: ok" "$WORK/report-cred" &&- grep -q "^ok: attestation key: activated the credential" "$WORK/report-cred" &&- grep -q "^ok: endorsement key: TCG default template" "$WORK/report-cred"+ grep -q "^ OK attestation key: activated the credential" "$WORK/report-cred" &&+ grep -q "^ OK endorsement key: TCG default template" "$WORK/report-cred"'test_expect_success 'a credential expectation needs the pinned attestation key' '@@ -297,7 +297,7 @@ test_expect_success 'a wrong credential, a tampered blob and a foreign challenge! $S attest verify --evidence="$WORK/evidence-cred.json" --nonce=$nonce \--ak-name="$(cat "$WORK/ak")" --allow-runtime-events \--expect-credential="$(py "print(\"00\"*32)")" >"$WORK/report-cred2" &&- grep -q "^FAIL: attestation key: activated the credential" "$WORK/report-cred2" &&+ grep -q "^ FAIL attestation key: activated the credential" "$WORK/report-cred2" &&sed "s/\"credential_blob\":\"\([0-9a-f]\{4\}\)[0-9a-f]\{4\}/\"credential_blob\":\"\10000/" \"$WORK/challenge.json" >"$WORK/challenge-tampered.json" &&! ./$R evidence $nonce "$WORK/challenge-tampered.json" >/dev/null 2>&1 &&@@ -326,8 +326,8 @@ test_expect_success 'challenge refuses a key that is not an endorsement key' 'py "import json; d=json.load(open(\"$WORK/evidence.json\")); d[\"ek\"]={\"type\":\"ecc\",\"public\":d[\"ak\"][\"public\"],\"name\":d[\"ak\"][\"name\"]}; open(\"$WORK/fake-ek.json\",\"w\").write(json.dumps(d))" &&! $S attest challenge --evidence="$WORK/fake-ek.json" --trust-presented-ek \--out="$WORK/challenge-fake.json" >"$WORK/fake.out" &&- grep -q "^FAIL: endorsement key: TCG default template" "$WORK/fake.out" &&- grep -qx "verdict: FAIL" "$WORK/fake.out" &&+ grep -q "^ FAIL endorsement key: TCG default template" "$WORK/fake.out" &&+ grep -qx "verdict: fail" "$WORK/fake.out" &&[ ! -e "$WORK/challenge-fake.json" ]'@@ -376,15 +376,15 @@ test_expect_success 'a late binding is told apart by the phase value and the ini--ak-name="$(cat "$WORK/ak")" --cert="$WORK/keys/cert.der" \--strict-anchor >"$WORK/report6" &&grep -qx "verdict: ok" "$WORK/report6" &&- grep -q "^note: binding: made in the root file system" "$WORK/report6" &&- grep -q "^ok: eventlog: one init record for this TPM reset (2 this boot)" "$WORK/report6" &&- grep -q "^ok: register: init record is of the TPM" "$WORK/report6" &&- grep -q "^ok: quote and certification are of one TPM reset" "$WORK/report6" &&+ grep -q "^ note binding: made in the root file system" "$WORK/report6" &&+ grep -q "^ OK eventlog: one init record for this TPM reset (2 this boot)" "$WORK/report6" &&+ grep -q "^ OK register: init record is of the TPM" "$WORK/report6" &&+ grep -q "^ OK quote and certification are of one TPM reset" "$WORK/report6" &&! $S attest verify --evidence="$WORK/evidence2.json" --nonce=$nonce \--ak-name="$(cat "$WORK/ak")" --cert="$WORK/keys/cert.der" \--require-initrd --expect-bind-pcr=11=$PHASE >"$WORK/report6b" &&- grep -q "^FAIL: binding: PCR 11 held the expected value" "$WORK/report6b" &&- grep -q "^FAIL: binding: made while the initrd ran" "$WORK/report6b"+ grep -q "^ FAIL binding: PCR 11 held the expected value" "$WORK/report6b" &&+ grep -q "^ FAIL binding: made while the initrd ran" "$WORK/report6b"'test_expect_success 'a second init record for one TPM reset fails status and verify' '@@ -405,7 +405,7 @@ PY--ak-name="$(cat "$WORK/ak")" --cert="$WORK/keys/cert.der" \>"$WORK/report7"; rc=$? &&[ "$rc" = 1 ] &&- grep -q "^FAIL: eventlog: one init record for this TPM reset" "$WORK/report7" &&+ grep -q "^ FAIL eventlog: one init record for this TPM reset" "$WORK/report7" &&cp "$WORK/eventlog.orig" "$WORK/eventlog" &&./$R status | grep -qx "rebound=0"'@@ -418,7 +418,7 @@ test_expect_success 'an init record of another TPM reset fails verification' '--ak-name="$(cat "$WORK/ak")" --cert="$WORK/keys/cert.der" \>"$WORK/report8"; rc=$? &&[ "$rc" = 1 ] &&- grep -q "^FAIL: register: init record is of the TPM" "$WORK/report8"+ grep -q "^ FAIL register: init record is of the TPM" "$WORK/report8"'test_donediff --git a/testing/functional/tpm/t4004-config-attest.sh b/testing/functional/tpm/t4004-config-attest.shindex 1311af5c..c87ee2dd 100755--- a/testing/functional/tpm/t4004-config-attest.sh+++ b/testing/functional/tpm/t4004-config-attest.sh@@ -84,7 +84,7 @@ PYtest_expect_success 'genuine TPM evidence verifies against the operator root and PCR choice' 'verify "$WORK/b.json" >"$WORK/verified" &&- grep -q "^ok: config: config root history matches the quoted PCR" "$WORK/verified" &&+ grep -q "^ OK config: config root history matches the quoted PCR" "$WORK/verified" &&grep -qx "verdict: ok" "$WORK/verified"'@@ -114,7 +114,7 @@ test_expect_success 'without operator approval the report names its limit explic"$S" attest verify --evidence="$WORK/b.json" --nonce="$NONCE" \--ak-name="$(field "$WORK/b.json" ak.name)" --expect-chain="$CHAIN" \>"$WORK/unapproved" &&- grep -q "^note: config root has no operator approval" "$WORK/unapproved" &&+ grep -q "^ note config root has no operator approval" "$WORK/unapproved" &&grep -q "direct TPM writer protection is deferred" "$WORK/unapproved"'@@ -162,9 +162,9 @@ donetest_expect_success 'an inconsistent config history names the check it fails' '! verify "$WORK/bad-reordered.json" >"$WORK/reordered-report" 2>/dev/null &&- grep -qx "FAIL: config: the events are one boot event followed by updates in sequence" \+ grep -qx " FAIL config: the events are one boot event followed by updates in sequence" \"$WORK/reordered-report" &&- grep -qx "verdict: FAIL" "$WORK/reordered-report"+ grep -qx "verdict: fail" "$WORK/reordered-report"'test_expect_success 'pending effects prevent evidence collection despite a measured selection' 'diff --git a/testing/functional/tpm/t4102-tpm-chain.sh b/testing/functional/tpm/t4102-tpm-chain.shindex 2d2c4f8e..f130ed30 100644--- a/testing/functional/tpm/t4102-tpm-chain.sh+++ b/testing/functional/tpm/t4102-tpm-chain.sh@@ -97,7 +97,7 @@ test_expect_success 'the installed binary emits evidence that verifies against t--ak-name="$AK" --ek-name="$EK" --expect-chain="$CHAIN" \--strict-anchor >"$W/report" &&grep -qx "verdict: ok" "$W/report" &&- grep -q "^ok: register: public area is bound to PCRs 9 and 11" "$W/report"+ grep -q "^ OK register: public area is bound to PCRs 9 and 11" "$W/report"'AK=$(evidence_field ak.name) || exit 1@@ -139,8 +139,8 @@ PY! "$SHIRUDO_BIN" attest verify --evidence="$W/forged.json" --nonce="$NONCE" \--ak-name="$AK" --expect-chain="$(cat "$W/forged-chain")" \>"$W/forged-report" &&- grep -q "^FAIL: eventlog:" "$W/forged-report" &&- grep -q "^FAIL: state:" "$W/forged-report"+ grep -q "^ FAIL eventlog:" "$W/forged-report" &&+ grep -q "^ FAIL state:" "$W/forged-report"'test_expect_success 'the certified name binds the writer public key and its exact encoding' '@@ -175,7 +175,7 @@ PY;;*)[ "$rc" = 1 ] &&- grep -q "^FAIL: register: public area" "$W/writer-$kind.report" || failed=1+ grep -q "^ FAIL register: public area" "$W/writer-$kind.report" || failed=1;;esacdone &&@@ -185,16 +185,16 @@ PYtest_expect_success 'a challenge requires the correct pinned endorsement and attestation keys' '! "$SHIRUDO_BIN" attest challenge --evidence="$W/evidence.json" \--out="$W/challenge-none.json" >"$W/challenge-none.out" &&- grep -q "^FAIL: no endorsement certificate: pin the key" "$W/challenge-none.out" &&+ grep -q "^ FAIL no endorsement certificate: pin the key" "$W/challenge-none.out" &&[ ! -e "$W/challenge-none.json" ] &&! "$SHIRUDO_BIN" attest challenge --evidence="$W/evidence.json" \--ek-name=000b$(printf "%064d" 0) --out="$W/challenge-wrong.json" \>"$W/challenge-wrong.out" &&- grep -q "^FAIL: endorsement key: the pinned key" "$W/challenge-wrong.out" &&+ grep -q "^ FAIL endorsement key: the pinned key" "$W/challenge-wrong.out" &&! "$SHIRUDO_BIN" attest challenge --evidence="$W/evidence.json" \--ak-name=000b$(printf "%064d" 0) --trust-presented-ek \--out="$W/challenge-wrong.json" >"$W/challenge-wrong-ak.out" &&- grep -q "^FAIL: attestation key: the pinned key" "$W/challenge-wrong-ak.out"+ grep -q "^ FAIL attestation key: the pinned key" "$W/challenge-wrong-ak.out"'test_expect_success 'the production target activates an ECC endorsement-key challenge' '@@ -214,7 +214,7 @@ test_expect_success 'wrong credentials, corrupted blobs and foreign challenges a! "$SHIRUDO_BIN" attest verify --evidence="$W/evidence-credential.json" --nonce=1112 \--ak-name="$AK" --allow-runtime-events --expect-credential=$(printf "%064d" 0) \>"$W/wrong-credential.report" &&- grep -q "^FAIL: attestation key: activated the credential" "$W/wrong-credential.report" &&+ grep -q "^ FAIL attestation key: activated the credential" "$W/wrong-credential.report" &&python3 - "$W/challenge.json" "$W" <<"PY"import copy, json, sysd = json.load(open(sys.argv[1]))@@ -266,7 +266,7 @@ json.dump(d, open(sys.argv[2], "w"))PY! "$SHIRUDO_BIN" attest challenge --evidence="$W/fake-ek.json" --trust-presented-ek \--out="$W/challenge-fake.json" >"$W/fake-ek.out" &&- grep -q "^FAIL: endorsement key: TCG default template" "$W/fake-ek.out" &&+ grep -q "^ FAIL endorsement key: TCG default template" "$W/fake-ek.out" &&[ ! -e "$W/challenge-fake.json" ]'diff --git a/testing/functional/upatch/t3106-upatch-get.sh b/testing/functional/upatch/t3106-upatch-get.shindex 45dc46c3..c4430077 100644--- a/testing/functional/upatch/t3106-upatch-get.sh+++ b/testing/functional/upatch/t3106-upatch-get.sh@@ -55,7 +55,7 @@ assert set(u) == {"name", "location", "prog_id", "loaded_at", "age",assert u["name"] == "shirudo-test-marker"assert u["location"] == "fentry/do_nanosleep"assert u["prog_id"] > 0-assert re.search(r"^Prog id: +%d$" % u["prog_id"], text, re.M)+assert re.search(r"^Program ID: +%d$" % u["prog_id"], text, re.M)assert re.fullmatch(r"\d{4}-\d\d-\d\dT\d\d:\d\d:\d\dZ", u["loaded_at"])assert u["age"]assert u["payload_sha256"] == payloaddiff --git a/testing/fuzz/fuzz-kernel.c b/testing/fuzz/fuzz-kernel.cindex d8f859fc..545f6028 100644--- a/testing/fuzz/fuzz-kernel.c+++ b/testing/fuzz/fuzz-kernel.c@@ -2,40 +2,14 @@/** Copyright (c) 2026 Authors of shirudo*- * What the kernel hands status: a /dev/kmsg record, /proc/modules and the- * ELF notes of /sys/kernel/notes.+ * What the kernel hands status: the ELF notes of /sys/kernel/notes.*/-#include "fuzz.h"#include "kernel_build_id.h"-#include "kmodules.h"-#include "kmsg.c"int LLVMFuzzerTestOneInput(const __u8 *data, size_t size){- const struct timespec rt = { 1792540800, 999999999 };char build_id[KERNEL_BUILD_ID_STRING_MAX];- const struct timespec mt = { 86400, 1 };- char ts[KMSG_TS_LEN];- struct kmod_set set;- char msg[1024], *text;- const char *m;- __u64 us;- size_t n;-- if (!parse_record((const char *)data, size, &us, &m, &n)) {- monotonic_to_iso(us, &rt, &mt, ts, sizeof(ts));- copy_msg(msg, sizeof(msg), m, n);- }-- text = xmalloc(size + 1);- if (!text)- return 0;- memcpy(text, data, size);- text[size] = '\0';- if (!kmodules_parse(text, &set))- kmodules_free(&set);- xfree(text, size + 1);kernel_build_id_from_notes(data, size, build_id);return 0;diff --git a/util/attest.c b/util/attest.cindex a242b9d4..518f1ddb 100644--- a/util/attest.c+++ b/util/attest.c@@ -625,7 +625,7 @@ static void say(struct reporter *r, bool ok, const char *fmt, ...)r->failed++;if (r->len + 8 >= r->cap)return;- n = strscpy(r->buf + r->len, ok ? "ok: " : "FAIL: ", r->cap - r->len);+ n = strscpy(r->buf + r->len, ok ? " OK " : " FAIL ", r->cap - r->len);if (n > 0)r->len += (size_t)n;va_start(ap, fmt);@@ -649,7 +649,7 @@ static void note(struct reporter *r, const char *fmt, ...)if (r->len + 8 >= r->cap)return;- n = strscpy(r->buf + r->len, "note: ", r->cap - r->len);+ n = strscpy(r->buf + r->len, " note ", r->cap - r->len);if (n > 0)r->len += (size_t)n;va_start(ap, fmt);diff --git a/util/conditions.c b/util/conditions.cindex 46cf5bc2..bcab2c56 100644--- a/util/conditions.c+++ b/util/conditions.c@@ -24,10 +24,10 @@ static bool config_untrusted(const struct conditions_input *in)static const char *config_untrusted_detail(int state){if (state == -ESTALE)- return "the config activation record does not belong to this TPM boot (tamper?)";+ return "the config activation record does not belong to this TPM boot";if (state == -EKEYREJECTED)- return "the mounted config does not match the selected root (tamper?)";- return "the config PCR, activation records and mounted config disagree (tamper?)";+ return "the mounted config does not match the selected root";+ return "the config PCR, activation records and mounted config disagree";}static bool keyring_tampered(const struct conditions_input *in)@@ -58,13 +58,13 @@ static void keyring_condition(const struct conditions_input *in,c->type = "KeyringSealed";if (!in->keyring_present && in->ksp_seen)set_detail(c, "ALERT",- "pin serial=%lld, the BPF keyring is gone (removed?)",+ "pinned serial %lld, the .bpf keyring is gone",(__s64)in->keyring_serial_pinned);else if (!in->keyring_present)- set_detail(c, "WARN", "shirudo keyring absent (not init'd?)");+ set_detail(c, "WARN", ".bpf keyring absent before init");else if (in->ksm_seen && !in->keyring_serial_matches)set_detail(c, "ALERT",- "pin serial=%lld != live serial=%lld (swapped?)",+ "pinned serial %lld, live serial %lld: swapped",(__s64)in->keyring_serial_pinned,(__s64)in->keyring_serial);else if (in->bpf_unfrozen)@@ -73,11 +73,11 @@ static void keyring_condition(const struct conditions_input *in,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?)",+ "dm-verity pinned serial %lld, the dm-verity keyring is gone",(__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?)",+ "dm-verity pinned serial %lld, live serial %lld: swapped",(__s64)in->dmv_serial_pinned,(__s64)in->dmv_serial);else if (in->dmv_unfrozen)@@ -89,10 +89,10 @@ static void keyring_condition(const struct conditions_input *in,"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",+ "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",+ set_detail(c, "OK", "bpf serial %lld, %s",(__s64)in->keyring_serial,in->ksp_seen ? "pin matches" : "no pin recorded");}@@ -107,7 +107,7 @@ size_t conditions(const struct conditions_input *in,c[n].status = in->lsm_attached ? "OK" : "ALERT";strscpy(c[n].detail, in->lsm_attached ?"lsm/bpf link present and pinned" :- "lsm/bpf absent -- enforcement OFF",+ "lsm/bpf link absent, enforcement off",sizeof(c[n].detail));n++;}@@ -123,12 +123,12 @@ size_t conditions(const struct conditions_input *in,sizeof(c[n].detail));} else if (in->cm_seen && in->chain_matches) {c[n].status = "OK";- strscpy(c[n].detail, "live register == eventlog replay",+ strscpy(c[n].detail, "live register equals the eventlog replay",sizeof(c[n].detail));} else if (in->cm_seen) {c[n].status = "ALERT";strscpy(c[n].detail,- "live register != eventlog replay (tamper?)",+ "live register differs from the eventlog replay",sizeof(c[n].detail));} else {c[n].status = "WARN";@@ -183,7 +183,7 @@ size_t conditions(const struct conditions_input *in,c[n].status = "OK";if (!in->config_seen) {c[n].status = "WARN";- strscpy(c[n].detail, "no config activation state (init not run?)",+ strscpy(c[n].detail, "no config activation state before init",sizeof(c[n].detail));} else if (in->config_state == -EINPROGRESS) {c[n].status = "WARN";@@ -209,9 +209,9 @@ void conditions_print(const struct condition *c, size_t n)size_t i;printf("Conditions:\n");- printf(" %-16s %-7s %s\n", "TYPE", "STATUS", "DETAIL");+ printf(" %-18s %-7s %s\n", "TYPE", "STATUS", "DETAIL");for (i = 0; i < n; i++)- printf(" %-16s %-7s %s\n", c[i].type, c[i].status,+ printf(" %-18s %-7s %s\n", c[i].type, c[i].status,c[i].detail);}@@ -248,7 +248,7 @@ void status_reason(const struct conditions_input *in,strscpy(buf, "status JSON unparseable", cap);} else if (strcmp(v, "tampered") == 0) {if (in->cm_seen && !in->chain_matches)- strscpy(buf, "live register != eventlog replay", cap);+ strscpy(buf, "live register differs from the eventlog replay", cap);else if (in->pins_unmeasured)strscpy(buf, "a upatch is pinned or archived without a record of this boot",cap);@@ -271,7 +271,7 @@ void status_reason(const struct conditions_input *in,elsestrscpy(buf, "the config key init froze is gone", cap);} else if (strcmp(v, "lsm-off") == 0) {- strscpy(buf, "LSM not attached -- enforcement OFF", cap);+ strscpy(buf, "LSM not attached, enforcement off", cap);} else if (strcmp(v, "init-pending") == 0) {strscpy(buf, "target hasn't been `shirudo init`'d", cap);} else if (strcmp(v, "reboot-pending") == 0) {diff --git a/util/image_runtime.c b/util/image_runtime.cindex 6351f51e..b5e48f6f 100644--- a/util/image_runtime.c+++ b/util/image_runtime.c@@ -1020,7 +1020,7 @@ int image_config_state(__u8 root[32])return image.config_state;}-int image_status(void)+int image_status(bool json){struct config_update_record record;char buffer[512], root[65];@@ -1037,6 +1037,19 @@ int image_status(void)return ret;hex_encode(record.target.root_hash, 32, root);ret = record.pending ? -EINPROGRESS : current_config();+ if (!json) {+ printf("%-22s %s\n", "Config root hash:", root);+ printf("%-22s %d\n", "PCR:", record.pcr);+ printf("%-22s %lld\n", "Sequence:", (long long)record.sequence);+ printf("%-22s %lld\n", "TPM reset count:",+ (long long)record.reset_count);+ printf("%-22s %lld\n", "Restart count:",+ (long long)record.restart_count);+ printf("%-22s %s\n", "Pending:", record.pending ?+ "yes, until the next reboot" : "no");+ printf("%-22s %s\n", "Consistent:", ret ? "no" : "yes");+ return ret;+ }json_obj_open(&emit);json_kv_string(&emit, "root_hash", root);json_kv_int(&emit, "pcr", record.pcr);diff --git a/util/image_runtime.h b/util/image_runtime.hindex 25c0e513..2f021ca3 100644--- a/util/image_runtime.h+++ b/util/image_runtime.h@@ -22,7 +22,7 @@ int image_boot_complete(void);int image_enter(const char *command, int argc, const char **argv);void image_leave(void);int image_update(const char *prefix);-int image_status(void);+int image_status(bool json);/** The config state status reports: 0 with the selected config active,diff --git a/util/kmodules.c b/util/kmodules.cdeleted file mode 100644index 57a1a90c..00000000--- a/util/kmodules.c+++ /dev/null@@ -1,487 +0,0 @@-// SPDX-License-Identifier: BSD-2-Clause-/*- * Copyright (c) 2026 Authors of shirudo- *- * /proc/modules parser and dependency-tree printer.- */--#include <ctype.h>-#include <errno.h>-#include <fcntl.h>-#include <stdint.h>-#include <stdio.h>-#include <stdlib.h>-#include <string.h>-#include <sys/stat.h>-#include <unistd.h>--#include <time.h>--#include <shirudo/misc.h>-#include <shirudo/string.h>--#include "format.h"-#include "kmodules.h"-#include "malloc.h"-#include "timefmt.h"--static int slurp(char **buf_out, size_t *len_out)-{- size_t cap = 16384, len = 0;- char *buf;- int fd;-- fd = open("/proc/modules", O_RDONLY | O_CLOEXEC);- if (fd < 0)- return -errno;- buf = xmalloc(cap);- if (!buf) {- close(fd);- return -ENOMEM;- }- for (;;) {- ssize_t n = read(fd, buf + len, cap - len - 1);-- if (n < 0) {- int e = -errno;-- xfree(buf, cap);- close(fd);- return e;- }- if (n == 0)- break;- len += (size_t)n;- if (cap - len < 4096) {- void *p = xreallocarray(buf, cap, cap * 2, 1);-- if (!p) {- xfree(buf, cap);- close(fd);- return -ENOMEM;- }- buf = p;- cap *= 2;- }- }- close(fd);- buf[len] = '\0';- *buf_out = buf;- *len_out = cap; /* freed at full cap by caller */- return 0;-}--static int kmod_cmp(const void *a, const void *b)-{- return strcmp(((const struct kmod *)a)->name,- ((const struct kmod *)b)->name);-}--static int kmod_find(const struct kmod_set *set, const char *name)-{- size_t lo = 0, hi = set->n;-- while (lo < hi) {- size_t mid = lo + (hi - lo) / 2;- int c = strcmp(set->mods[mid].name, name);-- if (c == 0)- return (int)mid;- if (c < 0)- lo = mid + 1;- else- hi = mid;- }- return -1;-}--/*- * The number in the next column, which *p then points past, or 0 when- * there is none: the kernel prints "-" as the use count of a module it- * cannot unload.- */-static __u64 next_column(char **p, __u64 max)-{- char *s = *p + strspn(*p, " \t");- size_t n = digits(s, strlen(s));- __u64 v;-- *p = s + n;- return parse_u64(s, n, max, &v) ? 0 : v;-}--int kmodules_parse(char *buf, struct kmod_set *set)-{- size_t edge_cap = 256, n_edges = 0;- struct edge { __u16 user, dep; } *edges = NULL;- char *line, *end;- size_t i, j;- int ret;-- memset(set, 0, sizeof(*set));- end = buf + strlen(buf);- for (line = buf; line < end; line++) {- if (*line == '\n')- *line = '\0';- }-- set->mods_cap = 64;- set->deps_cap = 256;- set->mods = xmalloc(set->mods_cap * sizeof(*set->mods));- set->deps = xmalloc(set->deps_cap * sizeof(*set->deps));- edges = xmalloc(edge_cap * sizeof(*edges));- if (!set->mods || !set->deps || !edges) {- ret = -ENOMEM;- goto out;- }-- /*- * Names first, sorted, so that the second pass can turn the- * used-by column into indices.- */- for (line = buf; line < end; line += strlen(line) + 1) {- struct kmod *m;- char *p = line, *e;- size_t name_len;-- while (*p == ' ' || *p == '\t')- p++;- if (!*p)- continue;- e = p;- while (*e && *e != ' ' && *e != '\t')- e++;- name_len = (size_t)(e - p);- if (name_len == 0 || name_len >= KMOD_NAME_LEN)- continue;- if (set->n == set->mods_cap) {- void *np = xreallocarray(set->mods, set->mods_cap,- set->mods_cap * 2,- sizeof(*set->mods));-- if (!np) {- ret = -ENOMEM;- goto out;- }- set->mods = np;- set->mods_cap *= 2;- }- m = &set->mods[set->n++];- memcpy(m->name, p, name_len);- m->name[name_len] = '\0';- m->size = next_column(&e, UINT64_MAX);- m->refcount = (__u32)next_column(&e, UINT32_MAX);- }- qsort(set->mods, set->n, sizeof(*set->mods), kmod_cmp);-- /* A module index and a dependency offset are __u16. */- if (set->n > UINT16_MAX) {- ret = -E2BIG;- goto out;- }-- /*- * The fourth column of a line names who uses the module, so each- * entry there is an edge from that user down to the module.- */- for (line = buf; line < end; line += strlen(line) + 1) {- char name[KMOD_NAME_LEN];- char *p = line, *e;- size_t name_len;- int dep, col;-- while (*p == ' ' || *p == '\t')- p++;- if (!*p)- continue;- e = p;- while (*e && *e != ' ' && *e != '\t')- e++;- name_len = (size_t)(e - p);- if (name_len == 0 || name_len >= sizeof(name))- continue;- memcpy(name, p, name_len);- name[name_len] = '\0';- dep = kmod_find(set, name);- if (dep < 0)- continue;- p = e;- for (col = 0; col < 2 && *p; col++) {- while (*p == ' ' || *p == '\t')- p++;- while (*p && *p != ' ' && *p != '\t')- p++;- }- while (*p == ' ' || *p == '\t')- p++;- if (!*p || *p == '-')- continue;- while (*p && *p != ' ' && *p != '\t') {- int user = -1;-- e = p;- while (*e && *e != ',' && *e != ' ' && *e != '\t')- e++;- name_len = (size_t)(e - p);- if (name_len && name_len < sizeof(name)) {- memcpy(name, p, name_len);- name[name_len] = '\0';- user = kmod_find(set, name);- }- p = *e == ',' ? e + 1 : e;- if (user < 0)- continue;- if (n_edges == edge_cap) {- void *np = xreallocarray(edges, edge_cap,- edge_cap * 2,- sizeof(*edges));-- if (!np) {- ret = -ENOMEM;- goto out;- }- edges = np;- edge_cap *= 2;- }- edges[n_edges].user = (__u16)user;- edges[n_edges].dep = (__u16)dep;- n_edges++;- }- }-- for (i = 0; i < set->n; i++) {- set->mods[i].deps_off = (__u16)set->n_deps;- set->mods[i].n_deps = 0;- for (j = 0; j < n_edges; j++) {- if (edges[j].user != i)- continue;- if (set->n_deps >= UINT16_MAX) {- ret = -E2BIG;- goto out;- }- if (set->n_deps == set->deps_cap) {- void *np = xreallocarray(set->deps, set->deps_cap,- set->deps_cap * 2,- sizeof(*set->deps));-- if (!np) {- ret = -ENOMEM;- goto out;- }- set->deps = np;- set->deps_cap *= 2;- }- set->deps[set->n_deps++] = edges[j].dep;- set->mods[i].n_deps++;- }- }-- ret = 0;-out:- xfree(edges, edge_cap * sizeof(*edges));- if (ret) {- xfree(set->mods, set->mods_cap * sizeof(*set->mods));- xfree(set->deps, set->deps_cap * sizeof(*set->deps));- memset(set, 0, sizeof(*set));- }- return ret;-}--int kmodules_read(struct kmod_set *set)-{- size_t buf_cap = 0, i;- char *buf = NULL;- int ret;-- memset(set, 0, sizeof(*set));- ret = slurp(&buf, &buf_cap);- if (ret)- return ret;- ret = kmodules_parse(buf, set);- xfree(buf, buf_cap);- if (ret)- return ret;-- /*- * Stat each /sys/module/<name>/ for its kernfs mtime, which the- * kernel sets when sysfs_create_dir registers the module's- * kobject during init_module/finit_module. That mtime is the- * load time. ENOENT on a race (rmmod between /proc/modules read- * and this stat) is non-fatal; leave loaded_at zero.- */- for (i = 0; i < set->n; i++) {- struct kmod *m = &set->mods[i];- char path[64 + sizeof("/sys/module/")];- struct stat st;-- if (strsprintf(path, sizeof(path), "/sys/module/%s",- m->name) >= 0 && stat(path, &st) == 0) {- m->loaded_at_sec = (__s64)st.st_mtim.tv_sec;- m->loaded_at_nsec = (__s32)st.st_mtim.tv_nsec;- }- }- return 0;-}--void kmodules_free(struct kmod_set *set)-{- xfree(set->mods, set->mods_cap * sizeof(*set->mods));- xfree(set->deps, set->deps_cap * sizeof(*set->deps));- memset(set, 0, sizeof(*set));-}--static void print_subtree(const struct kmod_set *set, size_t i,- const char *prefix, int is_last, __u8 *seen)-{- const struct kmod *m = &set->mods[i];- const char *branch = is_last ? "└── " : "├── ";- int already = (seen[i >> 3] >> (i & 7)) & 1;- const char *child = prefix;- char child_prefix[256];- char size_s[16];-- human_size(m->size, size_s, sizeof(size_s));-- if (already) {- printf("%s%s%s (shared)\n", prefix, branch, m->name);- return;- }- seen[i >> 3] |= (__u8)(1U << (i & 7));-- printf("%s%s%s (%s, refs=%u)\n", prefix, branch, m->name,- size_s, (__u32)m->refcount);-- if (strsprintf(child_prefix, sizeof(child_prefix), "%s%s", prefix,- is_last ? " " : "│ ") >= 0)- child = child_prefix;-- for (__u16 k = 0; k < m->n_deps; k++) {- size_t dep = set->deps[m->deps_off + k];- int last_child = (k == m->n_deps - 1);-- print_subtree(set, dep, child, last_child, seen);- }-}--void kmodules_print_tree(const struct kmod_set *set)-{- __u8 *used_by;- __u8 *seen;- size_t bitmap_bytes;- size_t n_roots = 0;- size_t *roots;-- if (set->n == 0) {- printf(" (no modules loaded)\n");- return;- }-- bitmap_bytes = (set->n + 7) / 8;- used_by = xcalloc(bitmap_bytes, 1);- seen = xcalloc(bitmap_bytes, 1);- roots = xmalloc(set->n * sizeof(*roots));- if (!used_by || !seen || !roots) {- xfree(used_by, bitmap_bytes);- xfree(seen, bitmap_bytes);- xfree(roots, set->n * sizeof(*roots));- printf(" (out of memory)\n");- return;- }-- /*- * Mark "is a dep of someone": that module is NOT a root.- * The remainder are entry-point modules nothing else uses.- */- for (size_t i = 0; i < set->n; i++) {- const struct kmod *m = &set->mods[i];-- for (__u16 k = 0; k < m->n_deps; k++) {- size_t d = set->deps[m->deps_off + k];-- used_by[d >> 3] |= (__u8)(1U << (d & 7));- }- }- for (size_t i = 0; i < set->n; i++) {- if (((used_by[i >> 3] >> (i & 7)) & 1) == 0)- roots[n_roots++] = i;- }-- for (size_t r = 0; r < n_roots; r++) {- int is_last = (r == n_roots - 1);-- print_subtree(set, roots[r], " ", is_last, seen);- }-- xfree(used_by, bitmap_bytes);- xfree(seen, bitmap_bytes);- xfree(roots, set->n * sizeof(*roots));-}--/*- * qsort comparator: descending by (loaded_at_sec, loaded_at_nsec).- * Indices into set->mods[]. Modules with loaded_at_sec == 0 (stat- * failure) sort to the bottom so they don't crowd out real entries.- */-struct recent_idx {- const struct kmod_set *set;- size_t idx;-};--static int recent_cmp(const void *a, const void *b)-{- const struct recent_idx *x = a, *y = b;- const struct kmod *mx = &x->set->mods[x->idx];- const struct kmod *my = &y->set->mods[y->idx];-- if (mx->loaded_at_sec == 0 && my->loaded_at_sec != 0)- return 1;- if (mx->loaded_at_sec != 0 && my->loaded_at_sec == 0)- return -1;- if (mx->loaded_at_sec != my->loaded_at_sec)- return mx->loaded_at_sec < my->loaded_at_sec ? 1 : -1;- if (mx->loaded_at_nsec != my->loaded_at_nsec)- return mx->loaded_at_nsec < my->loaded_at_nsec ? 1 : -1;- return strcmp(mx->name, my->name);-}--void kmodules_print_recent(const struct kmod_set *set,- size_t last_n, __s64 boot_sec)-{- struct recent_idx *all;- size_t take, i;-- if (set->n == 0) {- printf(" (no modules loaded)\n");- return;- }-- all = xmalloc(set->n * sizeof(*all));- if (!all) {- printf(" (out of memory)\n");- return;- }- for (i = 0; i < set->n; i++) {- all[i].set = set;- all[i].idx = i;- }- qsort(all, set->n, sizeof(*all), recent_cmp);- take = min(set->n, last_n);- for (i = 0; i < take; i++) {- const struct kmod *m = &set->mods[all[i].idx];- char ts[32], size_s[16], age[24];-- if (m->loaded_at_sec <= 0 ||- iso8601((time_t)m->loaded_at_sec, ts, sizeof(ts)))- strscpy(ts, "?", sizeof(ts));- human_size(m->size, size_s, sizeof(size_s));- if (boot_sec > 0 && m->loaded_at_sec >= boot_sec)- format_duration((long)(m->loaded_at_sec - boot_sec),- age, sizeof(age));- else- strscpy(age, "?", sizeof(age));-- printf(" [%s] %s (%s, refs=%u, %s since boot)\n",- ts, m->name, size_s, (__u32)m->refcount, age);- }- xfree(all, set->n * sizeof(*all));-}diff --git a/util/kmodules.h b/util/kmodules.hdeleted file mode 100644index 5d8f2d5b..00000000--- a/util/kmodules.h+++ /dev/null@@ -1,56 +0,0 @@-/* SPDX-License-Identifier: BSD-2-Clause */-/*- * Copyright (c) 2026 Authors of shirudo- *- * /proc/modules as a dependency tree, for `status --include-modules`.- */--#ifndef SHIRUDO_UTIL_KMODULES_H-#define SHIRUDO_UTIL_KMODULES_H--#include <stddef.h>--#include <shirudo/misc.h>--#define KMOD_NAME_LEN 64--struct kmod {- char name[KMOD_NAME_LEN];- __u64 size; /* bytes */- __u32 refcount; /* /proc/modules column 3 */- __u16 n_deps;- __u16 deps_off; /* index into the global deps[] */- /*- * sysfs `/sys/module/<name>` mtime -- the moment the kernel's- * kobject for this module was created, i.e. when it was loaded.- * Zero if the stat() failed (race: rmmod between /proc/modules- * read and the per-module stat).- */- __s64 loaded_at_sec;- __s32 loaded_at_nsec;-};--struct kmod_set {- struct kmod *mods; /* sorted by name, ascending */- size_t n;- __u16 *deps; /* flat: mods[i].deps_off..+n_deps */- size_t n_deps;- size_t mods_cap;- size_t deps_cap;-};--int kmodules_read(struct kmod_set *set);-/* The text of /proc/modules, modified in place, into set. */-int kmodules_parse(char *buf, struct kmod_set *set);-void kmodules_free(struct kmod_set *set);--void kmodules_print_tree(const struct kmod_set *set);--/*- * boot_sec is the wallclock instant of boot: the since-boot column is- * elapsed from boot, not time ago.- */-void kmodules_print_recent(const struct kmod_set *set,- size_t last_n, __s64 boot_sec);--#endif /* SHIRUDO_UTIL_KMODULES_H */diff --git a/util/kmsg.c b/util/kmsg.cdeleted file mode 100644index 887272ba..00000000--- a/util/kmsg.c+++ /dev/null@@ -1,205 +0,0 @@-// SPDX-License-Identifier: BSD-2-Clause-/*- * Copyright (c) 2026 Authors of shirudo- *- * /dev/kmsg reader; the records' monotonic timestamps become wallclock- * UTC the way `dmesg --time-format=iso` does.- */--#include <errno.h>-#include <fcntl.h>-#include <stdbool.h>-#include <stdint.h>-#include <stdio.h>-#include <string.h>-#include <sys/types.h>-#include <time.h>-#include <unistd.h>--#include <shirudo/misc.h>-#include <shirudo/string.h>--#include "kmsg.h"-#include "timefmt.h"-#include "malloc.h"--/* Per-record buffer size accepted by /dev/kmsg: kernel allows up to 8 KiB. */-#define KMSG_READ_BUF 8192--static ssize_t read_record(int fd, char *buf, size_t cap)-{- ssize_t n = read(fd, buf, cap);-- if (n > 0)- return n;- if (n == 0)- return 0;- if (errno == EAGAIN)- return 0;- if (errno == EPIPE)- return -EPIPE;- return -errno;-}--static int parse_record(const char *rec, size_t len,- __u64 *monotonic_us_out,- const char **msg_out, size_t *msg_len_out)-{- const char *semi, *end;- const char *p;- int commas = 0;-- end = rec + len;- semi = memchr(rec, ';', len);- if (!semi)- return -EINVAL;-- for (p = rec; p < semi; p++) {- if (*p == ',') {- commas++;- if (commas == 2) {- const char *q = p + 1;-- if (parse_u64(q, digits(q, (size_t)(semi - q)),- UINT64_MAX, monotonic_us_out))- return -EINVAL;- break;- }- }- }- if (commas < 2)- return -EINVAL;-- *msg_out = semi + 1;- {- const char *nl = memchr(*msg_out, '\n',- (size_t)(end - *msg_out));-- *msg_len_out = nl ? (size_t)(nl - *msg_out)- : (size_t)(end - *msg_out);- }- return 0;-}--/* Strip control bytes (kernel sometimes embeds \x01..\x08 markers). */-static void copy_msg(char *dst, size_t dst_cap,- const char *src, size_t src_len)-{- size_t i, o = 0;-- if (dst_cap == 0)- return;- for (i = 0; i < src_len && o + 1 < dst_cap; i++) {- __u8 c = (__u8)src[i];-- if (c == '\t' || c == ' ' || (c >= 0x20 && c < 0x7f))- dst[o++] = (char)c;- else if (c >= 0x80)- dst[o++] = (char)c;- }- dst[o] = '\0';-}--static void monotonic_to_iso(__u64 mono_us,- const struct timespec *rt_at_open,- const struct timespec *mt_at_open,- char *out, size_t out_cap)-{- struct timespec rec;-- /*- * record_realtime = realtime_at_open + (record_monotonic- * - monotonic_at_open),- * seconds and nanoseconds apart so that no timestamp overflows.- */- rec.tv_sec = rt_at_open->tv_sec - mt_at_open->tv_sec +- (__s64)(mono_us / 1000000);- rec.tv_nsec = rt_at_open->tv_nsec - mt_at_open->tv_nsec +- (__s64)(mono_us % 1000000) * 1000;- if (rec.tv_nsec < 0) {- rec.tv_nsec += 1000000000LL;- rec.tv_sec--;- } else if (rec.tv_nsec >= 1000000000LL) {- rec.tv_nsec -= 1000000000LL;- rec.tv_sec++;- }-- if (iso8601(rec.tv_sec, out, out_cap))- strscpy(out, "?", out_cap);-}--int kmsg_tail(struct kmsg_record *out, size_t cap)-{- struct timespec rt_at_open, mt_at_open;- char buf[KMSG_READ_BUF];- size_t head = 0, count = 0;- int fd;-- if (cap == 0)- return 0;-- fd = open("/dev/kmsg", O_RDONLY | O_NONBLOCK | O_CLOEXEC);- if (fd < 0)- return -errno;- /*- * Default open() position is the *start* of the ring buffer- * (oldest available record). That is exactly what we want.- */- if (clock_gettime(CLOCK_REALTIME, &rt_at_open) != 0 ||- clock_gettime(CLOCK_MONOTONIC, &mt_at_open) != 0) {- int err = errno;-- close(fd);- return -err;- }-- for (;;) {- __u64 mono_us = 0;- const char *msg = NULL;- size_t msg_len = 0;- size_t slot;- ssize_t n;-- n = read_record(fd, buf, sizeof(buf));- if (n == 0)- break;- if (n == -EPIPE)- continue; /* skipped, try next */- if (n < 0) {- close(fd);- return (int)n;- }- if (parse_record(buf, (size_t)n, &mono_us, &msg, &msg_len) != 0)- continue;-- slot = head % cap;- monotonic_to_iso(mono_us, &rt_at_open, &mt_at_open,- out[slot].ts, sizeof(out[slot].ts));- copy_msg(out[slot].msg, sizeof(out[slot].msg), msg, msg_len);- head++;- if (count < cap)- count++;- }-- close(fd);- /*- * Reorder so out[0..count) is chronological. The ring buffer- * may have wrapped; rotate so the oldest surviving record is- * at index 0.- */- if (count == cap && head > cap) {- size_t bytes = cap * sizeof(*out);- size_t start = head % cap;- size_t i;- struct kmsg_record *tmp = xmalloc(bytes);-- if (!tmp)- return -ENOMEM;- for (i = 0; i < cap; i++)- tmp[i] = out[(start + i) % cap];- for (i = 0; i < cap; i++)- out[i] = tmp[i];- xfree(tmp, bytes);- }- return (int)count;-}diff --git a/util/kmsg.h b/util/kmsg.hdeleted file mode 100644index 5603faaf..00000000--- a/util/kmsg.h+++ /dev/null@@ -1,27 +0,0 @@-/* SPDX-License-Identifier: BSD-2-Clause */-/*- * Copyright (c) 2026 Authors of shirudo- *- * /dev/kmsg records with wallclock timestamps.- */--#ifndef SHIRUDO_UTIL_KMSG_H-#define SHIRUDO_UTIL_KMSG_H--#include <stddef.h>--#define KMSG_TS_LEN 24 /* "2026-05-28T14:32:01Z" + slack */-#define KMSG_MSG_LEN 480 /* one printk record, joined */--struct kmsg_record {- char ts[KMSG_TS_LEN]; /* ISO-8601 UTC, NUL-term */- char msg[KMSG_MSG_LEN]; /* control bytes stripped */-};--/*- * Records the ring buffer has dropped are skipped: EPIPE restarts the- * read.- */-int kmsg_tail(struct kmsg_record *out, size_t cap);--#endif /* SHIRUDO_UTIL_KMSG_H */diff --git a/util/preflight.c b/util/preflight.cindex 6fa02d01..3d41b5b0 100644--- a/util/preflight.c+++ b/util/preflight.c@@ -353,8 +353,9 @@ static void check_tpm(struct preflight_result *r)if (override) {pass(c);if (strsprintf(c->detail, sizeof(c->detail),- "TCTI override: %s", cfg.tpm_tcti) < 0)- strscpy(c->detail, "TCTI override",+ "TCTI from the config: %s",+ cfg.tpm_tcti) < 0)+ strscpy(c->detail, "TCTI from the config",sizeof(c->detail));}if (override)diff --git a/util/upatch_maps.c b/util/upatch_maps.cindex ff30bafe..d23e402e 100644--- a/util/upatch_maps.c+++ b/util/upatch_maps.c@@ -1496,7 +1496,7 @@ void upatch_maps_print_detail(const struct map_view *v){__u32 i;- printf("upatch: %s\n", v->upatch);+ printf("Name: %s\n", v->upatch);printf("Map: %s\n", v->name);if (upatch_map_is_percpu(v->type))printf("Type: %s (%u CPUs)\n",@@ -1505,7 +1505,7 @@ void upatch_maps_print_detail(const struct map_view *v)printf("Type: %s\n", v->type_name);printf("Max entries: %u\n", v->max_entries);if (v->skipped) {- printf("Status: skipped -- %s\n",+ printf("Status: skipped: %s\n",v->skipped_reason ? v->skipped_reason : "(no reason)");return;}diff --git a/util/upatch_table.c b/util/upatch_table.cindex 47677bff..f9d7c17d 100644--- a/util/upatch_table.c+++ b/util/upatch_table.c@@ -31,9 +31,11 @@ void upatch_table_print(const struct upatch_table_row *rows,{size_t i;- printf("\nupatches loaded (%zu):\n", n);- if (n == 0)+ printf("\nLoaded upatches (%zu):\n", n);+ if (n == 0) {+ printf(" none\n");return;+ }printf(" %-24s %-28s %5s %-28s %s\n","NAME", "LOCATION", "MAPS", "STATUS", "AGE");for (i = 0; i < n; i++) {