eBPF-based security platform
tpm: authenticate exchanges with the enrolled TPM
Leonard Cohnen7e62a0ad3214
diff --git a/Documentation/concepts/background/tpm.rst b/Documentation/concepts/background/tpm.rstindex c628face..52258a52 100644--- a/Documentation/concepts/background/tpm.rst+++ b/Documentation/concepts/background/tpm.rst@@ -252,17 +252,25 @@ because a typical Linux system has no PCR that are not used already.Authorization and sessions---------------------------shirudo uses password authorizations for operations such as creating-TPM keys, defining or deleting the :term:`measurement register`, reading-it and signing. The owner authorization comes from ``tpm.owner_auth``;-register reads and signing use empty authorization values. A password-authorization carries that value in plaintext in the command.--Extending the register requires a policy session instead. This is-temporary state inside the TPM that shirudo updates with policy commands.-The TPM checks that the session's policy digest matches the register's-policy and that its restrictions hold when executing the extension.-shirudo uses these commands:+Each TPM connection creates the standard ECC :term:`endorsement key`+and uses it to salt SHA-256 HMAC and policy sessions. ``init`` freezes+the EK's Name in the :term:`identity map` during trusted initrd setup.+Later connections require that same Name. Initial EK creation uses the+empty endorsement authorization before a session is established and+trusts the TPM device.++The HMAC session authorizes key creation, definition and deletion of+the :term:`measurement register`, register reads and signing. The owner+authorization from ``tpm.owner_auth`` is used in HMAC authorization,+not sent as a plaintext password. Register reads and signing use empty+authorization values. Even reads that require no permission use an authenticated+session, so a proxy cannot substitute the returned values.++Extending the register starts a new authenticated policy session in the TPM.+shirudo uses policy commands in that session to satisfy the register's write+policy. The TPM checks that the session's policy digest matches the register's+policy and that its restrictions hold when executing the extension. shirudo+uses these commands:- ``TPM2_PolicyNvWritten`` requires an unwritten index for the firstextension, or an already written index for later extensions.@@ -279,16 +287,19 @@ shirudo uses these commands:``TPM2_NV_Extend``.Before submitting the extension, shirudo calls ``TPM2_PolicyGetDigest``-and compares the session's digest with the policy it computed in software.-The next section explains how these conditions protect the register.+through the authenticated session and compares the session's digest+with the policy it computed in software. The next section explains how+these conditions protect the register.Credential activation uses a separate policy session for the:term:`endorsement key`. shirudo satisfies that policy with``TPM2_PolicySecret``, using the empty endorsement-hierarchy authorization.-These sessions do not encrypt command parameters or authenticate command-responses. The TPM signatures on attestation :term:`evidence` are separate-from session authentication. `Limits`_ describes the transport risks.+Salted policy sessions authenticate successful extension replies. The+sessions do not encrypt command parameters. The TPM signatures on+attestation :term:`evidence` are separate from session authentication.+:doc:`/internals/measurement-register` describes the session checks in+detail, and `Limits`_ describes the transport risks.Register binding----------------@@ -490,14 +501,13 @@ LimitsThe :doc:`/security/threat-model` gives the full analysis of each ofthese.-- The transport is not authenticated. shirudo opens the device by path- in the caller's mount namespace, and its sessions are unsalted and- unbound, so no TPM response carries proof of its origin. The AK Name- comparison detects a different TPM but not a device that replays the- public Name. A root process that substitutes the device can keep- shirudo's extensions from reaching the real register.-- The owner authorization travels as a password to whatever device is- at the path, and root on the :term:`target` can read it from the+- The first TPM contact in the authenticated initrd is trusted.+ ``init`` pins the ECC endorsement primary used to salt later HMAC+ and policy sessions. Successful replies and measurement readbacks are+ authenticated, but a substituted device can still drop requests and+ deny service. See :doc:`/internals/measurement-register`.+- The owner authorization is protected in transit by HMAC authorization,+ but root on the :term:`target` can read it from the:term:`runtime image`.- The ``tpm_command`` guard covers ``TPM2_NV_Extend`` of the registeronly. ``TPM2_NV_UndefineSpace`` with the owner authorization anddiff --git a/Documentation/concepts/glossary.rst b/Documentation/concepts/glossary.rstindex 973c644e..bcdf7e8c 100644--- a/Documentation/concepts/glossary.rst+++ b/Documentation/concepts/glossary.rst@@ -165,7 +165,8 @@ it.enforcement programs compare against: the devices of the privatebpffs and of ``/run/shirudo``, the ``.bpf`` keyring and the enrolled keyserials, the runtime image's root hash, the NV index and its writer- key, the attestation key's name and the ``.dm-verity`` keyring.+ key, the attestation and session-establishment key names and the+ ``.dm-verity`` keyring.``init`` freezes it before the admission gates attach, so userspacecannot change it afterwards. See :doc:`/internals/enforcement`.diff --git a/Documentation/contribute/testing/test-coverage.rst b/Documentation/contribute/testing/test-coverage.rstindex 4e6354e3..ba65f5cb 100644--- a/Documentation/contribute/testing/test-coverage.rst+++ b/Documentation/contribute/testing/test-coverage.rst@@ -212,6 +212,14 @@ signed config image.* - ``t4004-config-attest``- Config activation in the evidence and its verification. Runs inthe register VM+ * - ``t4005-tpm-session``+ - Salted HMAC and policy sessions, ECC and RSA credential+ activation, rejected key pins, forged and replayed extension+ replies, forged NV, PCR, clock and policy-digest readbacks, and+ refusal of TPM logging overrides during bootstrap and enforcement.+ An unsalted negative control accepts a forged acknowledgment+ with an empty or SHA-256 response HMAC; malformed lengths are refused.+ Salted sessions reject it and leave the real measured value unchanged* - ``t4101-initrd``- The production configuration: ``init`` from the initrd, adoption,PCR 11 after the binding, pins under ``/run``@@ -344,7 +352,9 @@ signed config image.* - ``t6124-overlay-copy-up``- An overlay over the state root* - ``t6125-tpm-identity``- - A substituted TPM device is refused by its attestation key name+ - A substituted TPM is refused by its session key name; a proxy+ forwarding the enrolled TPM cannot suppress an extension and+ make a signed load succeed without measurement* - ``t6126-kexec``- ``kexec_file_load`` and, where available, ``kexec_load`` arerefused and counted@@ -768,7 +778,7 @@ Most of these attacks are open threats inexpectation of the state.- An environment that steers an authorized shirudo process, such as``BPM_OCI_SCHEME``, ``BPM_OCI_CA_FILE``, proxy variables,- ``SSLKEYLOGFILE`` or ``TSS2_LOGFILE``. ``t6136`` covers the dynamic+ ``SSLKEYLOGFILE``. ``t6136`` covers the dynamicloader's variables only.- A repository index or tree publication signed with a classicalalgorithm.@@ -776,8 +786,6 @@ Most of these attacks are open threats inACLs on them, and a hard link of a labeled inode into an unsealeddirectory. ``t6118`` covers hard links into sealed directories only.- An eventlog larger than the size the readers accept.-- A fake TPM transport that replays the attestation key name ``init``- recorded. ``t6125`` covers a device with another name.- Making ``init`` read another boot ID, or miss this boot's initrecord by other means than the unlabeled state directory ``t6115``covers, so that it binds the register again.diff --git a/Documentation/internals/architecture.rst b/Documentation/internals/architecture.rstindex a0883b2d..f4a91704 100644--- a/Documentation/internals/architecture.rst+++ b/Documentation/internals/architecture.rst@@ -135,7 +135,9 @@ export.The TPM holds the measurement register, an NV extend index anchored inPCR 9, the config PCR the bootstrap settings select, and the attestation-key that signs evidence.+key that signs evidence. The ECC EK salts the authenticated TPM+session; init freezes EK's name in the identity map.+How the parts depend on each other----------------------------------diff --git a/Documentation/internals/enforcement.rst b/Documentation/internals/enforcement.rstindex ae4fd841..56b2c5f0 100644--- a/Documentation/internals/enforcement.rst+++ b/Documentation/internals/enforcement.rst@@ -58,7 +58,8 @@ The objects share seven maps, which ``init`` hands from ``bpf2`` toand of ``/run/shirudo``, the runtime root hash, the ``.bpf``keyring serial and kind, the serials of the enrolled keys, the``.dm-verity`` keyring and key serials, the NV index, the NV- writer's public modulus and seed, and the attestation key name.+ writer's public modulus and seed, the attestation key name and+ the ECC endorsement key name used to salt authenticated sessions.* - ``shirudo_tasks``- ``task_authority``- Task storage with each task's mark and exec candidate.diff --git a/Documentation/internals/measurement-register.rst b/Documentation/internals/measurement-register.rstindex 9c06112a..0972378b 100644--- a/Documentation/internals/measurement-register.rst+++ b/Documentation/internals/measurement-register.rst@@ -118,6 +118,23 @@ A new host boot chooses new input and so a new key. A TPM reset withinthe same host boot keeps the input, and so the key. A TPM clear changesthe owner seed, and the frozen key can no longer be recreated.+Authenticated TPM sessions+--------------------------++Shirudo employs trust on first use (TOFU) and trusts the TPM it finds during+initialization in the initrd by freezing the EK's name in the identity map.++Every TPM connection creates the standard ECC P-256 endorsement key+(EK) to transport a secret salt via ECDH to calculate an HMAC session key.+This salted HMAC session binds communication to the enrolled TPM.+Successful responses contain HMACs that shirudo verifies.++The session's audit flag allows shirudo to authenticate responses even from+commands that require no authorization, such as PCR and clock reads.+NV extensions use separately salted policy sessions with the existing+command-bound writer authorization. An intermediary that suppresses an+extension cannot invent or replay a successful response.+Binding at boot---------------@@ -425,13 +442,11 @@ LimitsThese are properties of the design as implemented.:doc:`/security/threat-model` gives their consequences.-The TPM transport is not authenticated.- shirudo opens the TPM by device path, ``/dev/tpmrm0`` unless the- runtime settings name another device, and uses unsalted, unbound- policy sessions. The attestation key name check rejects a TPM that- reports a different name, but the name is public, so a substitute- transport could replay it. Only evidence signed by a pinned- attestation key settles which TPM answered.+The first TPM contact must be trusted.+ Session-key enrollment runs in the authenticated initrd against+ its kernel TPM device. Sessions protect later communications, not+ a bootstrap already controlled by an attacker. The operator's+ enrollment and attestation checks remain necessary.Rebinding depends on the record.``init`` decides that the register is already bound this boot fromdiff --git a/Documentation/reference/environment.rst b/Documentation/reference/environment.rstindex def72441..4f52bb7d 100644--- a/Documentation/reference/environment.rst+++ b/Documentation/reference/environment.rst@@ -182,7 +182,9 @@ per-signal variable takes precedence over the generic one. SeeLibraries----------shirudo sets none of these and refuses none of them.+These variables control library behavior. Target entry refuses the log+file destinations described above, and TPM setup always disables library+logging, including during bootstrap... list-table:::header-rows: 1@@ -204,12 +206,14 @@ shirudo sets none of these and refuses none of them.upper case is not read.* - ``TSS2_LOG``- tpm2-tss- - Log levels of the TPM library. shirudo sets ``all+none`` when the- variable is unset.+ - Log levels of the TPM library. shirudo always forces ``all+none``,+ including during bootstrap, because library debug logs can expose+ session secrets.* - ``TSS2_LOGFILE``- tpm2-tss- Destination of those logs: ``stderr`` (default), ``stdout`` or- ``-``, or a file opened for appending.+ ``-``, or a file opened for appending. Refused on a target.+ TPM connection setup always clears it before library initialization.* - ``LIBBPF_LOG_LEVEL``- libbpf- ``warn``, ``info`` (default) or ``debug`` for libbpf's messagesdiff --git a/Documentation/security/cryptography.rst b/Documentation/security/cryptography.rstindex 7b2be025..d5d333e7 100644--- a/Documentation/security/cryptography.rst+++ b/Documentation/security/cryptography.rst@@ -205,7 +205,8 @@ TPM* - Endorsement key- The TCG default template, RSA-2048 with the exponent 65537 or ECCP-256, with AES-128 in CFB mode as its symmetric algorithm- - Credential activation for ``shirudo attest challenge``+ - Credential activation for ``shirudo attest challenge``; the ECC+ primary also salts TPM sessions, with its name frozen at init* - Credential- RSA-OAEP with SHA-256 and the label ``IDENTITY`` for an RSAendorsement key, or an ephemeral ECDH on P-256 with KDFe for an@@ -234,13 +235,16 @@ TPMSessions and authorization:-- The register's policy session uses SHA-256, is unsalted and unbound,- and has no symmetric algorithm, so no parameter is encrypted and no- response is authenticated by a session (threat model U8).-- Commands that need authorization use password sessions: the owner- password from ``tpm.owner_auth``, when configured, in plain, and an- empty password for the endorsement hierarchy. shirudo uses no HMAC- session.+- SHA-256 HMAC and policy sessions are salted with the standard ECC+ endorsement primary whose name ``init`` freezes. Successful responses,+ including NV, PCR and clock readbacks, are authenticated. The HMAC+ session has the audit attribute to cover commands without an+ authorization handle.+- The sessions are unbound and have no symmetric algorithm: parameters+ are not encrypted. The owner authorization from ``tpm.owner_auth`` is+ used in HMAC authorization, not transmitted as a password. Initial+ endorsement-primary creation uses the empty endorsement authorization+ and trusts the initrd's TPM device.Key custody-----------diff --git a/Documentation/security/security-model.rst b/Documentation/security/security-model.rstindex 646b974a..eabb06e9 100644--- a/Documentation/security/security-model.rst+++ b/Documentation/security/security-model.rst@@ -46,10 +46,11 @@ What shirudo provides- :ref:`T3 <tm-t3>`, R19* - Every change is measured- Loads, unloads, revocations and tree operations extend a TPM NV- register whose writes ``lsm/tpm_command`` keeps to shirudo.- - The TPM transport is not authenticated; the config PCR is not- guarded.- - :ref:`T5 <tm-t5>`, R4, U8, U9+ register whose writes ``lsm/tpm_command`` keeps to shirudo;+ salted sessions authenticate TPM acknowledgments and readbacks.+ - Initial session-key enrollment trusts the initrd; the config+ PCR is not guarded.+ - :ref:`T5 <tm-t5>`, R4, U9* - A verifier can tell- ``shirudo attest`` returns a TPM quote and a certification of theregister; ``shirudo attest verify`` checks them offline.diff --git a/Documentation/security/threat-model.rst b/Documentation/security/threat-model.rstindex 5dc832a5..643a4db5 100644--- a/Documentation/security/threat-model.rst+++ b/Documentation/security/threat-model.rst@@ -459,7 +459,7 @@ ADV-C, root with mount-namespace and device controlA refinement of ADV-B that uses private mount namespaces, bindmounts over shirudo's paths, overlays, substitute device nodes and``/proc`` substitution to show a shirudo command a different world.- T3, T11 and T14 address parts of it. R22, U8 and U9 are the parts+ T3, T11 and T14 address parts of it. R22 and U9 are the partsthat remain.ADV-D, network and registry@@ -962,7 +962,7 @@ tree operations run without it.:Proofs: ``Shirudo.Chain``, ``Shirudo.Events``, ``Shirudo.Measured``,``Shirudo.UpatchLoad``, ``chain-events``, ``measured-fold-model``,``eventlog-records``, ``tpm-digest``-:Residual: R4, R12, R20, U6, U8, U9+:Residual: R4, R12, R20, U6, U9T6 Boot window~~~~~~~~~~~~~~@@ -1126,7 +1126,7 @@ document can carry a software key's signatures (U1).:Proofs: ``tpm-reader``, ``tpm-attest``, ``tpm-signature``,``tpm-public``, ``attest-pcr``, ``attest-fields``,``attest-name-digest``, ``Shirudo.Chain``, ``Shirudo.Events``-:Residual: R10, R11, U1, U8, U9+:Residual: R10, R11, U1, U9.. _tm-t10:@@ -1291,28 +1291,32 @@ instance, and the emulator would answer every check that comparespublic values, since the index name, the policy and the reset count arein the readable init record.-Before it binds or extends the register, and before a config-activation, shirudo recreates the attestation key under the endorsement-hierarchy and compares its name with the one ``init`` froze in the-identity map. An emulator lacks the TPM's endorsement seed and produces-another name, and the command refuses. The comparison authenticates the-TPM's answer to that one command, not the responses that follow: shirudo-uses unsalted, unbound sessions, so a device that forwards some-commands to the real TPM and answers others itself is not detected-(U8). ``lsm/tpm_command`` refuses an unauthorized extension only for-commands that reach the real driver.+Every connection recreates the ECC endorsement primary and, while+enforcement is active, compares its name with the one ``init`` froze.+That primary salts HMAC and policy sessions. Successful TPM replies,+including the extension acknowledgments and NV, PCR and clock readbacks,+are authenticated. A device that forwards the key creation but suppresses+an extension cannot produce a valid success response or fabricate the+readback. Session failures are not retried as measurements.++Initial enrollment trusts the authenticated initrd and the kernel TPM+device it opens (A1, A6, A8). An unreadable frozen identity, a missing pin+or a different session key fails rather than enrolling a replacement.+The attestation key comparison remains an additional check.+``lsm/tpm_command`` refuses unauthorized extensions that reach the real+driver; sessions do not prevent denial of service by dropping requests... rst-class:: facts:Adversary: ADV-C, root with mount-namespace and device control:Enforced at: ``lsm/tpm_command`` for commands that reach the driver;- the attestation key comparison in userspace-:Refusal: ``tampered`` from the register path+ pinned-key and session-response checks in userspace+:Refusal: the TPM operation fails; measuring commands refuse:Counters: ``TpmExtend`` for a refused extension; none for asubstituted device-:Tests: ``t4103``, ``t6125``+:Tests: ``t4005``, ``t4103``, ``t6125``:Proofs: ``tpm-public``, ``tpm-kdf``-:Residual: U8+:Residual: trusted bootstrap (A1, A6, A8); denial of serviceResidual risks--------------@@ -1524,9 +1528,10 @@ R19 Raw device and offline writes bypass the sealR20 The TPM owner password is not a secret on the target``tpm.owner_auth`` lives in the runtime image's ``shirudo.conf``,- where root reads it, and shirudo sends it as a plain password- session. Root can undefine the register, which makes every measuring- command refuse until the next TPM reset, or use the owner hierarchy.+ where root reads it. shirudo uses it in HMAC authorization, but this+ does not hide it on disk. Root can undefine the register, which makes+ every measuring command refuse until the next TPM reset, or use the+ owner hierarchy.An image shared across a fleet shares the password.R21 upatches can be neutralized without detaching them@@ -1657,22 +1662,6 @@ U7 The shipped timer units run the host binarystarts its commands from the runtime image, as the test VM doesin :src:`testing/vm/guest.sh`.-U8 The TPM transport is not authenticated- :Affects: The register (T5) and the device check (T14).- :Consequence: shirudo opens the TPM by path and uses unsalted,- unbound sessions, so no response is authenticated. A device in- root's mount namespace that forwards the attestation key's- creation to the real TPM and answers the rest can accept- extensions that never reach the TPM. Root then drops those- records from the evidence it relays, and the evidence verifies- while an upatch was loaded or removed unmeasured. The owner- password, when configured, goes to that device too.- :Status: Confirmed in code for the sessions and the device path; the- attack is a code-path reading, not reproduced.- :Meanwhile: No deployment setting closes it. Pin the bind PCRs and- the expected state on every verification so that other- substitutions fail.-U9 init can rebind the register after hiding this boot's record:Affects: The one-binding-per-reset rule (T5).:Consequence: ``init`` decides whether it bound the register thisdiff --git a/Makefile.shirudo b/Makefile.shirudoindex 7c2283d1..2d417427 100644--- a/Makefile.shirudo+++ b/Makefile.shirudo@@ -659,6 +659,7 @@ TEST_HELPERS := $(VERITY_TEST_HELPERS) \testing/helper/test-register \testing/helper/test-register-cli \testing/helper/test-nv-cphash \+ testing/helper/test-tpm-session \testing/helper/test-eventlog \testing/helper/test-keys \testing/helper/test-seal \@@ -710,6 +711,8 @@ REGISTER_OBJS := util/config_attest.o util/config_update.o util/config_measure.oREGISTER_LIBS := $(LIBCRYPTO_LIBS) $(LIBSSL_LIBS) $(TSS2_LIBS) \$(LIBBPF_A) $(LIBELF_LIBS) $(ZLIB_LIBS)+TPM_CLIENT_SRCS := testing/helper/tpm-client.c testing/helper/tpm-session.h+testing/helper/test-nv-writer: testing/helper/test-nv-writer.c $(REGISTER_OBJS)@printf ' CC $@\n'$(Q)$(CC) $(CFLAGS) -o $@ $^ $(REGISTER_LIBS)@@ -725,9 +728,10 @@ testing/helper/test-keyring-seal: testing/helper/test-keyring-seal.c \$(STATIC_LIBS) $(DYNAMIC_LIBS)testing/helper/test-tpm-preopened: testing/helper/test-tpm-preopened.c \- $(REGISTER_OBJS)+ $(TPM_CLIENT_SRCS) $(REGISTER_OBJS)@printf ' CC $@\n'- $(Q)$(CC) $(CFLAGS) -o $@ $^ $(REGISTER_LIBS)+ $(Q)$(CC) $(CFLAGS) -o $@ $(filter-out %.h,$^) $(REGISTER_LIBS) \+ -Wl,--wrap=enforcement_activetesting/helper/test-keys: testing/helper/test-keys.c util/keys.o \util/upatch.o $(REGISTER_OBJS)@@ -751,9 +755,10 @@ testing/helper/test-tpm-wire: testing/helper/test-tpm-wire.c util/tpm_wire.o uti$(Q)$(CC) $(CFLAGS) -o $@ $^ -lcrypto -lssltesting/helper/test-register: testing/helper/test-register.c util/attest.o util/keyring.o \- util/upatch.o $(REGISTER_OBJS)+ util/upatch.o $(TPM_CLIENT_SRCS) $(REGISTER_OBJS)@printf ' CC $@\n'- $(Q)$(CC) $(CFLAGS) -o $@ $^ $(REGISTER_LIBS)+ $(Q)$(CC) $(CFLAGS) -o $@ $(filter-out %.h,$^) $(REGISTER_LIBS) \+ -Wl,--wrap=enforcement_activetesting/helper/test-register-cli: testing/helper/test-register-cli.c \$(BUILTIN_OBJS) $(UTIL_OBJS) $(VERSION_OBJ) $(LIBBPF_A)@@ -764,9 +769,17 @@ testing/helper/tpmsim-cmd: testing/helper/tpmsim-cmd.c@printf ' CC $@\n'$(Q)$(CC) $(CFLAGS_BASE) -Iinclude $(TPMSIM_CFLAGS) -o $@ $< $(TPMSIM_LIBS) -lcrypto-testing/helper/test-nv-cphash: testing/helper/test-nv-cphash.c util/keyring.o $(REGISTER_OBJS)+testing/helper/test-nv-cphash: testing/helper/test-nv-cphash.c util/keyring.o \+ $(TPM_CLIENT_SRCS) $(REGISTER_OBJS)@printf ' CC $@\n'- $(Q)$(CC) $(CFLAGS) -o $@ $^ $(REGISTER_LIBS)+ $(Q)$(CC) $(CFLAGS) -o $@ $(filter-out %.h,$^) $(REGISTER_LIBS) \+ -Wl,--wrap=enforcement_active++testing/helper/test-tpm-session: testing/helper/test-tpm-session.c \+ $(TPM_CLIENT_SRCS) $(REGISTER_OBJS)+ @printf ' CC $@\n'+ $(Q)$(CC) $(CFLAGS) -o $@ $(filter-out %.h,$^) $(REGISTER_LIBS) \+ -Wl,--wrap=enforcement_active,--wrap=identity_readtesting/helper/test-config: testing/helper/test-config.c util/config.o util/io.o util/seal.o util/log.o util/hex.o \util/image_config.o util/string.o util/malloc.odiff --git a/bpf/lib/identity.h b/bpf/lib/identity.hindex 015c6ca9..98ad8ff6 100644--- a/bpf/lib/identity.h+++ b/bpf/lib/identity.h@@ -21,6 +21,7 @@ struct sb_id {__u8 nv_writer_public[TPM_NV_RSA_BYTES];__u8 ak_name[TPM_NAME_LEN];__u32 ak_name_len;+ __u8 ek_name[TPM_NAME_LEN];__s32 dm_verity_ring;__s32 dm_verity_key;__u32 nv_index;diff --git a/builtin-init.c b/builtin-init.cindex 77b74f79..bd75695c 100644--- a/builtin-init.c+++ b/builtin-init.c@@ -559,10 +559,8 @@ static int freeze_task_maps(struct bpf_object *obj)}/*- * The register is only as good as the TPM that holds it, and the device- * the TCTI opens is root's to replace: every register write recreates the- * attestation key, whose name no other TPM produces, and compares it with- * the one recorded here (util/chain.c).+ * Initial TPM contact is trusted in the authenticated initrd. Later+ * connections salt their sessions with the key whose name we freeze here.*/static int record_attestation_key(struct identity *id){@@ -577,6 +575,7 @@ static int record_attestation_key(struct identity *id)if (!ret) {memcpy(id->ak_name, ak.name, ak.name_len);id->ak_name_len = (__u32)ak.name_len;+ tpm_ek_name(tpm, id->ek_name);tpm_key_flush(tpm, &ak);}tpm_close(tpm);diff --git a/testing/functional/tamperproof/t6125-pty-tpm.py b/testing/functional/tamperproof/t6125-pty-tpm.pyindex 12cee8d5..09c0d549 100755--- a/testing/functional/tamperproof/t6125-pty-tpm.py+++ b/testing/functional/tamperproof/t6125-pty-tpm.py@@ -44,6 +44,50 @@ def serve(state, swtpm):"--log", "file=" + os.path.join(state, "log") + ",level=1"])+def read_packet(fd):+ data = b""+ size = 10+ while len(data) < size:+ chunk = os.read(fd, size - len(data))+ if not chunk:+ raise RuntimeError("TPM connection closed mid-packet")+ data += chunk+ if len(data) == 10:+ size = struct.unpack(">I", data[2:6])[0]+ if not 10 <= size <= 65536:+ raise RuntimeError("invalid TPM packet size")+ return data+++def proxy(state):+ backend = os.open("/dev/tpmrm0", os.O_RDWR)+ master, slave = pty.openpty()+ tty.setraw(master)+ tty.setraw(slave)+ with open(os.path.join(state, "slave"), "w") as f:+ f.write(os.ttyname(slave))+ while True:+ command = read_packet(master)+ code = struct.unpack(">I", command[6:10])[0]+ if code == 0x136:+ response = (struct.pack(">HIIIH", 0x8002, 83, 0, 0, 32) ++ bytes(32) + b"\x01" + struct.pack(">H", 32) + bytes(32))+ print("proxy: suppressed NV_Extend", flush=True)+ else:+ if os.write(backend, command) != len(command):+ raise RuntimeError("short TPM command write")+ response = read_packet(backend)+ offset = 0+ while offset < len(response):+ written = os.write(master, response[offset:])+ if written <= 0:+ raise RuntimeError("short TPM response write")+ offset += written++if sys.argv[1] == "probe":sys.exit(probe(sys.argv[2]))+if sys.argv[1] == "proxy":+ proxy(sys.argv[2])+ sys.exit(0)serve(sys.argv[1], sys.argv[2])diff --git a/testing/functional/tamperproof/t6125-tpm-identity.sh b/testing/functional/tamperproof/t6125-tpm-identity.shindex be09d982..f8a163f8 100755--- a/testing/functional/tamperproof/t6125-tpm-identity.sh+++ b/testing/functional/tamperproof/t6125-tpm-identity.sh@@ -4,11 +4,8 @@## t6125 -- the TPM behind the device path is root's to replace: in a# mount namespace of root's own a bind mount puts a character device of-# root's at /dev/tpmrm0, and an emulator behind it answered every check-# the register path made, since the index name, policy and reset count-# it compares are in the readable init record. Every TPM handle a-# command takes must first compare the attestation key's name with the-# one init recorded, which takes the endorsement seed no emulator has.+# root's at /dev/tpmrm0. Refuse both another TPM and forged responses+# from a proxy forwarding the enrolled TPM's identity.cd "$(dirname "$0")/../..". ./integration-lib.sh@@ -30,6 +27,7 @@ mkdir -p "$W"cleanup() {[ -s "$W/pid" ] && kill "$(cat "$W/pid")" 2>/dev/null+ [ -s "$W/proxy-pid" ] && kill "$(cat "$W/proxy-pid")" 2>/dev/nullif [ -e "$PIN" ]; then"$SHIRUDO_BIN" upatch unload "$UNLOAD" --no-precheck \>/dev/null 2>&1 || true@@ -83,4 +81,37 @@ test_expect_success 'the same load succeeds against the TPM init bound' '[ ! -e "$PIN" ]'+mkdir "$W/proxy" || exit 1+python3 functional/tamperproof/t6125-pty-tpm.py proxy "$W/proxy" >"$W/proxy.out" 2>&1 &+echo $! >"$W/proxy-pid"+for i in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20; do+ [ -s "$W/proxy/slave" ] && break+ sleep 0.5+done++test_expect_success 'the genuine TPM remains identifiable through the proxy' '+ [ -s "$W/proxy/slave" ] &&+ SLAVE=$(cat "$W/proxy/slave") &&+ at_slave env TSS2_LOG=all+TRACE \+ "$SHIRUDO_BIN" status --json >"$W/proxy-status.json" &&+ python3 -c "import json; assert json.load(open(\"$W/proxy-status.json\"))[\"tpm\"][\"chain_matches_eventlog\"] is True"+'++test_expect_success 'suppressing an extension cannot produce a successful unmeasured load' '+ SLAVE=$(cat "$W/proxy/slave") &&+ before=$(chain) &&+ lines=$(wc -l </var/lib/shirudo/eventlog) &&+ {+ rc=0+ at_slave "$SHIRUDO_BIN" upatch load "$LOAD" --no-precheck \+ >/dev/null 2>"$W/proxy-load.err" || rc=$?+ [ "$rc" != 0 ] &&+ grep -qx "proxy: suppressed NV_Extend" "$W/proxy.out" &&+ grep -q "NV_Extend.*rc=0x0007001b" "$W/proxy-load.err" &&+ [ ! -e "$PIN" ] &&+ [ "$(chain)" = "$before" ] &&+ [ "$(wc -l </var/lib/shirudo/eventlog)" = "$lines" ]+ }+'+test_donediff --git a/testing/functional/tamperproof/t6134-seal-task.sh b/testing/functional/tamperproof/t6134-seal-task.shindex 00b9ee85..dfeaadfd 100755--- a/testing/functional/tamperproof/t6134-seal-task.sh+++ b/testing/functional/tamperproof/t6134-seal-task.sh@@ -18,17 +18,11 @@ command -v python3 >/dev/null 2>&1 || test_skip_all "no python3"W=$(mktemp -d) || test_skip_all "cannot make a scratch directory"PID=cleanup() {- # A writer lets the blocked open return; shirudo then rejects the- # input and exits. ENXIO means it is not waiting any more.- [ -n "$PID" ] && python3 -c '-import os, sys-try:- fd = os.open(sys.argv[1], os.O_WRONLY | os.O_NONBLOCK)- os.write(fd, b"x")- os.close(fd)-except OSError:- pass' "$W/fifo" 2>/dev/nullif [ -n "$PID" ]; then+ if [ -d "/proc/$PID" ] &&+ [ "$(awk '{print $3}' "/proc/$PID/stat" 2>/dev/null)" != Z ]; then+ fifo_release "$W/fifo" || :+ fiwait "$PID" 2>/dev/null || :firm -rf "$W"@@ -38,7 +32,7 @@ trap cleanup EXITmkfifo "$W/fifo" || test_skip_all "cannot make a fifo""$SHIRUDO_BIN" bpm info "$W/fifo" >/dev/null 2>&1 &PID=$!-# Blocked in open(2) of the fifo: alive and sleeping.+# A sleeping task may still be completing TPM startup.i=0while [ "$i" -lt 50 ]; do[ -d "/proc/$PID" ] || break@@ -92,12 +86,8 @@ fi# The task is the main shell's child: the case's subshell cannot reap it,# so it watches the task become a zombie instead.test_expect_success 'the task is unharmed and finishes once released' '- [ "$(cut -d" " -f3 "/proc/$PID/stat")" = S ] &&- python3 -c "-import os, sys-fd = os.open(sys.argv[1], os.O_WRONLY | os.O_NONBLOCK)-os.write(fd, b\"x\")-os.close(fd)" "$W/fifo" &&+ [ -d "/proc/$PID" ] &&+ fifo_release "$W/fifo" &&i=0 &&while s=$(cut -d" " -f3 "/proc/$PID/stat" 2>/dev/null) &&[ "$s" != Z ]; dodiff --git a/testing/functional/tamperproof/t6135-task-descriptors.sh b/testing/functional/tamperproof/t6135-task-descriptors.shindex 59750fba..b9096435 100755--- a/testing/functional/tamperproof/t6135-task-descriptors.sh+++ b/testing/functional/tamperproof/t6135-task-descriptors.sh@@ -19,14 +19,10 @@ PID=OTHER=release() {[ -n "$PID" ] || return 0- python3 -c '-import os, sys-try:- fd = os.open(sys.argv[1], os.O_WRONLY | os.O_NONBLOCK)- os.write(fd, b"x")- os.close(fd)-except OSError:- pass' "$W/fifo" 2>/dev/null || true+ if [ -d "/proc/$PID" ] &&+ [ "$(awk '{print $3}' "/proc/$PID/stat" 2>/dev/null)" != Z ]; then+ fifo_release "$W/fifo" || true+ fiwait "$PID" 2>/dev/null || truePID=}diff --git a/testing/functional/tpm/t4005-tpm-session.sh b/testing/functional/tpm/t4005-tpm-session.shnew file mode 100644index 00000000..2caaec68--- /dev/null+++ b/testing/functional/tpm/t4005-tpm-session.sh@@ -0,0 +1,28 @@+#!/bin/sh+# SPDX-License-Identifier: BSD-2-Clause+# Copyright (c) 2026 Authors of shirudo++cd "$(dirname "$0")/../.."+. ./test-lib.sh++[ -x helper/tpmsim-cmd ] || test_skip_all "tpmsim-cmd not built (libtpms required)"+WORK=$(mktemp -d) || exit 1+cleanup() {+ for mode in unsalted-control nv-extend nv-replay pcr-extend nv-read \+ pcr-read clock policy-digest identity; do+ rm -f "$WORK/$mode/permanent" "$WORK/$mode/volatile" "$WORK/$mode/NVChip"+ rmdir "$WORK/$mode"+ done+ rmdir "$WORK"+}+trap cleanup EXIT++for mode in unsalted-control nv-extend nv-replay pcr-extend nv-read \+ pcr-read clock policy-digest identity; do+ export SHIRUDO_TPM_TCTI="cmd:$(pwd)/helper/tpmsim-cmd $WORK/$mode"+ test_expect_success "TPM session: $mode" '+ ./helper/test-tpm-session "$mode"+ '+done++test_donediff --git a/testing/helper/test-tpm-session.c b/testing/helper/test-tpm-session.cnew file mode 100644index 00000000..435942bb--- /dev/null+++ b/testing/helper/test-tpm-session.c@@ -0,0 +1,374 @@+// SPDX-License-Identifier: BSD-2-Clause+/* Copyright (c) 2026 Authors of shirudo */++#include <errno.h>+#include <stdio.h>+#include <stdlib.h>+#include <string.h>++#include "tpm_internal.h"++#include <shirudo/byteorder.h>+#include <shirudo/string.h>++#include "chain.h"+#include "crypto.h"+#include "tpm-session.h"++#define TEST_INDEX 0x01818E02u+#define CHECK(expr) do { \+ if (!(expr)) { \+ fprintf(stderr, "line %d: %s\n", __LINE__, #expr); \+ goto out; \+ } \+} while (0)++static struct identity identity;+static int identity_error;++int __wrap_identity_read(struct identity *out)+{+ *out = identity;+ return identity_error;+}++enum fault_mode {+ CAPTURE,+ REPLAY,+ FORGE,+ CORRUPT,+ CORRUPT_HMAC,+};++static struct {+ TSS2_TCTI_TRANSMIT_FCN transmit;+ TSS2_TCTI_RECEIVE_FCN receive;+ TSS2_TCTI_CONTEXT *context;+ __u8 response[4096];+ size_t response_len;+ enum fault_mode mode;+ __u32 command;+ bool selected;+ bool hit;+} proxy;++/*+ * NV_Extend replies have no parameters. Unsalted policy sessions may+ * omit the response HMAC; older libtpms versions still emit one.+ */+static TSS2_RC forge_success(const __u8 *command, size_t size)+{+ __u8 input[97], header[8], empty = 0;+ __u16 hmac_len;++ if (size < 62 || get_be16(command + 26) != TPM_DIGEST_LEN ||+ proxy.response_len < 51 ||+ get_be16(proxy.response + 14) != TPM_DIGEST_LEN)+ return TSS2_TCTI_RC_BAD_VALUE;+ hmac_len = get_be16(proxy.response + 49);+ if ((hmac_len && hmac_len != TPM_DIGEST_LEN) ||+ proxy.response_len != 51u + hmac_len)+ return TSS2_TCTI_RC_BAD_VALUE;+ if (!hmac_len)+ return TSS2_RC_SUCCESS;+ memcpy(header, proxy.response + 6, 4);+ memcpy(header + 4, command + 6, 4);+ if (sha256_buffer(header, sizeof(header), input))+ return TSS2_TCTI_RC_GENERAL_FAILURE;+ memcpy(input + 32, proxy.response + 16, 32);+ memcpy(input + 64, command + 28, 32);+ input[96] = proxy.response[48];+ if (hmac_sha256(&empty, 0, input, sizeof(input), proxy.response + 51))+ return TSS2_TCTI_RC_GENERAL_FAILURE;+ return TSS2_RC_SUCCESS;+}++static int forge_reply_cases(void)+{+ __u8 command[97] = {};+ int ret = 1;++ put_be16(command + 26, TPM_DIGEST_LEN);+ put_be16(proxy.response + 14, TPM_DIGEST_LEN);+ proxy.response_len = 51;+ CHECK(forge_success(command, sizeof(command)) == TSS2_RC_SUCCESS);+ proxy.response_len = 83;+ CHECK(forge_success(command, sizeof(command)) == TSS2_TCTI_RC_BAD_VALUE);+ put_be16(proxy.response + 49, TPM_DIGEST_LEN);+ CHECK(forge_success(command, sizeof(command)) == TSS2_RC_SUCCESS);+ proxy.response_len--;+ CHECK(forge_success(command, sizeof(command)) == TSS2_TCTI_RC_BAD_VALUE);+ put_be16(proxy.response + 49, TPM_DIGEST_LEN - 1);+ CHECK(forge_success(command, sizeof(command)) == TSS2_TCTI_RC_BAD_VALUE);+ ret = 0;+out:+ memzero_explicit(&proxy, sizeof(proxy));+ return ret;+}++static TSS2_RC transmit(TSS2_TCTI_CONTEXT *context, size_t size,+ const __u8 *command)+{+ __u32 code;++ if (size < 10)+ return TSS2_TCTI_RC_BAD_VALUE;+ code = ((__u32)command[6] << 24) | ((__u32)command[7] << 16) |+ ((__u32)command[8] << 8) | command[9];+ proxy.selected = code == proxy.command;+ if (proxy.selected && proxy.mode == FORGE)+ return forge_success(command, size);+ if (proxy.selected && proxy.mode == REPLAY)+ return TSS2_RC_SUCCESS;+ return proxy.transmit(context, size, command);+}++static TSS2_RC receive(TSS2_TCTI_CONTEXT *context, size_t *size,+ __u8 *response, __s32 timeout)+{+ TSS2_RC ret;++ if (proxy.selected && (proxy.mode == REPLAY || proxy.mode == FORGE)) {+ if (!proxy.response_len)+ return TSS2_TCTI_RC_BAD_VALUE;+ if (response) {+ if (*size < proxy.response_len)+ return TSS2_TCTI_RC_INSUFFICIENT_BUFFER;+ memcpy(response, proxy.response, proxy.response_len);+ proxy.hit = true;+ }+ *size = proxy.response_len;+ return TSS2_RC_SUCCESS;+ }+ ret = proxy.receive(context, size, response, timeout);+ if (ret || !response || !proxy.selected)+ return ret;+ if (*size < 17 || *size > sizeof(proxy.response))+ return TSS2_TCTI_RC_BAD_VALUE;+ proxy.hit = true;+ if (proxy.mode == CAPTURE) {+ memcpy(proxy.response, response, *size);+ proxy.response_len = *size;+ } else if (proxy.mode == CORRUPT_HMAC) {+ if (get_be16(response) == TPM2_ST_SESSIONS)+ response[*size - 1] ^= 1;+ } else {+ response[16] ^= 1;+ }+ return TSS2_RC_SUCCESS;+}++static void intercept(struct tpm *t, __u32 command, enum fault_mode mode)+{+ proxy.context = t->tcti;+ proxy.transmit = TSS2_TCTI_TRANSMIT(t->tcti);+ proxy.receive = TSS2_TCTI_RECEIVE(t->tcti);+ proxy.command = command;+ proxy.mode = mode;+ proxy.selected = false;+ proxy.hit = false;+ TSS2_TCTI_TRANSMIT(t->tcti) = transmit;+ TSS2_TCTI_RECEIVE(t->tcti) = receive;+}++static void restore(void)+{+ if (!proxy.context)+ return;+ TSS2_TCTI_TRANSMIT(proxy.context) = proxy.transmit;+ TSS2_TCTI_RECEIVE(proxy.context) = proxy.receive;+ proxy.context = NULL;+}++static int activate(struct tpm *t, const struct tpm_key *ak,+ bool rsa)+{+ TPM2B_DIGEST credential = { .size = 32, .buffer = { 7 } };+ TPM2B_ENCRYPTED_SECRET *secret = NULL;+ TPM2B_ID_OBJECT *blob = NULL;+ struct tpm_key ek = {};+ TPM2B_NAME name = {};+ __u8 recovered[32];+ size_t length = 0;+ int ret = 1;++ CHECK(!tpm_ek_create(t, rsa, &ek));+ name.size = ak->name_len;+ memcpy(name.name, ak->name, name.size);+ CHECK(Esys_MakeCredential(t->esys, ek.handle, t->session, ESYS_TR_NONE,+ ESYS_TR_NONE, &credential, &name, &blob,+ &secret) == TSS2_RC_SUCCESS);+ CHECK(!tpm_activate_credential(t, ak, &ek, blob->credential, blob->size,+ secret->secret, secret->size, recovered,+ sizeof(recovered), &length));+ CHECK(length == credential.size &&+ !memneq_explicit(recovered, credential.buffer, length));+ blob->credential[blob->size - 1] ^= 1;+ CHECK(tpm_activate_credential(t, ak, &ek, blob->credential, blob->size,+ secret->secret, secret->size, recovered,+ sizeof(recovered), &length) == -EKEYREJECTED);+ ret = 0;+out:+ memzero_explicit(recovered, sizeof(recovered));+ memzero_explicit(&credential, sizeof(credential));+ if (secret)+ memzero_explicit(secret, sizeof(*secret));+ Esys_Free(secret);+ Esys_Free(blob);+ tpm_key_flush(t, &ek);+ return ret;+}++int main(int argc, char **argv)+{+ __u8 branch_written[32], branch_init[32], policy[32], values[64];+ __u8 public[TPM_NV_RSA_BYTES], seed[32] = { 1 };+ __u8 before[32], after[32], event[32] = { 2 };+ struct tpm *t = NULL, *other = NULL;+ struct tpm_attestation attestation;+ struct tpm_nv_info info;+ const char *log_setting;+ struct tpm_key ak = {};+ __u32 reset, restart;+ bool defined = false;+ int ret = 1;++ CHECK(argc == 2);+ CHECK(!forge_reply_cases());+ CHECK(!setenv("TSS2_LOG", "all+TRACE", 1));+ CHECK(!setenv("TSS2_LOGFILE", "stdout", 1));+ CHECK(!tpm_open(&t));+ log_setting = getenv("TSS2_LOG");+ CHECK(log_setting && !strcmp(log_setting, "all+none"));+ CHECK(!getenv("TSS2_LOGFILE"));+ tpm_ek_name(t, identity.ek_name);+ CHECK(identity.ek_name[1] == TPM2_ALG_SHA256);+ tpm_close(t);+ t = NULL;+ enforcing = 1;+ CHECK(!setenv("TSS2_LOG", "all+TRACE", 1));+ CHECK(!setenv("TSS2_LOGFILE", "stdout", 1));+ CHECK(!tpm_open(&t));+ log_setting = getenv("TSS2_LOG");+ CHECK(log_setting && !strcmp(log_setting, "all+none"));+ CHECK(!getenv("TSS2_LOGFILE"));+ CHECK(!tpm_boot_identity(t, &reset, &restart));+ CHECK(!tpm_pcr_read(t, 9, values));+ CHECK(!tpm_pcr_read(t, 11, values + 32));+ CHECK(!tpm_ak_create(t, &ak));+ CHECK(!tpm_quote(t, &ak, event, sizeof(event), 1u << 9, &attestation));+ CHECK(!activate(t, &ak, false));+ CHECK(!activate(t, &ak, true));+ tpm_key_flush(t, &ak);+ CHECK(!tpm_writer_create(t, seed, public));+ CHECK(!tpm_nv_set_writer(t, seed, public));+ CHECK(!tpm_register_policy(CHAIN_PCR_MASK, values, 2, public,+ branch_written, branch_init, policy));+ CHECK(!tpm_nv_info(t, TEST_INDEX, &info) && !info.defined);+ CHECK(!tpm_nv_define(t, TEST_INDEX, policy, NULL, 0));+ defined = true;+ CHECK(!tpm_nv_extend_first(t, TEST_INDEX, CHAIN_PCR_MASK,+ branch_written, branch_init, event));+ CHECK(!tpm_nv_read(t, TEST_INDEX, before));+ CHECK(!tpm_ak_create(t, &ak));+ CHECK(!tpm_nv_certify(t, &ak, TEST_INDEX, event, sizeof(event), &attestation));+ tpm_key_flush(t, &ak);+ puts("authenticated TPM reads, writes, quote and certification succeeded");++ if (!strcmp(argv[1], "nv-extend") || !strcmp(argv[1], "nv-replay") ||+ !strcmp(argv[1], "unsalted-control")) {+ bool unsalted = !strcmp(argv[1], "unsalted-control");+ bool replay = !strcmp(argv[1], "nv-replay");+ ESYS_TR salting_key = t->session_key.handle;++ if (unsalted)+ t->session_key.handle = ESYS_TR_NONE;+ intercept(t, TPM2_CC_NV_Extend, CAPTURE);+ CHECK(!tpm_nv_extend(t, TEST_INDEX, branch_written, branch_init, event));+ CHECK(proxy.hit);+ restore();+ CHECK(!tpm_nv_read(t, TEST_INDEX, before));+ intercept(t, TPM2_CC_NV_Extend, replay ? REPLAY : FORGE);+ if (unsalted)+ CHECK(!tpm_nv_extend(t, TEST_INDEX, branch_written, branch_init, event));+ else+ CHECK(tpm_nv_extend(t, TEST_INDEX, branch_written, branch_init, event) < 0);+ CHECK(proxy.hit);+ restore();+ t->session_key.handle = salting_key;+ tpm_close(t);+ t = NULL;+ CHECK(!tpm_open(&t));+ CHECK(!tpm_nv_read(t, TEST_INDEX, after) && !memcmp(before, after, 32));+ puts(unsalted ? "negative control: unsalted session accepted suppressed NV_Extend" :+ "suppressed NV_Extend with forged or replayed success rejected; register unchanged");+ } else if (!strcmp(argv[1], "pcr-extend")) {+ intercept(t, TPM2_CC_PCR_Extend, CAPTURE);+ CHECK(!tpm_pcr_extend(t, 23, event) && proxy.hit);+ restore();+ CHECK(!tpm_pcr_read(t, 23, before));+ intercept(t, TPM2_CC_PCR_Extend, REPLAY);+ CHECK(tpm_pcr_extend(t, 23, event) < 0 && proxy.hit);+ restore();+ tpm_close(t);+ t = NULL;+ CHECK(!tpm_open(&t));+ CHECK(!tpm_pcr_read(t, 23, after) && !memcmp(before, after, 32));+ puts("suppressed PCR_Extend with replayed success rejected; PCR unchanged");+ } else if (!strcmp(argv[1], "nv-read") || !strcmp(argv[1], "pcr-read") ||+ !strcmp(argv[1], "clock") || !strcmp(argv[1], "policy-digest")) {+ if (!strcmp(argv[1], "policy-digest")) {+ intercept(t, TPM2_CC_PolicyGetDigest, CORRUPT_HMAC);+ CHECK(tpm_nv_extend(t, TEST_INDEX, branch_written,+ branch_init, event) < 0 && proxy.hit);+ } else if (!strcmp(argv[1], "nv-read")) {+ intercept(t, TPM2_CC_NV_Read, CORRUPT);+ CHECK(tpm_nv_read(t, TEST_INDEX, after) < 0 && proxy.hit);+ } else if (!strcmp(argv[1], "pcr-read")) {+ intercept(t, TPM2_CC_PCR_Read, CORRUPT);+ CHECK(tpm_pcr_read(t, 9, after) < 0 && proxy.hit);+ } else {+ intercept(t, TPM2_CC_ReadClock, CORRUPT);+ CHECK(tpm_boot_identity(t, &reset, &restart) < 0 && proxy.hit);+ }+ restore();+ tpm_close(t);+ t = NULL;+ CHECK(!tpm_open(&t));+ CHECK(!tpm_nv_read(t, TEST_INDEX, after) && !memcmp(before, after, 32));+ puts("forged readback rejected; live register unchanged");+ } else {+ CHECK(!strcmp(argv[1], "identity"));+ tpm_close(t);+ t = NULL;+ identity.ek_name[2] ^= 1;+ CHECK(tpm_open(&other) == -EACCES && !other);+ identity.ek_name[2] ^= 1;+ identity.ek_name[1] = 0;+ CHECK(tpm_open(&other) == -EACCES && !other);+ identity.ek_name[1] = TPM2_ALG_SHA256;+ identity_error = -ENOENT;+ CHECK(tpm_open(&other) == -ENOENT && !other);+ identity_error = 0;+ enforcing = -EIO;+ CHECK(tpm_open(&other) == -EIO && !other);+ enforcing = 1;+ puts("wrong, missing and unreadable session-key pins refused without fallback");+ }+ ret = 0;+out:+ restore();+ tpm_key_flush(t, &ak);+ tpm_close(t);+ tpm_close(other);+ enforcing = 1;+ identity_error = 0;+ identity.ek_name[1] = TPM2_ALG_SHA256;+ if (defined) {+ t = NULL;+ if (tpm_open(&t) || tpm_nv_undefine(t, TEST_INDEX, NULL, 0))+ ret = 1;+ tpm_close(t);+ }+ return ret;+}diff --git a/testing/helper/tpm-client.c b/testing/helper/tpm-client.cnew file mode 100644index 00000000..3f9734f4--- /dev/null+++ b/testing/helper/tpm-client.c@@ -0,0 +1,12 @@+// SPDX-License-Identifier: BSD-2-Clause+/* Copyright (c) 2026 Authors of shirudo */++#include "tpm-session.h"++int enforcing;++/* Untrusted clients use the default; session tests select guarded states. */+int __wrap_enforcement_active(void)+{+ return enforcing;+}diff --git a/testing/helper/tpm-session.h b/testing/helper/tpm-session.hnew file mode 100644index 00000000..680a06ac--- /dev/null+++ b/testing/helper/tpm-session.h@@ -0,0 +1,13 @@+/* SPDX-License-Identifier: BSD-2-Clause */+/* Copyright (c) 2026 Authors of shirudo */+#ifndef SHIRUDO_TEST_TPM_SESSION_H+#define SHIRUDO_TEST_TPM_SESSION_H++#include "identity.h"++extern int enforcing;++int __wrap_enforcement_active(void);+int __wrap_identity_read(struct identity *out);++#endifdiff --git a/testing/integration-lib.sh b/testing/integration-lib.shindex 198748b3..1e5ff889 100644--- a/testing/integration-lib.sh+++ b/testing/integration-lib.sh@@ -29,6 +29,28 @@ target_guard() {test_skip_all "LSM not attached; run \`shirudo init\` first"}+# TPM startup can sleep before the task reaches its blocking FIFO open.+fifo_release() {+ python3 -c '+import errno, os, sys, time+for _ in range(100):+ try:+ fd = os.open(sys.argv[1], os.O_WRONLY | os.O_NONBLOCK)+ except OSError as error:+ if error.errno != errno.ENXIO:+ raise+ time.sleep(0.1)+ continue+ try:+ os.write(fd, b"x")+ finally:+ os.close(fd)+ break+else:+ raise TimeoutError("task did not open the FIFO within ten seconds")+' "$1"+}+# The executable $SHIRUDO_BIN runs: itself, or the one the runtime image's# wrapper script hands over to.runtime_binary() {diff --git a/util/identity.h b/util/identity.hindex 7a5114af..06f81989 100644--- a/util/identity.h+++ b/util/identity.h@@ -30,6 +30,7 @@ struct identity {__u8 nv_writer_public[TPM_NV_RSA_BYTES];__u8 ak_name[TPM_NAME_LEN];__u32 ak_name_len;+ __u8 ek_name[TPM_NAME_LEN];__s32 dm_verity_ring;__s32 dm_verity_key;__u32 nv_index;@@ -71,7 +72,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) != 584);+BUILD_BUG_ON(sizeof(struct identity) != 620);BUILD_BUG_ON(sizeof(struct task_policy) != 16);/* The bpffs mount init made, which the unmount guard keeps mounted. */diff --git a/util/tpm.c b/util/tpm.cindex 1a489c9b..6eba5804 100644--- a/util/tpm.c+++ b/util/tpm.c@@ -17,6 +17,7 @@#include "config.h"#include "image_config.h"+#include "identity.h"#include "log.h"#include "malloc.h"#include "nv_writer.h"@@ -26,6 +27,58 @@#define EK_CERT_NV_ECC 0x01C0000Au#define NV_READ_CHUNK 512u+/* Reads without an authorization handle require an audit session for HMACs. */+static int session_start(struct tpm *t, TPM2_SE type, ESYS_TR *session)+{+ TPMT_SYM_DEF sym = { .algorithm = TPM2_ALG_NULL };+ TPMA_SESSION attrs = TPMA_SESSION_CONTINUESESSION;+ TSS2_RC ret;++ if (type == TPM2_SE_HMAC)+ attrs |= TPMA_SESSION_AUDIT;+ ret = Esys_StartAuthSession(t->esys, t->session_key.handle, ESYS_TR_NONE,+ ESYS_TR_NONE, ESYS_TR_NONE, ESYS_TR_NONE,+ NULL, type, &sym, TPM2_ALG_SHA256, session);+ if (ret == TSS2_RC_SUCCESS)+ ret = Esys_TRSess_SetAttributes(t->esys, *session, attrs, 0xff);+ if (ret != TSS2_RC_SUCCESS) {+ pr_err("tpm: start salted session: rc=0x%08x", (__u32)ret);+ if (*session != ESYS_TR_NONE) {+ Esys_FlushContext(t->esys, *session);+ *session = ESYS_TR_NONE;+ }+ return -EIO;+ }+ return 0;+}++static int session_setup(struct tpm *t, bool active)+{+ struct identity id = {};+ int ret;++ if (active) {+ ret = identity_read(&id);+ if (ret) {+ pr_err("tpm: frozen identity unreadable: %s", strerror(-ret));+ return ret;+ }+ if (id.ek_name[0] || id.ek_name[1] != TPM2_ALG_SHA256) {+ pr_err("tpm: no frozen session key; trusted reboot required");+ return -EACCES;+ }+ }+ ret = tpm_ek_create(t, false, &t->session_key);+ if (ret)+ return ret;+ if (t->session_key.name_len != TPM_NAME_LEN ||+ (active && memcmp(t->session_key.name, id.ek_name, TPM_NAME_LEN))) {+ pr_err("tpm: not the TPM init bound (session key name differs)");+ return -EACCES;+ }+ return session_start(t, TPM2_SE_HMAC, &t->session);+}+/** Before an authenticated image is active, tests can select a software* TPM. Once active, require a device TCTI. The configured device path@@ -50,20 +103,24 @@ int tpm_tcti(char *buf, size_t size)return n < 0 ? (int)n : 0;}+/* libtss2 debug logs can expose session keys, even during bootstrap. */static int open_tpm(struct tpm **out, bool quiet){char tcti[TPM_TCTI_MAX];+ int active, err;struct tpm *t;TSS2_RC ret;- int err;- /*- * Quiet libtss2's own stderr logging (it screams ERROR on the- * expected "index not yet defined" probe during first-init).- * shirudo logs its own diagnostics via pr_*; an operator who- * sets TSS2_LOG keeps their setting (overwrite = 0).- */- setenv("TSS2_LOG", "all+none", 0);+ active = enforcement_active();+ if (active < 0) {+ pr_err("tpm: cannot determine enforcement state: %s", strerror(-active));+ return active;+ }+ if (setenv("TSS2_LOG", "all+none", 1) || unsetenv("TSS2_LOGFILE")) {+ err = -errno;+ pr_err("tpm: cannot disable library logging: %s", strerror(-err));+ return err;+ }err = tpm_tcti(tcti, sizeof(tcti));if (err) {@@ -78,6 +135,8 @@ static int open_tpm(struct tpm **out, bool quiet)t = xcalloc(1, sizeof(*t));if (!t)return -ENOMEM;+ t->session = ESYS_TR_NONE;+ t->session_key.handle = ESYS_TR_NONE;ret = Tss2_TctiLdr_Initialize(tcti, &t->tcti);if (ret != TSS2_RC_SUCCESS) {if (!quiet)@@ -94,6 +153,11 @@ static int open_tpm(struct tpm **out, bool quiet)xfree(t, sizeof(*t));return -EIO;}+ err = session_setup(t, active);+ if (err) {+ tpm_close(t);+ return err;+ }*out = t;return 0;}@@ -112,13 +176,22 @@ void tpm_close(struct tpm *t){if (!t)return;- if (t->esys)+ if (t->esys) {+ if (t->session != ESYS_TR_NONE)+ Esys_FlushContext(t->esys, t->session);+ tpm_key_flush(t, &t->session_key);Esys_Finalize(&t->esys);+ }if (t->tcti)Tss2_TctiLdr_Finalize(&t->tcti);xfree(t, sizeof(*t));}+void tpm_ek_name(struct tpm *t, __u8 out[TPM_NAME_LEN])+{+ memcpy(out, t->session_key.name, TPM_NAME_LEN);+}+int tpm_nv_set_writer(struct tpm *t,const __u8 seed[TPM_DIGEST_LEN],const __u8 public[TPM_NV_RSA_BYTES])@@ -171,7 +244,7 @@ int tpm_pcr_read(struct tpm *t, __u32 pcr,if (pcr >= 24)return -EINVAL;pcr_selection(1u << pcr, &sel);- ret = Esys_PCR_Read(t->esys, ESYS_TR_NONE, ESYS_TR_NONE, ESYS_TR_NONE,+ ret = Esys_PCR_Read(t->esys, t->session, ESYS_TR_NONE, ESYS_TR_NONE,&sel, &counter, NULL, &values);if (ret != TSS2_RC_SUCCESS) {pr_err("tpm: PCR_Read(%u): rc=0x%08x", pcr, (__u32)ret);@@ -197,7 +270,7 @@ int tpm_pcr_extend(struct tpm *t, __u32 pcr,return -EINVAL;dv.digests[0].hashAlg = TPM2_ALG_SHA256;memcpy(dv.digests[0].digest.sha256, digest, 32);- ret = Esys_PCR_Extend(t->esys, ESYS_TR_PCR0 + pcr, ESYS_TR_PASSWORD,+ ret = Esys_PCR_Extend(t->esys, ESYS_TR_PCR0 + pcr, t->session,ESYS_TR_NONE, ESYS_TR_NONE, &dv);if (ret != TSS2_RC_SUCCESS) {pr_err("tpm: PCR_Extend(%u): rc=0x%08x", pcr, (__u32)ret);@@ -214,7 +287,7 @@ int tpm_boot_identity(struct tpm *t, __u32 *reset,if (!t || !reset || !restart)return -EINVAL;- ret = Esys_ReadClock(t->esys, ESYS_TR_NONE, ESYS_TR_NONE, ESYS_TR_NONE,+ ret = Esys_ReadClock(t->esys, t->session, ESYS_TR_NONE, ESYS_TR_NONE,&info);if (ret != TSS2_RC_SUCCESS) {pr_err("tpm: ReadClock: rc=0x%08x", (__u32)ret);@@ -231,7 +304,7 @@ int tpm_reset_count(struct tpm *t, __u32 *out)TPMS_TIME_INFO *info = NULL;TSS2_RC ret;- ret = Esys_ReadClock(t->esys, ESYS_TR_NONE, ESYS_TR_NONE, ESYS_TR_NONE,+ ret = Esys_ReadClock(t->esys, t->session, ESYS_TR_NONE, ESYS_TR_NONE,&info);if (ret != TSS2_RC_SUCCESS) {pr_err("tpm: ReadClock: rc=0x%08x", (__u32)ret);@@ -246,7 +319,7 @@ static int nv_handle(struct tpm *t, __u32 index, ESYS_TR *out){TSS2_RC ret;- ret = Esys_TR_FromTPMPublic(t->esys, index, ESYS_TR_NONE, ESYS_TR_NONE,+ ret = Esys_TR_FromTPMPublic(t->esys, index, t->session, ESYS_TR_NONE,ESYS_TR_NONE, out);if (rc_is(ret, TPM2_RC_HANDLE))return -ENOENT; /* quiet: undefined is normal */@@ -273,7 +346,7 @@ int tpm_nv_info(struct tpm *t, __u32 index,return 0;if (err)return err;- ret = Esys_NV_ReadPublic(t->esys, nv, ESYS_TR_NONE, ESYS_TR_NONE,+ ret = Esys_NV_ReadPublic(t->esys, nv, t->session, ESYS_TR_NONE,ESYS_TR_NONE, &pub, &name);Esys_TR_Close(t->esys, &nv);if (ret != TSS2_RC_SUCCESS) {@@ -356,7 +429,7 @@ int tpm_nv_define(struct tpm *t, __u32 index,pub.nvPublic.authPolicy.size = 32;memcpy(pub.nvPublic.authPolicy.buffer, policy, 32);pub.nvPublic.dataSize = TPM_NV_DIGEST_LEN;- ret = Esys_NV_DefineSpace(t->esys, ESYS_TR_RH_OWNER, ESYS_TR_PASSWORD,+ ret = Esys_NV_DefineSpace(t->esys, ESYS_TR_RH_OWNER, t->session,ESYS_TR_NONE, ESYS_TR_NONE, &nv_auth, &pub,&nv);owner_auth_clear(t);@@ -382,7 +455,7 @@ int tpm_nv_undefine(struct tpm *t, __u32 index,return err;}ret = Esys_NV_UndefineSpace(t->esys, ESYS_TR_RH_OWNER, nv,- ESYS_TR_PASSWORD, ESYS_TR_NONE,+ t->session, ESYS_TR_NONE,ESYS_TR_NONE);owner_auth_clear(t);if (ret != TSS2_RC_SUCCESS) {@@ -402,7 +475,7 @@ int tpm_nv_read(struct tpm *t, __u32 index, __u8 out[32])err = nv_handle(t, index, &nv);if (err)return err;- ret = Esys_NV_Read(t->esys, nv, nv, ESYS_TR_PASSWORD, ESYS_TR_NONE,+ ret = Esys_NV_Read(t->esys, nv, nv, t->session, ESYS_TR_NONE,ESYS_TR_NONE, TPM_NV_DIGEST_LEN, 0, &data);Esys_TR_Close(t->esys, &nv);if (rc_is(ret, TPM2_RC_NV_UNINITIALIZED))@@ -424,18 +497,7 @@ int tpm_nv_read(struct tpm *t, __u32 index, __u8 out[32])int tpm_policy_session_start(struct tpm *t, ESYS_TR *session){- TPMT_SYM_DEF sym = { .algorithm = TPM2_ALG_NULL };- TSS2_RC ret;-- ret = Esys_StartAuthSession(t->esys, ESYS_TR_NONE, ESYS_TR_NONE,- ESYS_TR_NONE, ESYS_TR_NONE, ESYS_TR_NONE,- NULL, TPM2_SE_POLICY, &sym, TPM2_ALG_SHA256,- session);- if (ret != TSS2_RC_SUCCESS) {- pr_err("tpm: StartAuthSession: rc=0x%08x", (__u32)ret);- return -EIO;- }- return 0;+ return session_start(t, TPM2_SE_POLICY, session);}static void session_flush(struct tpm *t, ESYS_TR session)@@ -518,7 +580,7 @@ static int tpm_writer_primary(struct tpm *t,if (err)return err;ret = Esys_CreatePrimary(t->esys, ESYS_TR_RH_OWNER,- ESYS_TR_PASSWORD, ESYS_TR_NONE, ESYS_TR_NONE,+ t->session, ESYS_TR_NONE, ESYS_TR_NONE,&sensitive, &in_pub, &outside, &creation_pcr,key, &out_pub, NULL, NULL, NULL);owner_auth_clear(t);@@ -611,7 +673,7 @@ static int tpm_writer_sign(struct tpm *t, ESYS_TR key,memcpy(digest.buffer, hash, TPM_DIGEST_LEN);scheme.details.rsassa.hashAlg = TPM2_ALG_SHA256;- ret = Esys_Sign(t->esys, key, ESYS_TR_PASSWORD, ESYS_TR_NONE,+ ret = Esys_Sign(t->esys, key, t->session, ESYS_TR_NONE,ESYS_TR_NONE, &digest, &scheme, &validation, &signature);if (ret != TSS2_RC_SUCCESS) {pr_err("tpm: Sign(NV writer): rc=0x%08x", (__u32)ret);@@ -703,7 +765,7 @@ int tpm_policy_session_finish(struct tpm *t, ESYS_TR session,pr_err("tpm: register policy assertion: rc=0x%08x", (__u32)ret);return -EACCES;}- ret = Esys_PolicyGetDigest(t->esys, session, ESYS_TR_NONE,+ ret = Esys_PolicyGetDigest(t->esys, session, t->session,ESYS_TR_NONE, ESYS_TR_NONE, &digest);if (ret != TSS2_RC_SUCCESS || !digest || digest->size != TPM_DIGEST_LEN ||memcmp(digest->buffer, expected, TPM_DIGEST_LEN)) {@@ -937,7 +999,9 @@ static int endorsement_primary(struct tpm *t,memset(key, 0, sizeof(*key));ret = Esys_CreatePrimary(t->esys, ESYS_TR_RH_ENDORSEMENT,- ESYS_TR_PASSWORD, ESYS_TR_NONE, ESYS_TR_NONE,+ t->session == ESYS_TR_NONE ?+ ESYS_TR_PASSWORD : t->session,+ ESYS_TR_NONE, ESYS_TR_NONE,&sensitive, in_pub, &outside, &creation_pcr,&handle, &out_pub, NULL, NULL, NULL);if (ret != TSS2_RC_SUCCESS) {@@ -1068,7 +1132,7 @@ int tpm_quote(struct tpm *t, const struct tpm_key *ak,memcpy(qual.buffer, nonce, nonce_len);qual.size = (__u16)nonce_len;pcr_selection(pcr_mask, &sel);- ret = Esys_Quote(t->esys, ak->handle, ESYS_TR_PASSWORD, ESYS_TR_NONE,+ ret = Esys_Quote(t->esys, ak->handle, t->session, ESYS_TR_NONE,ESYS_TR_NONE, &qual, &scheme, &sel, "ed, &sig);if (ret != TSS2_RC_SUCCESS) {pr_err("tpm: Quote: rc=0x%08x", (__u32)ret);@@ -1100,7 +1164,7 @@ int tpm_nv_certify(struct tpm *t,err = nv_handle(t, index, &nv);if (err)return err;- ret = Esys_NV_Certify(t->esys, ak->handle, nv, nv, ESYS_TR_PASSWORD,+ ret = Esys_NV_Certify(t->esys, ak->handle, nv, nv, t->session,ESYS_TR_PASSWORD, ESYS_TR_NONE, &qual, &scheme,TPM_NV_DIGEST_LEN, 0, &info, &sig);Esys_TR_Close(t->esys, &nv);@@ -1140,7 +1204,7 @@ int tpm_activate_credential(struct tpm *t,return err;/* The endorsement key's policy: the hierarchy's own authorisation. */ret = Esys_PolicySecret(t->esys, ESYS_TR_RH_ENDORSEMENT, session,- ESYS_TR_PASSWORD, ESYS_TR_NONE, ESYS_TR_NONE,+ t->session, ESYS_TR_NONE, ESYS_TR_NONE,NULL, NULL, NULL, 0, NULL, NULL);if (ret != TSS2_RC_SUCCESS) {pr_err("tpm: PolicySecret(endorsement): rc=0x%08x",@@ -1149,7 +1213,7 @@ int tpm_activate_credential(struct tpm *t,return -EACCES;}ret = Esys_ActivateCredential(t->esys, ak->handle, ek->handle,- ESYS_TR_PASSWORD, session, ESYS_TR_NONE,+ t->session, session, ESYS_TR_NONE,&id, &sec, &cert_info);session_flush(t, session);if (ret != TSS2_RC_SUCCESS) {@@ -1178,7 +1242,7 @@ static int nv_read_all(struct tpm *t, __u32 index, __u8 *out,err = nv_handle(t, index, &nv);if (err)return err;- ret = Esys_NV_ReadPublic(t->esys, nv, ESYS_TR_NONE, ESYS_TR_NONE,+ ret = Esys_NV_ReadPublic(t->esys, nv, t->session, ESYS_TR_NONE,ESYS_TR_NONE, &pub, NULL);if (ret != TSS2_RC_SUCCESS) {Esys_TR_Close(t->esys, &nv);@@ -1196,7 +1260,7 @@ static int nv_read_all(struct tpm *t, __u32 index, __u8 *out,if (want > NV_READ_CHUNK)want = NV_READ_CHUNK;- ret = Esys_NV_Read(t->esys, nv, nv, ESYS_TR_PASSWORD,+ ret = Esys_NV_Read(t->esys, nv, nv, t->session,ESYS_TR_NONE, ESYS_TR_NONE, (UINT16)want,(UINT16)off, &data);if (ret != TSS2_RC_SUCCESS) {diff --git a/util/tpm.h b/util/tpm.hindex 5f410bad..689a3021 100644--- a/util/tpm.h+++ b/util/tpm.h@@ -26,6 +26,7 @@ int tpm_tcti(char *buf, size_t size);int tpm_open(struct tpm **out);int tpm_open_quiet(struct tpm **out);void tpm_close(struct tpm *t);+void tpm_ek_name(struct tpm *t, __u8 out[TPM_NAME_LEN]);int tpm_writer_create(struct tpm *t,const __u8 seed[TPM_DIGEST_LEN],diff --git a/util/tpm_internal.h b/util/tpm_internal.hindex 5d67b323..04f2c6f7 100644--- a/util/tpm_internal.h+++ b/util/tpm_internal.h@@ -9,8 +9,10 @@#include "tpm.h"struct tpm {+ struct tpm_key session_key;TSS2_TCTI_CONTEXT *tcti;ESYS_CONTEXT *esys;+ ESYS_TR session;__u8 writer_seed[TPM_DIGEST_LEN];__u8 writer_public[TPM_NV_RSA_BYTES];bool writer_set;diff --git a/vendor/libbpf/README.md b/vendor/libbpf/README.mdindex 28e2d1a1..bc7dcbcf 100644--- a/vendor/libbpf/README.md+++ b/vendor/libbpf/README.md@@ -31,7 +31,9 @@ of `bpf-deps` fails on the missing symbol; extend the shim.`bpf/gen_loader.c` carries one local change on top of the recordedcommit: `MAX_USED_PROGS` is 64 instead of 32, as required by thekernel-obs package. In addition `gen_loader.c` also supports reusing a-signer-selected map FD supplied through the loader context. `bpf-deps`+signer-selected map FD supplied through the loader context.+`bpf/btf_dump.c` preserves complete native GNU attribute spellings without+wrapping them twice. `bpf-deps`overwrites these files, so re-apply those changes after a refresh untilthey are upstream.diff --git a/vendor/libbpf/bpf/btf_dump.c b/vendor/libbpf/bpf/btf_dump.cindex ea9a34db..b7ac879e 100644--- a/vendor/libbpf/bpf/btf_dump.c+++ b/vendor/libbpf/bpf/btf_dump.c@@ -1023,7 +1023,8 @@ static void btf_dump_emit_decl_tag(struct btf_dump *d, const struct btf_type *t)const char *name = btf_name_of(d, t->name_off);if (btf_kflag(t))- btf_dump_printf(d, " __attribute__((%s))", name);+ btf_dump_printf(d, str_has_pfx(name, "__attribute__(") ?+ " %s" : " __attribute__((%s))", name);elsebtf_dump_printf(d, " __attribute__((btf_decl_tag(\"%s\")))", name);}@@ -1594,7 +1595,8 @@ static void btf_dump_emit_type_chain(struct btf_dump *d,btf_dump_emit_mods(d, decls);name = btf_name_of(d, t->name_off);if (btf_kflag(t))- btf_dump_printf(d, " __attribute__((%s))", name);+ btf_dump_printf(d, str_has_pfx(name, "__attribute__(") ?+ " %s" : " __attribute__((%s))", name);else if (strcmp(name, "arena") == 0)/* the tag denotes a pointer into the BPF arena address space */btf_dump_printf(d, " __attribute__((address_space(1))) __attribute__((btf_type_tag(\"arena\")))");