Skip to content

eBPF-based security platform

tpm: classify device commands and reserve protected mutations

KP Singh4cbcb29362f8
diff --git a/Documentation/internals/measurement-register.rst b/Documentation/internals/measurement-register.rst
index b1b88b8f..415636a7 100644
--- a/Documentation/internals/measurement-register.rst
+++ b/Documentation/internals/measurement-register.rst
@@ -645,3 +645,40 @@ Related
- :doc:`/concepts/measurement-register` for the concept
- :doc:`/operate/run/attest` for attesting a target
- :doc:`/reference/eventlog` for the eventlog format
+
+TPM command authority
+======================
+
+The kernel ``tpm_command`` LSM hook runs after the TPM driver copies a
+userspace command into its buffer and before it submits the command. The BPF
+guard therefore checks every write to the raw and resource-manager devices,
+including writes through a descriptor another task opened. It does not inspect
+kernel-internal TPM commands. The classifier is ``include/shirudo/tpm_command.h``;
+the BPF program and the unit test include the same code.
+
+The policy is frozen during authenticated initialization:
+
+* Only the full Shirudo task role may mutate the measurement register
+ ``0x01818E00``: definition, deletion, extension, writes, increments, bit
+ changes, authorization changes and read/write locks.
+* Only the full role may extend, reset or change the authorization of the
+ configured config PCR.
+* systemd defines its NvPCRs in the UAPI.19 Linux range
+ (``0x01D10200`` to ``0x01D105FF``) from the initrd, before the guards attach,
+ and anchors each in PCR 9. Afterwards it only extends them. Extensions stay
+ available; every other mutation of an index in that range needs the full
+ role, so no root process can delete and recreate an NvPCR that its anchor
+ names.
+* Every other PCR stays the platform's. systemd's ``systemd-pcrmachine`` and
+ ``systemd-pcrfs`` extend PCR 15 as root, for example.
+* Hierarchy changes, clear, global write locks, shutdown and other
+ measurement-affecting administration need the full role, as do unknown and
+ vendor commands. ``TPM2_Startup`` stays available: systemd probes a TPM that
+ the firmware already initialized. Malformed headers and handle encodings are
+ refused.
+* Known read, attestation, session and cryptographic commands stay available.
+ Unrelated NV indices keep their normal TPM authorization.
+
+Denials increment ``TpmWrite`` in the tamper counters. ABI pre-flight rejects a
+kernel without the hook. ``testing/helper/test-tpm-command`` covers the
+classifier and ``testing/fuzz/fuzz-tpm-command`` fuzzes it.
diff --git a/Documentation/reference/cli/status.rst b/Documentation/reference/cli/status.rst
index 280ad4cf..65389411 100644
--- a/Documentation/reference/cli/status.rst
+++ b/Documentation/reference/cli/status.rst
@@ -333,7 +333,7 @@ Print the keepalive body of the same target, which follows no tree:
.. code-block:: console
target# shirudo status --keepalive
- {"schema":"shirudo.keepalive/1","boot_id":"82639935-1127-4dab-91b5-f818eabc7f13","version_id":"d0d7aa800303439023907d1979d917d46a21bec21f816689c138728a28e84af9","config_root":"6d5ed552f448a1c07e3b9d24f5a86c1e0b7d93f2c4e5a6b7180c9d2e3f4a5b6c","kernel_release":"7.3.0-bpf-next+","image_id":null,"image_version":null,"image_root":null,"verdict":"ok","cond":5461,"flags":0,"tamper":[15,0,0,0,0,1,0,0,0,0,0,8,0,0,0,0,0,1,0,0,1,0,0,0,0,0,7,0,0,2,0,0,0,0,0,0,0,0,0,0,0,0],"integrity":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"tree_id":null,"generation":null,"base_seq":null,"last_seq":null,"base_root":null,"projection_root":null,"mask":null,"set_sha256":"5f0c2e8b7a1d4c3f9e6b2a0d8c7f1e3b5a9d4c2e6f8b0a1d3c5e7f9b2d4a6c8e","count":1,"not_ok":0}
+ {"schema":"shirudo.keepalive/1","boot_id":"82639935-1127-4dab-91b5-f818eabc7f13","version_id":"d0d7aa800303439023907d1979d917d46a21bec21f816689c138728a28e84af9","config_root":"6d5ed552f448a1c07e3b9d24f5a86c1e0b7d93f2c4e5a6b7180c9d2e3f4a5b6c","kernel_release":"7.3.0-bpf-next+","image_id":null,"image_version":null,"image_root":null,"verdict":"ok","cond":5461,"flags":0,"tamper":[15,0,0,0,0,1,0,0,0,0,0,8,0,0,0,0,0,1,0,0,1,0,0,0,0,0,7,0,0,2,0,0,0,0,0,0,0,0,0,0,0,0,0],"integrity":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"tree_id":null,"generation":null,"base_seq":null,"last_seq":null,"base_root":null,"projection_root":null,"mask":null,"set_sha256":"5f0c2e8b7a1d4c3f9e6b2a0d8c7f1e3b5a9d4c2e6f8b0a1d3c5e7f9b2d4a6c8e","count":1,"not_ok":0}
Add this boot's eventlog to the report:
diff --git a/Documentation/reference/formats/keepalive.rst b/Documentation/reference/formats/keepalive.rst
index f0096e78..00f9a5d2 100644
--- a/Documentation/reference/formats/keepalive.rst
+++ b/Documentation/reference/formats/keepalive.rst
@@ -356,7 +356,7 @@ The body of a target with verdict ``ok`` that follows no tree:
.. code-block:: json
- {"schema":"shirudo.keepalive/1","boot_id":"82639935-1127-4dab-91b5-f818eabc7f13","version_id":"d0d7aa800303439023907d1979d917d46a21bec21f816689c138728a28e84af9","config_root":"6d5ed552f448a1c07e3b9d24f5a86c1e0b7d93f2c4e5a6b7180c9d2e3f4a5b6c","kernel_release":"7.3.0-bpf-next+","image_id":null,"image_version":null,"image_root":null,"verdict":"ok","cond":5461,"flags":0,"tamper":[15,0,0,0,0,1,0,0,0,0,0,8,0,0,0,0,0,1,0,0,1,0,0,0,0,0,7,0,0,2,0,0,0,0,0,0,0,0,0,0,0,0],"integrity":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"tree_id":null,"generation":null,"base_seq":null,"last_seq":null,"base_root":null,"projection_root":null,"mask":null,"set_sha256":"5f0c2e8b7a1d4c3f9e6b2a0d8c7f1e3b5a9d4c2e6f8b0a1d3c5e7f9b2d4a6c8e","count":1,"not_ok":0}
+ {"schema":"shirudo.keepalive/1","boot_id":"82639935-1127-4dab-91b5-f818eabc7f13","version_id":"d0d7aa800303439023907d1979d917d46a21bec21f816689c138728a28e84af9","config_root":"6d5ed552f448a1c07e3b9d24f5a86c1e0b7d93f2c4e5a6b7180c9d2e3f4a5b6c","kernel_release":"7.3.0-bpf-next+","image_id":null,"image_version":null,"image_root":null,"verdict":"ok","cond":5461,"flags":0,"tamper":[15,0,0,0,0,1,0,0,0,0,0,8,0,0,0,0,0,1,0,0,1,0,0,0,0,0,7,0,0,2,0,0,0,0,0,0,0,0,0,0,0,0,0],"integrity":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"tree_id":null,"generation":null,"base_seq":null,"last_seq":null,"base_root":null,"projection_root":null,"mask":null,"set_sha256":"5f0c2e8b7a1d4c3f9e6b2a0d8c7f1e3b5a9d4c2e6f8b0a1d3c5e7f9b2d4a6c8e","count":1,"not_ok":0}
Keepalive document
------------------
diff --git a/Documentation/security/tamper-counters.rst b/Documentation/security/tamper-counters.rst
index 978a3916..6882edba 100644
--- a/Documentation/security/tamper-counters.rst
+++ b/Documentation/security/tamper-counters.rst
@@ -210,6 +210,13 @@ counter.
without runtime authority, or a command too short to inspect
from any caller
- ``EACCES``
+ * - ``TpmWrite``
+ - protected TPM mutation by an unauthorized task
+ - ``lsm/tpm_command``: from a task without runtime authority, a
+ mutation of shirudo's register or the config PCR, a mutation other
+ than an extension of a systemd NvPCR, a hierarchy or clear
+ command, or an unknown or malformed command
+ - ``EACCES``
* - ``ObjGet``
- pin, map, link or XDP program opened by another executable
- ``lsm/bpf``: ``BPF_OBJ_GET``, ``BPF_MAP_GET_FD_BY_ID``,
diff --git a/Documentation/security/threat-model.rst b/Documentation/security/threat-model.rst
index 11f86dd6..8ee20dc5 100644
--- a/Documentation/security/threat-model.rst
+++ b/Documentation/security/threat-model.rst
@@ -1042,8 +1042,13 @@ signature alone does not change the register: the TPM must receive the
command written to ``/dev/tpm0`` or ``/dev/tpmrm0`` before the driver
queues it, and refuses an ``NV_Extend`` of shirudo's frozen index from a
task without authority, through inherited and nonblocking descriptors
-too (``TpmExtend``). Other NV indices, PCR extensions and TPM signing
-stay open to everyone.
+too (``TpmExtend``). The same hook classifies every other command
+(:doc:`/internals/measurement-register`, TPM command authority). Only shirudo may
+mutate its register, extend or reset the config PCR, change the
+hierarchies or send an unknown command. systemd's NvPCRs accept
+extensions only, so no root process can delete and recreate one that its
+PCR 9 anchor names. Every refusal counts as ``TpmWrite``. Other NV
+indices, other PCRs and TPM signing stay open to everyone.
The order of the steps decides what a crash or a stopped process
leaves, and Figure 3 in :ref:`register-lock` draws it for a load, an
@@ -1095,8 +1100,8 @@ tree operations run without it.
:Enforced at: ``lsm/tpm_command``
:Refusal: ``EACCES`` from ``write(2)`` on the TPM device; ``tampered``,
``tpm_error`` and ``eventlog_full`` from shirudo
-:Counters: ``TpmExtend``
-:Tests: ``t4002``, ``t4003``, ``t4102``, ``t4103``, ``t6115``,
+:Counters: ``TpmExtend``, ``TpmWrite``
+:Tests: ``t0057``, ``t4002``, ``t4003``, ``t4102``, ``t4103``, ``t6115``,
``t6122``, ``t6128``, ``t6143``, ``t6144``, ``t6147``
:Proofs: ``Shirudo.Chain``, ``Shirudo.Events``, ``Shirudo.Measured``,
``Shirudo.UpatchLoad``, ``chain-events``, ``measured-fold-model``,
@@ -1507,8 +1512,8 @@ driver; sessions do not prevent denial of service by dropping requests.
:Enforced at: ``lsm/tpm_command`` for commands that reach the driver;
pinned-key and session-response checks in userspace
:Refusal: the TPM operation fails; measuring commands refuse
-:Counters: ``TpmExtend`` for a refused extension; none for a
- substituted device
+:Counters: ``TpmExtend`` for a refused extension, ``TpmWrite`` for any
+ refused command; none for a substituted device
:Tests: ``t4005``, ``t4103``, ``t6125``
:Proofs: ``tpm-public``, ``tpm-kdf``
:Residual: trusted bootstrap (A1, A6, A8); denial of service
diff --git a/Makefile.shirudo b/Makefile.shirudo
index e8fa5181..0b6626e9 100644
--- a/Makefile.shirudo
+++ b/Makefile.shirudo
@@ -782,6 +782,7 @@ TEST_HELPERS := $(VERITY_TEST_HELPERS) \
testing/helper/test-config-image \
testing/helper/test-config-update \
testing/helper/test-config-attest \
+ testing/helper/test-tpm-command \
testing/helper/test-image-keys \
testing/helper/test-conditions \
testing/helper/test-config-image \
@@ -1043,6 +1044,10 @@ testing/helper/test-config-update: testing/helper/test-config-update.c \
@printf ' CC $@\n'
$(Q)$(CC) $(CFLAGS) -o $@ $^ $(REGISTER_LIBS)
+testing/helper/test-tpm-command: testing/helper/test-tpm-command.c include/shirudo/tpm_command.h
+ @printf ' CC $@\n'
+ $(Q)$(CC) $(CFLAGS) -o $@ $<
+
testing/helper/test-config-attest: testing/helper/test-config-attest.c \
util/attest.o util/upatch.o $(REGISTER_OBJS)
@printf ' CC $@\n'
@@ -1186,6 +1191,9 @@ FUZZ_PACKAGE := util/bpm_package.c util/bpm_tree.c util/chain_history.c \
FUZZ_TARGETS := $(patsubst testing/fuzz/%.c,$(FUZZ_OUT)/%, \
$(wildcard testing/fuzz/fuzz-*.c))
+$(FUZZ_OUT)/fuzz-tpm-command: testing/fuzz/fuzz-tpm-command.c $(FUZZ_BASE) \
+ include/shirudo/tpm_command.h
+
$(FUZZ_OUT)/fuzz-json: testing/fuzz/fuzz-json.c $(FUZZ_BASE)
$(FUZZ_OUT)/fuzz-oci-manifest: testing/fuzz/fuzz-oci-manifest.c \
$(FUZZ_BASE) $(FUZZ_OCI)
diff --git a/bpf/bpf2.c b/bpf/bpf2.c
index 768afbc7..655841bc 100644
--- a/bpf/bpf2.c
+++ b/bpf/bpf2.c
@@ -343,37 +343,6 @@ int BPF_PROG(shirudo_lsm_key_permission, key_ref_t key_ref,
shirudo_tamper_deny(TAMPER_KEYRING, -EACCES);
}
-/*
- * A TPM signature alone cannot change shirudo's NV register. Restrict
- * extension of its frozen index while leaving unrelated TPM signing alone.
- */
-SEC("lsm/tpm_command")
-int BPF_PROG(shirudo_lsm_tpm_command, struct file *file,
- const __u8 *command, size_t command_len, int ret)
-{
- struct sb_id *id;
- __u32 code, index;
-
- if (ret)
- return ret;
- if (command_len < 10 ||
- bpf_probe_read_kernel(&code, sizeof(code), command + 6))
- return shirudo_tamper_deny(TAMPER_TPM_EXTEND,
- -EACCES);
- if (bpf_ntohl(code) != TPM_CC_NV_EXTEND)
- return 0;
- if (command_len < 18 ||
- bpf_probe_read_kernel(&index, sizeof(index), command + 14))
- return shirudo_tamper_deny(TAMPER_TPM_EXTEND,
- -EACCES);
- id = shirudo_policy();
- if (!id || (bpf_ntohl(index) == id->nv_index &&
- !shirudo_task_is_self(id)))
- return shirudo_tamper_deny(TAMPER_TPM_EXTEND,
- -EACCES);
- return 0;
-}
-
/*
* Inside shirudo's bpffs: only an authorized caller may unlink
* (the `upatch unload` path). Every other caller -- including root
@@ -1165,3 +1134,34 @@ int BPF_PROG(shirudo_lsm_file_ioctl_compat, struct file *file,
{
return shirudo_ioctl(file, cmd, ret);
}
+
+#define SHIRUDO_TPM_COPY(out, in, size) bpf_probe_read_kernel(out, size, in)
+#include "../include/shirudo/tpm_command.h"
+#undef SHIRUDO_TPM_COPY
+
+/* Inspect each submitted command, including writes through inherited FDs. */
+SEC("lsm/tpm_command")
+int BPF_PROG(shirudo_lsm_tpm_command, struct file *file,
+ const __u8 *command, __u64 length, int ret)
+{
+ struct sb_id *id = shirudo_policy();
+ enum shirudo_tpm_access access;
+
+ if (ret)
+ return ret;
+ if (!id || length > 4096)
+ return -EPERM;
+ access = shirudo_tpm_access(command, length, id->config_pcr);
+ if (shirudo_tpm_allowed(access, shirudo_task_is_self(id)))
+ return 0;
+ if (length >= 18) {
+ __u32 code, index;
+
+ if (!bpf_probe_read_kernel(&code, sizeof(code), command + 6) &&
+ !bpf_probe_read_kernel(&index, sizeof(index), command + 14) &&
+ bpf_ntohl(code) == TPM_CC_NV_EXTEND &&
+ bpf_ntohl(index) == id->nv_index)
+ shirudo_tamper_count(TAMPER_TPM_EXTEND);
+ }
+ return shirudo_tamper_deny(SHIRUDO_TAMPER_TPM_WRITE, -EACCES);
+}
diff --git a/bpf/lib/identity.h b/bpf/lib/identity.h
index cc8ae95c..4212300f 100644
--- a/bpf/lib/identity.h
+++ b/bpf/lib/identity.h
@@ -24,6 +24,7 @@ struct sb_id {
__u32 n_dm_verity_keys;
__s32 dm_verity_keys[IDENTITY_KEYS_MAX];
__u32 nv_index;
+ __u32 config_pcr;
};
struct {
diff --git a/bpf/lib/tamper.h b/bpf/lib/tamper.h
index f0b3dcf7..dca213ac 100644
--- a/bpf/lib/tamper.h
+++ b/bpf/lib/tamper.h
@@ -54,6 +54,7 @@ enum tamper_point {
TAMPER_EXEC_SHARED,
TAMPER_XATTR_HANDLE,
TAMPER_SEAL_RLIMIT,
+ SHIRUDO_TAMPER_TPM_WRITE,
TAMPER_MAX
};
diff --git a/builtin-init.c b/builtin-init.c
index a0b318f9..ebc36fec 100644
--- a/builtin-init.c
+++ b/builtin-init.c
@@ -693,6 +693,7 @@ static int identity_build(struct identity *id)
memcpy(id->runtime_root, image_runtime_root(), 32);
id->nv_index = NV_INDEX;
+ id->config_pcr = shirudo_image_config_pcr();
err = bpf_anchor(id);
if (err)
diff --git a/include/shirudo/tpm_command.h b/include/shirudo/tpm_command.h
new file mode 100644
index 00000000..8598b44f
--- /dev/null
+++ b/include/shirudo/tpm_command.h
@@ -0,0 +1,229 @@
+/* SPDX-License-Identifier: GPL-2.0 OR BSD-2-Clause */
+/* Copyright (c) 2026 Authors of shirudo */
+
+#ifndef SHIRUDO_TPM_COMMAND_H
+#define SHIRUDO_TPM_COMMAND_H
+
+/* The includer supplies types, __always_inline and a bounded kernel/user copy. */
+enum shirudo_tpm_access {
+ SHIRUDO_TPM_PUBLIC,
+ SHIRUDO_TPM_RUNTIME,
+ SHIRUDO_TPM_MALFORMED,
+};
+
+static __always_inline bool shirudo_tpm_allowed(enum shirudo_tpm_access access,
+ bool runtime)
+{
+ return access != SHIRUDO_TPM_MALFORMED &&
+ (access == SHIRUDO_TPM_PUBLIC || runtime);
+}
+
+static __always_inline int
+shirudo_tpm_word(const __u8 *command, __u32 length, __u32 offset,
+ __u32 width, __u32 *value)
+{
+ __u8 bytes[4] = {};
+
+ if (offset > length || width > length - offset ||
+ SHIRUDO_TPM_COPY(bytes, command + offset, width))
+ return -1;
+ if (width == 2)
+ *value = ((__u32)bytes[0] << 8) | bytes[1];
+ else
+ *value = ((__u32)bytes[0] << 24) | ((__u32)bytes[1] << 16) |
+ ((__u32)bytes[2] << 8) | bytes[3];
+ return 0;
+}
+
+/*
+ * systemd defines its NvPCRs (verity, hardware, login, cryptsetup, ...) in the
+ * UAPI.19 Linux range from the initrd, before the guards attach, and anchors
+ * each in PCR 9. Afterwards it only extends them, as root. Deleting and
+ * recreating one would replace the register its anchor names, so every
+ * mutation but an extension needs the full role.
+ */
+static __always_inline bool shirudo_tpm_nvpcr(__u32 index)
+{
+ return index >= 0x01d10200u && index <= 0x01d105ffu;
+}
+
+static __always_inline enum shirudo_tpm_access
+shirudo_tpm_nv(__u32 index, bool extend)
+{
+ /* 0x01818e00 is Shirudo's measurement register (NV_INDEX). */
+ if (index == 0x01818e00u)
+ return SHIRUDO_TPM_RUNTIME;
+ if (shirudo_tpm_nvpcr(index) && !extend)
+ return SHIRUDO_TPM_RUNTIME;
+ return SHIRUDO_TPM_PUBLIC;
+}
+
+static __always_inline enum shirudo_tpm_access
+shirudo_tpm_access(const __u8 *command, __u32 length, __u32 config_pcr)
+{
+ __u32 tag, declared, code, target, offset, size;
+
+ if (!command || length < 10 || length > 4096 ||
+ shirudo_tpm_word(command, length, 0, 2, &tag) ||
+ (tag != 0x8001 && tag != 0x8002) ||
+ shirudo_tpm_word(command, length, 2, 4, &declared) || declared != length ||
+ shirudo_tpm_word(command, length, 6, 4, &code))
+ return SHIRUDO_TPM_MALFORMED;
+ switch (code) {
+ case 0x00000121u: /* HierarchyControl */
+ case 0x00000124u: /* ChangeEPS */
+ case 0x00000125u: /* ChangePPS */
+ case 0x00000126u: /* Clear */
+ case 0x00000127u: /* ClearControl */
+ case 0x00000128u: /* ClockSet */
+ case 0x00000129u: /* HierarchyChangeAuth */
+ case 0x0000012bu: /* PCR_Allocate */
+ case 0x0000012cu: /* PCR_SetAuthPolicy */
+ case 0x0000012du: /* PP_Commands */
+ case 0x0000012eu: /* SetPrimaryPolicy */
+ case 0x0000012fu: /* FieldUpgradeStart */
+ case 0x00000130u: /* ClockRateAdjust */
+ case 0x00000132u: /* NV_GlobalWriteLock */
+ case 0x00000139u: /* DictionaryAttackLockReset */
+ case 0x0000013au: /* DictionaryAttackParameters */
+ case 0x0000013fu: /* SetAlgorithmSet */
+ case 0x00000140u: /* SetCommandCodeAuditStatus */
+ case 0x00000141u: /* FieldUpgradeData */
+ case 0x00000145u: /* Shutdown */
+ case 0x00000198u: /* ACT_SetTimeout */
+ return SHIRUDO_TPM_RUNTIME;
+ case 0x0000013cu: /* PCR_Event */
+ case 0x0000013du: /* PCR_Reset */
+ case 0x00000182u: /* PCR_Extend */
+ case 0x00000183u: /* PCR_SetAuthValue */
+ case 0x00000185u: /* EventSequenceComplete */
+ if (shirudo_tpm_word(command, length, 10, 4, &target))
+ return SHIRUDO_TPM_MALFORMED;
+ if (target == config_pcr)
+ return SHIRUDO_TPM_RUNTIME;
+ /*
+ * Every other PCR belongs to the platform: systemd's
+ * pcrmachine and pcrfs extend PCR 15 as root, for example.
+ */
+ return SHIRUDO_TPM_PUBLIC;
+ case 0x0000011fu: /* NV_UndefineSpaceSpecial */
+ case 0x0000013bu: /* NV_ChangeAuth */
+ if (shirudo_tpm_word(command, length, 10, 4, &target))
+ return SHIRUDO_TPM_MALFORMED;
+ return shirudo_tpm_nv(target, false);
+ case 0x00000122u: /* NV_UndefineSpace */
+ case 0x00000134u: /* NV_Increment */
+ case 0x00000135u: /* NV_SetBits */
+ case 0x00000136u: /* NV_Extend */
+ case 0x00000137u: /* NV_Write */
+ case 0x00000138u: /* NV_WriteLock */
+ case 0x0000014fu: /* NV_ReadLock */
+ if (shirudo_tpm_word(command, length, 14, 4, &target))
+ return SHIRUDO_TPM_MALFORMED;
+ return shirudo_tpm_nv(target, code == 0x00000136u);
+ case 0x0000012au: /* NV_DefineSpace */
+ offset = 14;
+ if (tag == 0x8002) {
+ if (shirudo_tpm_word(command, length, offset, 4, &size) ||
+ size > length - 18)
+ return SHIRUDO_TPM_MALFORMED;
+ offset = 18 + size;
+ }
+ if (shirudo_tpm_word(command, length, offset, 2, &size) ||
+ size > length - offset - 2)
+ return SHIRUDO_TPM_MALFORMED;
+ offset += 2 + size;
+ if (shirudo_tpm_word(command, length, offset, 2, &size) ||
+ size < 14 || size != length - offset - 2 ||
+ shirudo_tpm_word(command, length, offset + 2, 4, &target))
+ return SHIRUDO_TPM_MALFORMED;
+ return shirudo_tpm_nv(target, false);
+ case 0x00000120u: /* EvictControl */
+ case 0x00000131u: /* CreatePrimary */
+ case 0x00000133u: /* GetCommandAuditDigest */
+ case 0x0000013eu: /* SequenceComplete */
+ case 0x00000142u: /* IncrementalSelfTest */
+ case 0x00000143u: /* SelfTest */
+ case 0x00000144u: /* Startup: already initialized before guards attach. */
+ case 0x00000146u: /* StirRandom */
+ case 0x00000147u: /* ActivateCredential */
+ case 0x00000148u: /* Certify */
+ case 0x00000149u: /* PolicyNV */
+ case 0x0000014au: /* CertifyCreation */
+ case 0x0000014bu: /* Duplicate */
+ case 0x0000014cu: /* GetTime */
+ case 0x0000014du: /* GetSessionAuditDigest */
+ case 0x0000014eu: /* NV_Read */
+ case 0x00000150u: /* ObjectChangeAuth */
+ case 0x00000151u: /* PolicySecret */
+ case 0x00000152u: /* Rewrap */
+ case 0x00000153u: /* Create */
+ case 0x00000154u: /* ECDH_ZGen */
+ case 0x00000155u: /* MAC */
+ case 0x00000156u: /* Import */
+ case 0x00000157u: /* Load */
+ case 0x00000158u: /* Quote */
+ case 0x00000159u: /* RSA_Decrypt */
+ case 0x0000015bu: /* MAC_Start */
+ case 0x0000015cu: /* SequenceUpdate */
+ case 0x0000015du: /* Sign */
+ case 0x0000015eu: /* Unseal */
+ case 0x00000160u: /* PolicySigned */
+ case 0x00000161u: /* ContextLoad */
+ case 0x00000162u: /* ContextSave */
+ case 0x00000163u: /* ECDH_KeyGen */
+ case 0x00000164u: /* EncryptDecrypt */
+ case 0x00000165u: /* FlushContext */
+ case 0x00000167u: /* LoadExternal */
+ case 0x00000168u: /* MakeCredential */
+ case 0x00000169u: /* NV_ReadPublic */
+ case 0x0000016au: /* PolicyAuthorize */
+ case 0x0000016bu: /* PolicyAuthValue */
+ case 0x0000016cu: /* PolicyCommandCode */
+ case 0x0000016du: /* PolicyCounterTimer */
+ case 0x0000016eu: /* PolicyCpHash */
+ case 0x0000016fu: /* PolicyLocality */
+ case 0x00000170u: /* PolicyNameHash */
+ case 0x00000171u: /* PolicyOR */
+ case 0x00000172u: /* PolicyTicket */
+ case 0x00000173u: /* ReadPublic */
+ case 0x00000174u: /* RSA_Encrypt */
+ case 0x00000176u: /* StartAuthSession */
+ case 0x00000177u: /* VerifySignature */
+ case 0x00000178u: /* ECC_Parameters */
+ case 0x00000179u: /* FirmwareRead */
+ case 0x0000017au: /* GetCapability */
+ case 0x0000017bu: /* GetRandom */
+ case 0x0000017cu: /* GetTestResult */
+ case 0x0000017du: /* Hash */
+ case 0x0000017eu: /* PCR_Read */
+ case 0x0000017fu: /* PolicyPCR */
+ case 0x00000180u: /* PolicyRestart */
+ case 0x00000181u: /* ReadClock */
+ case 0x00000184u: /* NV_Certify */
+ case 0x00000186u: /* HashSequenceStart */
+ case 0x00000187u: /* PolicyPhysicalPresence */
+ case 0x00000188u: /* PolicyDuplicationSelect */
+ case 0x00000189u: /* PolicyGetDigest */
+ case 0x0000018au: /* TestParms */
+ case 0x0000018bu: /* Commit */
+ case 0x0000018cu: /* PolicyPassword */
+ case 0x0000018du: /* ZGen_2Phase */
+ case 0x0000018eu: /* EC_Ephemeral */
+ case 0x0000018fu: /* PolicyNvWritten */
+ case 0x00000190u: /* PolicyTemplate */
+ case 0x00000191u: /* CreateLoaded */
+ case 0x00000192u: /* PolicyAuthorizeNV */
+ case 0x00000193u: /* EncryptDecrypt2 */
+ case 0x00000194u: /* AC_GetCapability */
+ case 0x00000195u: /* AC_Send */
+ case 0x00000196u: /* Policy_AC_SendSelect */
+ case 0x00000197u: /* CertifyX509 */
+ return SHIRUDO_TPM_PUBLIC;
+ default:
+ /* Unknown/vendor commands need full runtime authority. */
+ return SHIRUDO_TPM_RUNTIME;
+ }
+}
+
+#endif /* SHIRUDO_TPM_COMMAND_H */
diff --git a/testing/fixtures/keepalive/node-a-1.0.0.json b/testing/fixtures/keepalive/node-a-1.0.0.json
index 55d9b479..9cf0aba2 100644
--- a/testing/fixtures/keepalive/node-a-1.0.0.json
+++ b/testing/fixtures/keepalive/node-a-1.0.0.json
@@ -1 +1 @@
-{"schema":"shirudo.keepalive/1","boot_id":"168d20a1-5011-4e1b-9924-d8b73c85aa4e","version_id":"d6d918ad22ff597579e6678bef75adca84d30f9661e0b7bbdbf534eebc138c1f","config_root":"1d8465c5b17838303fee92b3905420d294d2c22c576a0bdef0f69f190ed22807","kernel_release":"7.4.2","image_id":"fleet-os","image_version":"2026.11.1","image_root":"a3c3f1b0e4c2d7f09e3b6b2a8b1d5e7c4f6a9d0b2c8e1f3a5b7d9c0e2f4a6b8c","verdict":"ok","cond":5461,"flags":0,"tamper":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"integrity":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"tree_id":"fleet-base","generation":1,"base_seq":0,"last_seq":1,"base_root":"0000000000000000000000000000000000000000000000000000000000000000","projection_root":"04f83540c1727aefcf3c53449a99594c8fd1cc15e1466dbdbf3168cc8f9dc136","mask":"QA==","set_sha256":"6c9e113d02cd14646f617d7bba4a092b91bc3802dfdaae50e2fef7a01e0580aa","count":1,"not_ok":0}
\ No newline at end of file
+{"schema":"shirudo.keepalive/1","boot_id":"168d20a1-5011-4e1b-9924-d8b73c85aa4e","version_id":"d6d918ad22ff597579e6678bef75adca84d30f9661e0b7bbdbf534eebc138c1f","config_root":"1d8465c5b17838303fee92b3905420d294d2c22c576a0bdef0f69f190ed22807","kernel_release":"7.4.2","image_id":"fleet-os","image_version":"2026.11.1","image_root":"a3c3f1b0e4c2d7f09e3b6b2a8b1d5e7c4f6a9d0b2c8e1f3a5b7d9c0e2f4a6b8c","verdict":"ok","cond":5461,"flags":0,"tamper":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"integrity":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"tree_id":"fleet-base","generation":1,"base_seq":0,"last_seq":1,"base_root":"0000000000000000000000000000000000000000000000000000000000000000","projection_root":"04f83540c1727aefcf3c53449a99594c8fd1cc15e1466dbdbf3168cc8f9dc136","mask":"QA==","set_sha256":"6c9e113d02cd14646f617d7bba4a092b91bc3802dfdaae50e2fef7a01e0580aa","count":1,"not_ok":0}
\ No newline at end of file
diff --git a/testing/fixtures/keepalive/node-a-1.1.0.json b/testing/fixtures/keepalive/node-a-1.1.0.json
index 2356f2af..e45d188e 100644
--- a/testing/fixtures/keepalive/node-a-1.1.0.json
+++ b/testing/fixtures/keepalive/node-a-1.1.0.json
@@ -1 +1 @@
-{"schema":"shirudo.keepalive/1","boot_id":"168d20a1-5011-4e1b-9924-d8b73c85aa4e","version_id":"d6d918ad22ff597579e6678bef75adca84d30f9661e0b7bbdbf534eebc138c1f","config_root":"1d8465c5b17838303fee92b3905420d294d2c22c576a0bdef0f69f190ed22807","kernel_release":"7.4.2","image_id":"fleet-os","image_version":"2026.11.1","image_root":"a3c3f1b0e4c2d7f09e3b6b2a8b1d5e7c4f6a9d0b2c8e1f3a5b7d9c0e2f4a6b8c","verdict":"ok","cond":5461,"flags":0,"tamper":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"integrity":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"tree_id":"fleet-base","generation":3,"base_seq":0,"last_seq":3,"base_root":"0000000000000000000000000000000000000000000000000000000000000000","projection_root":"154522480ff8884daa95589e80f26f20248bbf9c192dfbb3cee04e03b4f136a1","mask":"VA==","set_sha256":"74e5bd2c665109f6d8f926af5476c266ad70ab07293ff13b1a13d0b89aa5c1bf","count":1,"not_ok":0}
\ No newline at end of file
+{"schema":"shirudo.keepalive/1","boot_id":"168d20a1-5011-4e1b-9924-d8b73c85aa4e","version_id":"d6d918ad22ff597579e6678bef75adca84d30f9661e0b7bbdbf534eebc138c1f","config_root":"1d8465c5b17838303fee92b3905420d294d2c22c576a0bdef0f69f190ed22807","kernel_release":"7.4.2","image_id":"fleet-os","image_version":"2026.11.1","image_root":"a3c3f1b0e4c2d7f09e3b6b2a8b1d5e7c4f6a9d0b2c8e1f3a5b7d9c0e2f4a6b8c","verdict":"ok","cond":5461,"flags":0,"tamper":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"integrity":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"tree_id":"fleet-base","generation":3,"base_seq":0,"last_seq":3,"base_root":"0000000000000000000000000000000000000000000000000000000000000000","projection_root":"154522480ff8884daa95589e80f26f20248bbf9c192dfbb3cee04e03b4f136a1","mask":"VA==","set_sha256":"74e5bd2c665109f6d8f926af5476c266ad70ab07293ff13b1a13d0b89aa5c1bf","count":1,"not_ok":0}
\ No newline at end of file
diff --git a/testing/fixtures/keepalive/node-b-1.0.0.json b/testing/fixtures/keepalive/node-b-1.0.0.json
index 030815a1..782c7cc8 100644
--- a/testing/fixtures/keepalive/node-b-1.0.0.json
+++ b/testing/fixtures/keepalive/node-b-1.0.0.json
@@ -1 +1 @@
-{"schema":"shirudo.keepalive/1","boot_id":"9a6f14ea-0cc2-45e1-8e23-7b887120cf54","version_id":"d6d918ad22ff597579e6678bef75adca84d30f9661e0b7bbdbf534eebc138c1f","config_root":"ff2cbeff5d0e9c41a7b36f28d14ce09b73a5182e6fc40d97b5e2a1683c0f7ff8","kernel_release":"7.4.2","image_id":"fleet-os","image_version":"2026.11.1","image_root":null,"verdict":"ok","cond":5461,"flags":0,"tamper":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"integrity":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"tree_id":"fleet-base","generation":1,"base_seq":0,"last_seq":1,"base_root":"0000000000000000000000000000000000000000000000000000000000000000","projection_root":"0000000000000000000000000000000000000000000000000000000000000000","mask":"gA==","set_sha256":"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855","count":0,"not_ok":0}
\ No newline at end of file
+{"schema":"shirudo.keepalive/1","boot_id":"9a6f14ea-0cc2-45e1-8e23-7b887120cf54","version_id":"d6d918ad22ff597579e6678bef75adca84d30f9661e0b7bbdbf534eebc138c1f","config_root":"ff2cbeff5d0e9c41a7b36f28d14ce09b73a5182e6fc40d97b5e2a1683c0f7ff8","kernel_release":"7.4.2","image_id":"fleet-os","image_version":"2026.11.1","image_root":null,"verdict":"ok","cond":5461,"flags":0,"tamper":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"integrity":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"tree_id":"fleet-base","generation":1,"base_seq":0,"last_seq":1,"base_root":"0000000000000000000000000000000000000000000000000000000000000000","projection_root":"0000000000000000000000000000000000000000000000000000000000000000","mask":"gA==","set_sha256":"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855","count":0,"not_ok":0}
\ No newline at end of file
diff --git a/testing/fixtures/keepalive/node-b-1.1.0.json b/testing/fixtures/keepalive/node-b-1.1.0.json
index a6c8b52a..a77fa9d6 100644
--- a/testing/fixtures/keepalive/node-b-1.1.0.json
+++ b/testing/fixtures/keepalive/node-b-1.1.0.json
@@ -1 +1 @@
-{"schema":"shirudo.keepalive/1","boot_id":"9a6f14ea-0cc2-45e1-8e23-7b887120cf54","version_id":"d6d918ad22ff597579e6678bef75adca84d30f9661e0b7bbdbf534eebc138c1f","config_root":"ff2cbeff5d0e9c41a7b36f28d14ce09b73a5182e6fc40d97b5e2a1683c0f7ff8","kernel_release":"7.4.2","image_id":"fleet-os","image_version":"2026.11.1","image_root":null,"verdict":"ok","cond":5461,"flags":0,"tamper":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"integrity":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"tree_id":"fleet-base","generation":3,"base_seq":0,"last_seq":3,"base_root":"0000000000000000000000000000000000000000000000000000000000000000","projection_root":"0000000000000000000000000000000000000000000000000000000000000000","mask":"qA==","set_sha256":"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855","count":0,"not_ok":0}
\ No newline at end of file
+{"schema":"shirudo.keepalive/1","boot_id":"9a6f14ea-0cc2-45e1-8e23-7b887120cf54","version_id":"d6d918ad22ff597579e6678bef75adca84d30f9661e0b7bbdbf534eebc138c1f","config_root":"ff2cbeff5d0e9c41a7b36f28d14ce09b73a5182e6fc40d97b5e2a1683c0f7ff8","kernel_release":"7.4.2","image_id":"fleet-os","image_version":"2026.11.1","image_root":null,"verdict":"ok","cond":5461,"flags":0,"tamper":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"integrity":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"tree_id":"fleet-base","generation":3,"base_seq":0,"last_seq":3,"base_root":"0000000000000000000000000000000000000000000000000000000000000000","projection_root":"0000000000000000000000000000000000000000000000000000000000000000","mask":"qA==","set_sha256":"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855","count":0,"not_ok":0}
\ No newline at end of file
diff --git a/testing/fixtures/keepalive/ops-16.json b/testing/fixtures/keepalive/ops-16.json
index 9209c584..b92fb62b 100644
--- a/testing/fixtures/keepalive/ops-16.json
+++ b/testing/fixtures/keepalive/ops-16.json
@@ -1 +1 @@
-{"schema":"shirudo.keepalive/1","boot_id":"d5140906-4eab-4983-a62c-29e49d449ea3","version_id":"d6d918ad22ff597579e6678bef75adca84d30f9661e0b7bbdbf534eebc138c1f","config_root":"1fbdff17ad8d50404772901df54d5aa2c698eddbb413e286fc654f80931c688a","kernel_release":"7.4.0-shirudo","image_id":"fleet-os","image_version":"2026.11.1","image_root":"a3c3f1b0e4c2d7f09e3b6b2a8b1d5e7c4f6a9d0b2c8e1f3a5b7d9c0e2f4a6b8c","verdict":"ok","cond":5461,"flags":0,"tamper":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"integrity":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"tree_id":"fleet-base","generation":42,"base_seq":0,"last_seq":12,"base_root":"0000000000000000000000000000000000000000000000000000000000000000","projection_root":"f59301708fc8e150c5d2abb1009b4f13fc0dcc1304b708f77dc14b1541679e28","mask":"WdlZAA==","set_sha256":"ac1af1d44b5c1fe3f616384db421138aa4d296595797b5864908a89276e17e6d","count":7,"not_ok":0}
\ No newline at end of file
+{"schema":"shirudo.keepalive/1","boot_id":"d5140906-4eab-4983-a62c-29e49d449ea3","version_id":"d6d918ad22ff597579e6678bef75adca84d30f9661e0b7bbdbf534eebc138c1f","config_root":"1fbdff17ad8d50404772901df54d5aa2c698eddbb413e286fc654f80931c688a","kernel_release":"7.4.0-shirudo","image_id":"fleet-os","image_version":"2026.11.1","image_root":"a3c3f1b0e4c2d7f09e3b6b2a8b1d5e7c4f6a9d0b2c8e1f3a5b7d9c0e2f4a6b8c","verdict":"ok","cond":5461,"flags":0,"tamper":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"integrity":[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],"tree_id":"fleet-base","generation":42,"base_seq":0,"last_seq":12,"base_root":"0000000000000000000000000000000000000000000000000000000000000000","projection_root":"f59301708fc8e150c5d2abb1009b4f13fc0dcc1304b708f77dc14b1541679e28","mask":"WdlZAA==","set_sha256":"ac1af1d44b5c1fe3f616384db421138aa4d296595797b5864908a89276e17e6d","count":7,"not_ok":0}
\ No newline at end of file
diff --git a/testing/fixtures/keepalive/quotes.tsv b/testing/fixtures/keepalive/quotes.tsv
index 263883cb..f6d87831 100644
--- a/testing/fixtures/keepalive/quotes.tsv
+++ b/testing/fixtures/keepalive/quotes.tsv
@@ -1,4 +1,4 @@
-node-a-1.0.0.json /1RDR4AYACIACzzRy0Vu4QrA2QYIAEG+suvM8y0yKdNz0mEYxxwsV7JhACBGoxowhIt2CnR3mlHNkt5dMhw/XJ9hQDbR+/zFux3/mwAAAAAAAAAIAAAAAAAAAAABIBkQIwAWNjYAAAABAAsDAAAAACDjsMRCmPwcFJr79MiZb7kkJ65B5GSbk0yklZkbeFK4VQ== ABgACwAgOsqFz+hIGty6pVF+/6bcAEeU/BgyqkKCdQuZwTRPMVoAIOQbyQfNRFynftUoFq3mdmn8p8uoC8XhTXsZX8BKcjYr ACMACwAFAHIAAAAQABgACwADABAAIIX85Uj/SFzk5dE+P7jISlhFEgTkQgD5WJOhOb8ayvhXACBzopZ76SQHVgqnhP8tiHB6O+rzISw+/6k3eeDT/UtQNA== 46a31a30848b760a74779a51cd92de5d321c3f5c9f614036d1fbfcc5bb1dff9b
-node-a-1.1.0.json /1RDR4AYACIACzzRy0Vu4QrA2QYIAEG+suvM8y0yKdNz0mEYxxwsV7JhACB+8a36vsajTkF6VdKZ4rIDChYu23UCWpNELCY1TDaMIgAAAAAAAAAbAAAAAAAAAAABIBkQIwAWNjYAAAABAAsDAAAAACDjsMRCmPwcFJr79MiZb7kkJ65B5GSbk0yklZkbeFK4VQ== ABgACwAgENqr3I8/b72G/uLE46oL9Vd6fp12xo/T3IZYnPp88NkAIAqDLfPPAiS9JnBrPDwzXSP48cfQxRmxvC+vmE0IE6Dg ACMACwAFAHIAAAAQABgACwADABAAIIX85Uj/SFzk5dE+P7jISlhFEgTkQgD5WJOhOb8ayvhXACBzopZ76SQHVgqnhP8tiHB6O+rzISw+/6k3eeDT/UtQNA== 7ef1adfabec6a34e417a55d299e2b2030a162edb75025a93442c26354c368c22
-node-b-1.0.0.json /1RDR4AYACIACzITVKDjpRV7SpQyL9Joyb8851Q9c6JkQYxGUaHW91SUACBl4pR+5PV9v2gAwwTPQiNCXCFFaNE6/qHwLQGjgtpZ6AAAAAAAAAAJAAAAAAAAAAABIBkQIwAWNjYAAAABAAsDAAAAACDjsMRCmPwcFJr79MiZb7kkJ65B5GSbk0yklZkbeFK4VQ== ABgACwAgy354AaCHOAs/ej7UQE+mzJprxHzfFU558ny3FFILeBoAINegZjzzEqwJlNDJHJvuaaQ5c5gIZS7Eins/k9aPjnoj ACMACwAFAHIAAAAQABgACwADABAAIHWuL1VjHRbjt8bd2H9s/Rn8iEB7E/DZyW6DPuebgp5HACCx9U/+/I/55mBuc4Sh5bhT8uVKrFv3qiW+GmLY1dDliA== 65e2947ee4f57dbf6800c304cf4223425c214568d13afea1f02d01a382da59e8
-node-b-1.1.0.json /1RDR4AYACIACzITVKDjpRV7SpQyL9Joyb8851Q9c6JkQYxGUaHW91SUACDyFnDjslblAbFweN/6U8fHEItWTr1VE6gDPlP2EjizpgAAAAAAAAAbAAAAAAAAAAABIBkQIwAWNjYAAAABAAsDAAAAACDjsMRCmPwcFJr79MiZb7kkJ65B5GSbk0yklZkbeFK4VQ== ABgACwAg7m6jRDU0D0bzepqJ1fD8rc85Ks0JvY+npL8QwPy+R7IAIL5Oi9KGygqH/DZGqngGWdqcZRfbeBVfpBB9pUl1HQGi ACMACwAFAHIAAAAQABgACwADABAAIHWuL1VjHRbjt8bd2H9s/Rn8iEB7E/DZyW6DPuebgp5HACCx9U/+/I/55mBuc4Sh5bhT8uVKrFv3qiW+GmLY1dDliA== f21670e3b256e501b17078dffa53c7c7108b564ebd5513a8033e53f61238b3a6
+node-a-1.0.0.json /1RDR4AYACIACzjFnHptn39DrBja+klXt5araBa1ntaU9m7QUmdvYzBAACDnx7bryIjH7zvbCoI7mGaYMDmtyXYCiTNFnzLU2uGqxwAAAAAAAAAHAAAAAAAAAAABICQBJQASAAAAAAABAAsDAAAAACDjsMRCmPwcFJr79MiZb7kkJ65B5GSbk0yklZkbeFK4VQ== ABgACwAgDljppxUwnP7AGbywlcaLTuLlcO8pLcwNDhcY6mukd4wAIA5PR/PK3Xhw5ULFKheYU1bVFNT609CFAxtSEudeiGtr ACMACwAFAHIAAAAQABgACwADABAAIF46L7wdlHcbQ9P8BuOJYaiMIRoRSNd//H6uGpCFBuFvACC1DxZo2qb57xyTqhxtCbl4x3PUWooF8WkwmaTSjUktYA== e7c7b6ebc888c7ef3bdb0a823b9866983039adc976028933459f32d4dae1aac7
+node-a-1.1.0.json /1RDR4AYACIACzjFnHptn39DrBja+klXt5araBa1ntaU9m7QUmdvYzBAACCOTCe8dR1WrG2DWk/AjbyS3pKFoY/jdJDpqrXXkH4g3QAAAAAAAAAYAAAAAAAAAAABICQBJQASAAAAAAABAAsDAAAAACDjsMRCmPwcFJr79MiZb7kkJ65B5GSbk0yklZkbeFK4VQ== ABgACwAgaMENae2nk8mhIi1stOWH6D+85Pv49egfGNuy+UdHBKEAIJZiMuD0dBMTeDoXNJXda6pbmKFl42y6tbAylVEbW1FC ACMACwAFAHIAAAAQABgACwADABAAIF46L7wdlHcbQ9P8BuOJYaiMIRoRSNd//H6uGpCFBuFvACC1DxZo2qb57xyTqhxtCbl4x3PUWooF8WkwmaTSjUktYA== 8e4c27bc751d56ac6d835a4fc08dbc92de9285a18fe37490e9aab5d7907e20dd
+node-b-1.0.0.json /1RDR4AYACIACzf11bAMwtpdQf+XYkEaJHlio7BLAg3D1bTrxg4ZWiTHACBnZYSWIyXzdsWpEXUxYaVVnLs5EpSHcuGuech/pSbhpQAAAAAAAAAHAAAAAAAAAAABICQBJQASAAAAAAABAAsDAAAAACDjsMRCmPwcFJr79MiZb7kkJ65B5GSbk0yklZkbeFK4VQ== ABgACwAgg2MIB/i6ho5PeLq21lQQdsmH+ZFW0g0Lv+RNPEck8gEAIKre+6pL/UtAAD1ZYITZSCrFF+K1GRBytcrodvHYcqM+ ACMACwAFAHIAAAAQABgACwADABAAIF1lI7qzX7mwxKnFhJrse3XdMwin/TnVFD5n6frpU4y9ACCnBO085DFe6g6IQudpedpl/pRX/uuUqw67gC5HS4PRrg== 676584962325f376c5a911753161a5559cbb3912948772e1ae79c87fa526e1a5
+node-b-1.1.0.json /1RDR4AYACIACzf11bAMwtpdQf+XYkEaJHlio7BLAg3D1bTrxg4ZWiTHACDJ0bfQaHv4JohIdCzK1LF4Ua7pxuNyHMmMKWGDpezahAAAAAAAAAAXAAAAAAAAAAABICQBJQASAAAAAAABAAsDAAAAACDjsMRCmPwcFJr79MiZb7kkJ65B5GSbk0yklZkbeFK4VQ== ABgACwAg++gjuPyV2nmkWYcsLLwFt2vkJjAflEMDOlBg+4sAiGcAIG1sjRgW7qCblJOAMaBx4cybs4iWy/Yo7AjYXwWom2K4 ACMACwAFAHIAAAAQABgACwADABAAIF1lI7qzX7mwxKnFhJrse3XdMwin/TnVFD5n6frpU4y9ACCnBO085DFe6g6IQudpedpl/pRX/uuUqw67gC5HS4PRrg== c9d1b7d0687bf8268848742ccad4b17851aee9c6e3721cc98c296183a5ecda84
diff --git a/testing/fixtures/keepalive/recompute.py b/testing/fixtures/keepalive/recompute.py
index 3f198531..5237a6a8 100755
--- a/testing/fixtures/keepalive/recompute.py
+++ b/testing/fixtures/keepalive/recompute.py
@@ -24,7 +24,7 @@ BODY_KEYS = [
"base_root", "projection_root", "mask", "set_sha256", "count", "not_ok",
]
CANONICAL_KEYS = ["seq", "op", "id", "selector", "artifact"]
-TAMPER_COUNTERS = 42
+TAMPER_COUNTERS = 43
INTEGRITY_COUNTERS = 22
ALL_OK = 0x1555
@@ -52,9 +52,9 @@ MASKS = [
# The body the example pages print for node A after release 1.1.0: six
# conditions and no image keys.
-PAGE_BODY_LEN = 800
+PAGE_BODY_LEN = 802
PAGE_BODY_SHA256 = \
- "3a9fea87b58e250df58b7f336f6511a8b7c4a69752af3ccae3d76b2626bcbacd"
+ "2e2a4ae6919b10ab71ac0f11857dadca0eb1dcc2f6c280c0c70f1a72fbf5ce59"
PAGE_COND = 0x555
VERSION_ID = "d6d918ad22ff597579e6678bef75adca84d30f9661e0b7bbdbf534eebc138c1f"
diff --git a/testing/functional/tpm/t4004-config-attest.sh b/testing/functional/tpm/t4004-config-attest.sh
index b064fbba..916dd33a 100755
--- a/testing/functional/tpm/t4004-config-attest.sh
+++ b/testing/functional/tpm/t4004-config-attest.sh
@@ -115,7 +115,7 @@ test_expect_success 'without operator approval the report names its limit explic
--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 "direct TPM writer protection is deferred" "$WORK/unapproved"
+ grep -q "operation completion depends on trusted runtime guards" "$WORK/unapproved"
'
python3 - "$WORK/b.json" "$WORK" <<'PY'
diff --git a/testing/fuzz/corpus/tpm-command/get-capability b/testing/fuzz/corpus/tpm-command/get-capability
new file mode 100644
index 00000000..61886a51
Binary files /dev/null and b/testing/fuzz/corpus/tpm-command/get-capability differ
diff --git a/testing/fuzz/corpus/tpm-command/nv-define-register b/testing/fuzz/corpus/tpm-command/nv-define-register
new file mode 100644
index 00000000..45a50923
Binary files /dev/null and b/testing/fuzz/corpus/tpm-command/nv-define-register differ
diff --git a/testing/fuzz/corpus/tpm-command/nv-extend-register b/testing/fuzz/corpus/tpm-command/nv-extend-register
new file mode 100644
index 00000000..7eaa954a
Binary files /dev/null and b/testing/fuzz/corpus/tpm-command/nv-extend-register differ
diff --git a/testing/fuzz/corpus/tpm-command/nv-extend-systemd-nvpcr b/testing/fuzz/corpus/tpm-command/nv-extend-systemd-nvpcr
new file mode 100644
index 00000000..5f75a5b8
Binary files /dev/null and b/testing/fuzz/corpus/tpm-command/nv-extend-systemd-nvpcr differ
diff --git a/testing/fuzz/corpus/tpm-command/nv-write-systemd-nvpcr b/testing/fuzz/corpus/tpm-command/nv-write-systemd-nvpcr
new file mode 100644
index 00000000..089b8940
Binary files /dev/null and b/testing/fuzz/corpus/tpm-command/nv-write-systemd-nvpcr differ
diff --git a/testing/fuzz/corpus/tpm-command/pcr-extend-config b/testing/fuzz/corpus/tpm-command/pcr-extend-config
new file mode 100644
index 00000000..28a21a7c
Binary files /dev/null and b/testing/fuzz/corpus/tpm-command/pcr-extend-config differ
diff --git a/testing/fuzz/corpus/tpm-command/startup-clear b/testing/fuzz/corpus/tpm-command/startup-clear
new file mode 100644
index 00000000..359215ef
Binary files /dev/null and b/testing/fuzz/corpus/tpm-command/startup-clear differ
diff --git a/testing/fuzz/fuzz-tpm-command.c b/testing/fuzz/fuzz-tpm-command.c
new file mode 100644
index 00000000..60e7d998
--- /dev/null
+++ b/testing/fuzz/fuzz-tpm-command.c
@@ -0,0 +1,22 @@
+// SPDX-License-Identifier: BSD-2-Clause
+/* Copyright (c) 2026 Authors of shirudo */
+
+#include <stdbool.h>
+#include <string.h>
+#include "fuzz.h"
+
+#define SHIRUDO_TPM_COPY(out, in, size) (memcpy(out, in, size), 0)
+#include <shirudo/tpm_command.h>
+
+int LLVMFuzzerTestOneInput(const __u8 *data, size_t size)
+{
+ enum shirudo_tpm_access access;
+
+ if (size > 4096)
+ return 0;
+ access = shirudo_tpm_access(data, size, 13);
+ if (access == SHIRUDO_TPM_MALFORMED &&
+ shirudo_tpm_allowed(access, true))
+ __builtin_trap();
+ return 0;
+}
diff --git a/testing/helper/test-tpm-command.c b/testing/helper/test-tpm-command.c
new file mode 100644
index 00000000..046bf37a
--- /dev/null
+++ b/testing/helper/test-tpm-command.c
@@ -0,0 +1,173 @@
+// SPDX-License-Identifier: BSD-2-Clause
+/* Copyright (c) 2026 Authors of shirudo */
+
+#include <stdbool.h>
+#include <stdio.h>
+#include <string.h>
+#include <shirudo/misc.h>
+
+#define SHIRUDO_TPM_COPY(out, in, size) (memcpy(out, in, size), 0)
+#include <shirudo/tpm_command.h>
+
+static void put32(__u8 *out, __u32 value)
+{
+ out[0] = value >> 24;
+ out[1] = value >> 16;
+ out[2] = value >> 8;
+ out[3] = value;
+}
+
+static void packet(__u8 command[64], __u32 code, __u32 length)
+{
+ memset(command, 0, 64);
+ command[0] = 0x80;
+ command[1] = 1;
+ put32(command + 2, length);
+ put32(command + 6, code);
+}
+
+static int check(enum shirudo_tpm_access observed,
+ enum shirudo_tpm_access expected, const char *name)
+{
+ if (observed == expected)
+ return 0;
+ fprintf(stderr, "%s: access %d, expected %d\n", name, observed, expected);
+ return 1;
+}
+
+/* Only the Shirudo runtime may use a RUNTIME command; anyone a PUBLIC one. */
+static int check_runtime_only(enum shirudo_tpm_access access, const char *name)
+{
+ if (shirudo_tpm_allowed(access, false) || !shirudo_tpm_allowed(access, true)) {
+ fprintf(stderr, "%s: needs exactly the Shirudo runtime\n", name);
+ return 1;
+ }
+ return 0;
+}
+
+int main(void)
+{
+ static const __u32 nv_commands[] = {
+ 0x122, 0x134, 0x135, 0x136, 0x137, 0x138, 0x14f,
+ };
+ static const __u32 pcr_commands[] = { 0x13c, 0x13d, 0x182, 0x183, 0x185 };
+ enum shirudo_tpm_access expected, access;
+ __u8 command[64];
+ __u32 pcr;
+ size_t i;
+ int failures = 0;
+
+ for (i = 0; i < ARRAY_SIZE(nv_commands); i++) {
+ packet(command, nv_commands[i], 18);
+ put32(command + 10, 0x40000001);
+ /* Shirudo's measurement register: every mutation. */
+ put32(command + 14, 0x01818e00);
+ access = shirudo_tpm_access(command, 18, 13);
+ failures += check(access, SHIRUDO_TPM_RUNTIME, "register NV mutation");
+ failures += check_runtime_only(access, "register NV mutation");
+ put32(command + 14, 0x01500000);
+ failures += check(shirudo_tpm_access(command, 18, 13),
+ SHIRUDO_TPM_PUBLIC, "unrelated NV mutation");
+ /* systemd's NvPCRs: extensions stay public, nothing else does. */
+ expected = nv_commands[i] == 0x136 ? SHIRUDO_TPM_PUBLIC :
+ SHIRUDO_TPM_RUNTIME;
+ put32(command + 14, 0x01d10202);
+ access = shirudo_tpm_access(command, 18, 13);
+ failures += check(access, expected, "systemd NvPCR mutation");
+ if (nv_commands[i] != 0x136)
+ failures += check_runtime_only(access, "systemd NvPCR mutation");
+ put32(command + 14, 0x01d10200);
+ failures += check(shirudo_tpm_access(command, 18, 13), expected,
+ "first systemd NvPCR mutation");
+ put32(command + 14, 0x01d105ff);
+ failures += check(shirudo_tpm_access(command, 18, 13), expected,
+ "last UAPI.19 Linux NV mutation");
+ put32(command + 14, 0x01d10600);
+ failures += check(shirudo_tpm_access(command, 18, 13),
+ SHIRUDO_TPM_PUBLIC, "NV mutation past the Linux range");
+ put32(command + 14, 0x01d101ff);
+ failures += check(shirudo_tpm_access(command, 18, 13),
+ SHIRUDO_TPM_PUBLIC, "NV mutation before the Linux range");
+ }
+ for (i = 0; i < ARRAY_SIZE(pcr_commands); i++) {
+ packet(command, pcr_commands[i], 14);
+ put32(command + 10, 13);
+ access = shirudo_tpm_access(command, 14, 13);
+ failures += check(access, SHIRUDO_TPM_RUNTIME, "config PCR mutation");
+ failures += check_runtime_only(access, "config PCR mutation");
+ put32(command + 10, 15);
+ access = shirudo_tpm_access(command, 14, 13);
+ failures += check(access, SHIRUDO_TPM_PUBLIC,
+ "systemd machine and file system measurement");
+ if (!shirudo_tpm_allowed(access, false)) {
+ fprintf(stderr, "root without a role must extend PCR 15\n");
+ failures++;
+ }
+ for (pcr = 0; pcr < 24; pcr++) {
+ put32(command + 10, pcr);
+ expected = pcr == 13 ? SHIRUDO_TPM_RUNTIME : SHIRUDO_TPM_PUBLIC;
+ failures += check(shirudo_tpm_access(command, 14, 13),
+ expected, "PCR allocation");
+ }
+ put32(command + 10, 13);
+ failures += check(shirudo_tpm_access(command, 14, 16),
+ SHIRUDO_TPM_PUBLIC, "PCR 13 with another config PCR");
+ }
+ packet(command, 0x11f, 18);
+ put32(command + 10, 0x01818e00);
+ put32(command + 14, 0x4000000c);
+ failures += check(shirudo_tpm_access(command, 18, 13),
+ SHIRUDO_TPM_RUNTIME, "policy deletion names NV before platform");
+ put32(command + 10, 0x01d10202);
+ failures += check(shirudo_tpm_access(command, 18, 13),
+ SHIRUDO_TPM_RUNTIME, "systemd NvPCR deletion by policy");
+ packet(command, 0x13b, 14);
+ put32(command + 10, 0x01d10202);
+ failures += check(shirudo_tpm_access(command, 14, 13),
+ SHIRUDO_TPM_RUNTIME, "systemd NvPCR authorization change");
+ packet(command, 0x12a, 32);
+ put32(command + 10, 0x4000000c);
+ command[17] = 14;
+ put32(command + 18, 0x01818e00);
+ failures += check(shirudo_tpm_access(command, 32, 13),
+ SHIRUDO_TPM_RUNTIME, "NV definition without auth session");
+ put32(command + 18, 0x01d10202);
+ failures += check(shirudo_tpm_access(command, 32, 13),
+ SHIRUDO_TPM_RUNTIME, "systemd NvPCR redefinition");
+ packet(command, 0x12a, 45);
+ command[1] = 2;
+ put32(command + 10, 0x4000000c);
+ put32(command + 14, 9);
+ command[30] = 14;
+ put32(command + 31, 0x01818e00);
+ failures += check(shirudo_tpm_access(command, 45, 13),
+ SHIRUDO_TPM_RUNTIME, "NV definition with password session");
+ put32(command + 14, 4096);
+ failures += check(shirudo_tpm_access(command, 45, 13),
+ SHIRUDO_TPM_MALFORMED, "oversized authorization area");
+ packet(command, 0x126, 14);
+ failures += check(shirudo_tpm_access(command, 14, 13),
+ SHIRUDO_TPM_RUNTIME, "root cannot clear protected measurements");
+ packet(command, 0x198, 14);
+ failures += check(shirudo_tpm_access(command, 14, 13),
+ SHIRUDO_TPM_RUNTIME, "ACT timeout requires runtime authority");
+ packet(command, 0x17e, 10);
+ failures += check(shirudo_tpm_access(command, 10, 13),
+ SHIRUDO_TPM_PUBLIC, "PCR_Read remains public");
+ packet(command, 0x144, 12);
+ failures += check(shirudo_tpm_access(command, 12, 13),
+ SHIRUDO_TPM_PUBLIC, "systemd may probe an already initialized TPM");
+ failures += check(shirudo_tpm_access(command, 9, 13),
+ SHIRUDO_TPM_MALFORMED, "truncated header");
+ packet(command, 0x20000000, 10);
+ failures += check(shirudo_tpm_access(command, 10, 13),
+ SHIRUDO_TPM_RUNTIME, "unknown vendor command");
+ if (shirudo_tpm_allowed(SHIRUDO_TPM_MALFORMED, true) ||
+ shirudo_tpm_allowed(SHIRUDO_TPM_RUNTIME, false) ||
+ !shirudo_tpm_allowed(SHIRUDO_TPM_RUNTIME, true) ||
+ !shirudo_tpm_allowed(SHIRUDO_TPM_PUBLIC, false)) {
+ fprintf(stderr, "access classes were conflated\n");
+ failures++;
+ }
+ return failures ? 1 : 0;
+}
diff --git a/testing/t0057-tpm-command.sh b/testing/t0057-tpm-command.sh
new file mode 100755
index 00000000..fad7979e
--- /dev/null
+++ b/testing/t0057-tpm-command.sh
@@ -0,0 +1,10 @@
+#!/bin/sh
+# SPDX-License-Identifier: BSD-2-Clause
+# Copyright (c) 2026 Authors of shirudo
+
+cd "$(dirname "$0")"
+. ./test-lib.sh
+H=$(pwd)/helper/test-tpm-command
+[ -x "$H" ] || test_skip_all "test-tpm-command helper not built"
+test_expect_success 'TPM command routing separates root and Shirudo authority' '"$H"'
+test_done
diff --git a/testing/unit/keepalive.c b/testing/unit/keepalive.c
index 3e29a8e4..023acc35 100644
--- a/testing/unit/keepalive.c
+++ b/testing/unit/keepalive.c
@@ -602,6 +602,7 @@ static const char * const tamper_order[] = {
"SealPerf", "ExecTraced", "SealEntry", "PerfAttach", "PinEntry",
"SealCopyUp", "Kexec", "TpmExtend", "ObjGet", "SealSignal",
"SealCoreDump", "SealUprobe", "ExecShared", "XattrHandle", "SealRlimit",
+ "TpmWrite",
};
/* The same for enum integrity_point. */
@@ -617,10 +618,10 @@ static void tamper_counters_keep_their_places(void)
{
size_t i;
- ASSERT_EQ(ARRAY_SIZE(tamper_order), 42);
+ ASSERT_EQ(ARRAY_SIZE(tamper_order), 43);
ASSERT_EQ(TAMPER_MAX, ARRAY_SIZE(tamper_order));
EXPECT_EQ(TAMPER_LOAD_NOT_LOADER, 0);
- EXPECT_EQ(TAMPER_SEAL_RLIMIT, TAMPER_MAX - 1);
+ EXPECT_EQ(SHIRUDO_TAMPER_TPM_WRITE, TAMPER_MAX - 1);
for (i = 0; i < ARRAY_SIZE(tamper_order); i++)
EXPECT_STREQ(tamper_name(i), tamper_order[i]);
}
@@ -657,7 +658,7 @@ static void body_lists_the_counters_in_enum_order(void)
in.integrity = integrity;
expect_member(&in, ",\"tamper\":[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,"
"16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,"
- "34,35,36,18446744073709551615,38,39,40,41,42],"
+ "34,35,36,18446744073709551615,38,39,40,41,42,43],"
"\"integrity\":[100,101,102,103,104,105,106,107,108,109,"
"110,111,112,113,114,115,116,117,118,"
"18446744073709551615,120,121],\"tree_id\":");
@@ -784,7 +785,7 @@ static void body_of_the_largest_values_fits(void)
in.integrity = integrity;
ASSERT_EQ(keepalive_emit(&in, body, sizeof(body), &whole), 0);
- EXPECT_EQ(whole, 3879);
+ EXPECT_EQ(whole, 3900);
EXPECT_LT(whole, KEEPALIVE_BODY_MAX);
EXPECT_EQ(keepalive_emit(&in, body, whole, &len), -ENOSPC);
EXPECT_EQ(keepalive_emit(&in, body, whole + 1, &len), 0);
diff --git a/testing/unit/kernel_abi.c b/testing/unit/kernel_abi.c
index 198e69a7..7f7a6551 100644
--- a/testing/unit/kernel_abi.c
+++ b/testing/unit/kernel_abi.c
@@ -34,6 +34,7 @@ enum fixture {
KEYRING_TYPE_WIDTH,
NO_VERDICT,
VERDICT_SIGNED,
+ NO_TPM_COMMAND,
TRAILING_DRIFT,
};
@@ -132,6 +133,13 @@ static struct btf *make_fixture(enum fixture fixture)
if (fixture == TRAILING_DRIFT &&
btf__add_field(btf, "future_aux_field", u32, 64, 0) < 0)
goto err;
+ if (fixture != NO_TPM_COMMAND) {
+ ret = btf__add_func_proto(btf, s32);
+ if (ret < 0 ||
+ btf__add_func(btf, "bpf_lsm_tpm_command", BTF_FUNC_GLOBAL,
+ ret) < 0)
+ goto err;
+ }
return btf;
err:
@@ -399,7 +407,13 @@ static void lsm_hooks_need_btf(void)
EXPECT_TRUE(strstr(detail, "kernel BTF is unavailable"));
}
+static void needs_tpm_command(void)
+{
+ check(NO_TPM_COMMAND, 0, "tpm_command LSM hook is missing");
+}
+
static const struct unit_case cases[] = {
+ UNIT_CASE(needs_tpm_command),
UNIT_CASE(accepts_the_required_prefix),
UNIT_CASE(accepts_fields_past_the_prefix),
UNIT_CASE(needs_struct_bpf_map),
diff --git a/util/attest.c b/util/attest.c
index 24126d30..6021029a 100644
--- a/util/attest.c
+++ b/util/attest.c
@@ -1153,7 +1153,7 @@ static void verify_config(struct verify *v)
"--expect-config-root with --expect-config-pcr");
if (v->config.present)
note(rep, "config records a selection; "
- "direct TPM writer protection is deferred");
+ "operation completion depends on trusted runtime guards");
}
static int register_written_name(struct verify *v, __u8 name[TPM_NAME_LEN])
diff --git a/util/identity.h b/util/identity.h
index 549f489e..6a5bc264 100644
--- a/util/identity.h
+++ b/util/identity.h
@@ -34,6 +34,7 @@ struct identity {
__u32 n_dm_verity_keys;
__s32 dm_verity_keys[IDENTITY_KEYS_MAX];
__u32 nv_index;
+ __u32 config_pcr;
};
#define TASK_TRUSTED 1
@@ -72,7 +73,7 @@ struct task_policy {
BUILD_BUG_ON(sizeof(struct device_authority) != 48);
BUILD_BUG_ON(sizeof(struct task_authority) != 8);
-BUILD_BUG_ON(sizeof(struct identity) != 644);
+BUILD_BUG_ON(sizeof(struct identity) != 648);
BUILD_BUG_ON(sizeof(struct task_policy) != 16);
/* The bpffs mount init made, which the unmount guard keeps mounted. */
diff --git a/util/image_runtime.c b/util/image_runtime.c
index f8991d8f..4664f312 100644
--- a/util/image_runtime.c
+++ b/util/image_runtime.c
@@ -1241,3 +1241,8 @@ int image_stage_cancel(void)
ret = current_config();
return ret ? ret : config_update_clear_staged(&image.update);
}
+
+__u32 shirudo_image_config_pcr(void)
+{
+ return image.bootstrap.pcr;
+}
diff --git a/util/image_runtime.h b/util/image_runtime.h
index 905e9bf2..e1918797 100644
--- a/util/image_runtime.h
+++ b/util/image_runtime.h
@@ -34,4 +34,6 @@ int image_status(bool json);
*/
int image_config_state(__u8 root[32]);
+__u32 shirudo_image_config_pcr(void);
+
#endif /* SHIRUDO_IMAGE_RUNTIME_H */
diff --git a/util/kernel_abi.c b/util/kernel_abi.c
index 0c561d54..0b8ed539 100644
--- a/util/kernel_abi.c
+++ b/util/kernel_abi.c
@@ -193,6 +193,9 @@ int kernel_abi_validate_btf(const struct btf *btf,
if (!verdict || !is_unsigned_int(member_type, 1))
return abi_fail(detail, detail_sz,
"struct bpf_prog_aux.sig.verdict must have type u8");
+ if (btf__find_by_name_kind(btf, "bpf_lsm_tpm_command", BTF_KIND_FUNC) < 0)
+ return abi_fail(detail, detail_sz,
+ "tpm_command LSM hook is missing; boot a Shirudo-patched kernel");
return 0;
}
diff --git a/util/tamper.c b/util/tamper.c
index 2742d03c..782f89b0 100644
--- a/util/tamper.c
+++ b/util/tamper.c
@@ -104,6 +104,8 @@ static const struct {
"XFS attribute change by file handle, which passes no xattr hook" },
[TAMPER_SEAL_RLIMIT] = { "SealRlimit",
"resource limit of a shirudo task changed by another task" },
+ [SHIRUDO_TAMPER_TPM_WRITE] = { "TpmWrite",
+ "protected TPM mutation by an unauthorized task" },
};
const char *tamper_name(enum tamper_point point)