eBPF-based security platform
tpm: drop the redundant target-local AK pin
Leonard Cohnen95536358f6cb
diff --git a/Documentation/concepts/background/tpm.rst b/Documentation/concepts/background/tpm.rstindex 52258a52..2a6ea700 100644--- a/Documentation/concepts/background/tpm.rst+++ b/Documentation/concepts/background/tpm.rst@@ -174,13 +174,10 @@ shirudo's :term:`attestation key` (AK) is an ECC NIST P-256 primary key in theendorsement hierarchy that signs with ECDSA and SHA-256. Its attributesare ``fixedTPM``, ``fixedParent``, ``sensitiveDataOrigin``,``userWithAuth``, ``restricted`` and ``sign``, and it has no-authorization value and no policy. ``init`` records its Name in the-:term:`identity map`. Before each write to the register, shirudo creates the-AK again and compares its Name with the recorded one, which detects a-different TPM behind the device path. ``attest verify`` checks that-the AK's public area has these attributes, that the Name matches the-public area and, with ``--ak-name``, that it is the key pinned at-enrollment.+authorization value and no policy. ``shirudo attest`` creates the AK+when it collects evidence. ``attest verify`` checks that the AK's public+area has these attributes, that the Name matches the public area and,+with ``--ak-name``, that it is the key the operator pinned at enrollment.PCRs, banks and extension-------------------------diff --git a/Documentation/concepts/glossary.rst b/Documentation/concepts/glossary.rstindex bcdf7e8c..9a762a2b 100644--- a/Documentation/concepts/glossary.rst+++ b/Documentation/concepts/glossary.rst@@ -165,7 +165,7 @@ 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 and session-establishment key names and the+ key, the endorsement key's name for TPM sessions 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/internals/enforcement.rst b/Documentation/internals/enforcement.rstindex 56b2c5f0..63f4c54c 100644--- a/Documentation/internals/enforcement.rst+++ b/Documentation/internals/enforcement.rst@@ -58,8 +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, the attestation key name and- the ECC endorsement key name used to salt authenticated sessions.+ writer's public modulus and seed, 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 0972378b..6ecfefd0 100644--- a/Documentation/internals/measurement-register.rst+++ b/Documentation/internals/measurement-register.rst@@ -141,9 +141,8 @@ Binding at boot``init`` binds the register once per TPM boot, normally from the initrd,after it has restored the archived upatches (:doc:`boot-flow`):-#. Recreate the attestation key and compare its name with the one frozen- in the identity map, so the register is bound in the TPM ``init``- recorded.+#. Open a salted session using the EK whose name ``init`` froze in the+ identity map. The session authenticates the TPM's successful replies.#. Read the TPM's reset count. When this boot's eventlog already holds an``init`` record for that count, the register was bound: if the indexis written under the recorded name, ``init`` reuses it and adds no@@ -176,8 +175,8 @@ tree root and the events since boot, which the operator can compute.Extending later~~~~~~~~~~~~~~~-Every later extension recreates the attestation key and compares its-name, requires this boot's ``init`` record, recomputes the policy from+Every later extension uses a session authenticated with the pinned EK,+requires this boot's ``init`` record, recomputes the policy fromthe recorded PCR values and writer key, and requires the live index to bewritten, to carry the recorded name and policy, and the TPM's reset countto equal the recorded one. A missing register is ``tpm_error``; adiff --git a/Documentation/security/cryptography.rst b/Documentation/security/cryptography.rstindex d5d333e7..5ce0c89e 100644--- a/Documentation/security/cryptography.rst+++ b/Documentation/security/cryptography.rst@@ -200,8 +200,7 @@ TPM- ECDSA on NIST P-256 with SHA-256; a restricted signing primarywith a fixed template under the endorsement hierarchy- Signs ``TPM2_Quote`` and ``TPM2_NV_Certify`` with the verifier's- nonce, up to 64 bytes. ``init`` records its name in the identity- map.+ nonce, up to 64 bytes. The operator pins its name after enrollment.* - Endorsement key- The TCG default template, RSA-2048 with the exponent 65537 or ECCP-256, with AES-128 in CFB mode as its symmetric algorithmdiff --git a/Documentation/security/threat-model.rst b/Documentation/security/threat-model.rstindex 643a4db5..167f0eaf 100644--- a/Documentation/security/threat-model.rst+++ b/Documentation/security/threat-model.rst@@ -267,11 +267,12 @@ without the protection.the runtime image hands root shirudo's authority.- No.* - A15- - The TPM is a correct TPM 2.0 with RSA-3072 support and an- endorsement hierarchy without an authorization value.- - The register, the NV writer and the attestation key live in it.- - Partly. ``init`` fails without a TPM and when the attestation- key cannot be created under the endorsement hierarchy.+ - The TPM is a correct TPM 2.0 with RSA-3072 and ECC P-256 support+ and an endorsement hierarchy without an authorization value.+ - The register, the NV writer, the session key and the attestation+ key live in it.+ - Partly. ``init`` requires ECC endorsement-key creation, salted+ session setup and RSA-3072 NV writer creation.Assets------@@ -311,7 +312,7 @@ Assets* - Identity map- ``shirudo_bpffs_sb``, pinned as ``identity``- Frozen by ``init``; opened only by tasks with runtime authority- (T13). It holds the keyring serials, the runtime root, the AK+ (T13). It holds the keyring serials, the runtime root, the EKname, the NV writer seed and public key, and the NV index.* - Task marks- ``shirudo_tasks`` task storage, pinned as ``task_authority``@@ -346,8 +347,8 @@ Assets- The private key never leaves the TPM; the seed is not secret(T5).* - Attestation key- - An ECDSA P-256 endorsement-hierarchy primary; its name in the- identity map and with the operator+ - An ECDSA P-256 endorsement-hierarchy primary; its name pinned+ by the operator after enrollment- The TPM; the verifier's pin of its name (T9).* - Eventlog- ``/var/lib/shirudo/eventlog``; the initrd's record at@@ -1302,7 +1303,6 @@ readback. Session failures are not retried as measurements.Initial enrollment trusts the authenticated initrd and the kernel TPMdevice it opens (A1, A6, A8). An unreadable frozen identity, a missing pinor 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 realdriver; sessions do not prevent denial of service by dropping requests.diff --git a/bpf/lib/identity.h b/bpf/lib/identity.hindex 98ad8ff6..f874d667 100644--- a/bpf/lib/identity.h+++ b/bpf/lib/identity.h@@ -19,8 +19,6 @@ struct sb_id {__u8 runtime_root[32];__u8 nv_writer_seed[32];__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;diff --git a/builtin-init.c b/builtin-init.cindex bd75695c..88108b90 100644--- a/builtin-init.c+++ b/builtin-init.c@@ -562,24 +562,17 @@ static int freeze_task_maps(struct bpf_object *obj)* 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)+static int record_ek_name(struct identity *id){- struct tpm_key ak = {};struct tpm *tpm;int ret;ret = tpm_open(&tpm);if (ret)return ret;- ret = tpm_ak_create(tpm, &ak);- 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_ek_name(tpm, id->ek_name);tpm_close(tpm);- return ret;+ return 0;}static int init_lsm(void)@@ -707,9 +700,9 @@ static int init_lsm(void)pr_err("init: create TPM RSA-3072 NV writer: %s", strerror(-err));goto out;}- err = record_attestation_key(&id);+ err = record_ek_name(&id);if (err) {- pr_err("init: record the attestation key name: %s (tpm_error)",+ pr_err("init: record the endorsement key name: %s (tpm_error)",strerror(-err));goto out;}diff --git a/util/chain.c b/util/chain.cindex bcf45642..91a5310c 100644--- a/util/chain.c+++ b/util/chain.c@@ -21,7 +21,6 @@#include "chain.h"#include "config.h"#include "crypto.h"-#include "identity.h"#include "initrd.h"#include "log.h"#include "malloc.h"@@ -244,42 +243,6 @@ static int register_writer(struct tpm *tpm,return ret ? ret : tpm_nv_set_writer(tpm, seed, public);}-/*- * A different attestation key has a different Name, but the Name is- * public and a substitute transport can replay it. Remote evidence- * still needs a valid signature from the pinned key.- */-int chain_tpm_bound(struct tpm *tpm)-{- struct identity id = {};- struct tpm_key ak = {};- int ret;-- ret = enforcement_active();- if (ret <= 0)- return ret;- ret = identity_read(&id);- if (ret) {- pr_err("tpm: frozen identity unreadable: %s", strerror(-ret));- return ret;- }- if (id.ak_name_len != TPM_NAME_LEN) {- pr_err("tpm: no attestation key name on record");- return -EPROTO;- }- ret = tpm_ak_create(tpm, &ak);- if (ret)- return ret;- if (ak.name_len != TPM_NAME_LEN ||- memneq_explicit(ak.name, id.ak_name, TPM_NAME_LEN)) {- pr_err("tpm: not the TPM init bound (attestation key name "- "differs)");- ret = -EACCES;- }- tpm_key_flush(tpm, &ak);- return ret;-}-int chain_init(const __u8 event[32],struct chain_init_info *info){@@ -295,9 +258,6 @@ int chain_init(const __u8 event[32],ret = tpm_open(&tpm);if (ret)return -ENODEV;- ret = chain_tpm_bound(tpm);- if (ret)- goto out;ret = tpm_reset_count(tpm, &info->reset_count);if (ret)goto out;@@ -457,9 +417,6 @@ int chain_extend(const __u8 event[32], __u8 out_chain[32])ret = tpm_open(&tpm);if (ret)return -ENODEV;- ret = chain_tpm_bound(tpm);- if (ret)- goto out;ret = tpm_nv_info(tpm, NV_INDEX, &nv);if (ret)goto out;diff --git a/util/chain.h b/util/chain.hindex 14127d50..1ce0ff50 100644--- a/util/chain.h+++ b/util/chain.h@@ -104,15 +104,6 @@ int chain_extend(const __u8 event[CHAIN_DIGEST_LEN],/* The live value; -ENODEV when no register is written this boot. */int chain_read(__u8 out[CHAIN_DIGEST_LEN]);-struct tpm;--/*- * Whether the TPM behind an open handle is the one init recorded, by- * the name of its attestation key: 0 when it is or enforcement is not- * live, -EACCES for another TPM, -EPROTO without a record.- */-int chain_tpm_bound(struct tpm *tpm);-/* For a probe: a TPM that does not answer is not logged. */bool chain_bound(void);diff --git a/util/identity.h b/util/identity.hindex 06f81989..e44fda71 100644--- a/util/identity.h+++ b/util/identity.h@@ -28,8 +28,6 @@ struct identity {__u8 runtime_root[32];__u8 nv_writer_seed[32];__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;@@ -72,7 +70,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) != 620);+BUILD_BUG_ON(sizeof(struct identity) != 580);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.cindex 465d3325..e978c6d0 100644--- a/util/image_runtime.c+++ b/util/image_runtime.c@@ -26,7 +26,6 @@#include <shirudo/string.h>#include "../builtin.h"-#include "chain.h"#include "config.h"#include "config_image.h"#include "config_update.h"@@ -669,8 +668,6 @@ static int open_update(void)ret = mkdir_owned(CONFIG_UPDATE_DIR);if (!ret)ret = tpm_open(&image.tpm);- if (!ret)- ret = chain_tpm_bound(image.tpm);if (!ret)ret = config_update_open(CONFIG_UPDATE_DIR,&update_ops, &image,