Skip to content

eBPF-based security platform

tpm_wire: mask the PCR selection bytes it writes

Daniel Borkmann70fa335e847e
diff --git a/Documentation/contribute/testing/proof-coverage.rst b/Documentation/contribute/testing/proof-coverage.rst
index 3370af99..17cff98c 100644
--- a/Documentation/contribute/testing/proof-coverage.rst
+++ b/Documentation/contribute/testing/proof-coverage.rst
@@ -214,8 +214,9 @@ or shorter, and "lengths 0 to 6" every input of each of those lengths.
256-byte modulus, each spanning exactly the input
* - ``tpm-digest``
- The policy, name and cpHash digests of :src:`util/tpm_wire.c`,
- ``tpm_writer_auth_hash()``
- - Names of any length, SHA-256 as any result
+ the register's policy, ``tpm_writer_auth_hash()``
+ - Names of any length, every PCR mask, up to 24 PCR values, SHA-256
+ as any result
- Each reads only whole inputs and writes only its output; an object
name has a public area of 4 bytes or more; a writer's
authorization takes a nonce of 1 to 64 bytes
@@ -326,9 +327,9 @@ manifest readers, the tree publication and log, the eventlog's lines,
the evidence document beyond its PCRs, the config update record, the
site configuration file, the config image's settings and tree, and the
kernel configuration. The ``.upatch`` reader and the TPM structures are
-covered part by part, as the table shows; what joins those parts, the
-TPM policy that takes a PCR selection and the event encoders of the
-register, which need a model of SHA-256, have no proof.
+covered part by part, as the table shows; what joins those parts and
+the event encoders of the register, which need a model of SHA-256, have
+no proof.
Within the ``.upatch`` reader, the proofs cover its parts but not their
composition: ``upatch_parse()`` and ``upatch_open_memory()`` join the
diff --git a/testing/proofs/cbmc/tpm-digest.c b/testing/proofs/cbmc/tpm-digest.c
index 8e2a61e0..80ec7c34 100644
--- a/testing/proofs/cbmc/tpm-digest.c
+++ b/testing/proofs/cbmc/tpm-digest.c
@@ -3,9 +3,10 @@
* Copyright (c) 2026 Authors of shirudo
*
* What util/tpm_wire.c hands SHA-256, modelled as any result, for every
- * length a caller can pass: the policy digests but PolicyPCR's, the object,
- * NV and qualified names, cpHash and the writer's authorization hash only
- * whole inputs into whole outputs, and a nonce of 1 to 64 bytes.
+ * length a caller can pass: the policy digests, PolicyPCR's for every mask
+ * and the register's for every count of PCR values, the object, NV and
+ * qualified names, cpHash and the writer's authorization hash only whole
+ * inputs into whole outputs, and a nonce of 1 to 64 bytes.
*/
#include "proof.h"
@@ -76,14 +77,20 @@ static void policies(void)
{
__u8 *a = digest(), *b = digest(), *name = any_bytes(TPM_NAME_LEN);
__u8 *prev = digest(), *out = digest(), *pub = any_bytes(384);
- __u32 cc, index, attrs, hierarchy;
+ __u32 cc, index, attrs, hierarchy, mask;
__u16 data_size;
+ size_t n_values;
bool written;
+ __CPROVER_assume(n_values <= 24);
+
if (tpm_policy_nv_written(prev, written, out) ||
tpm_policy_or(a, b, out) || tpm_policy_signed(prev, pub, out) ||
tpm_policy_command_code(prev, cc, out) ||
tpm_register_policy_final(a, b, pub, out) ||
+ tpm_policy_pcr(prev, mask, a, out) ||
+ tpm_register_policy(mask, any_bytes(32 * n_values), n_values, pub,
+ digest(), digest(), out) ||
tpm_nv_name(index, attrs, prev, data_size, name) ||
tpm_qualified_name(hierarchy, name, any_bytes(TPM_NAME_LEN)) ||
tpm_nv_extend_cphash(name, prev, out))
diff --git a/util/tpm_wire.c b/util/tpm_wire.c
index d1007661..a0adad3d 100644
--- a/util/tpm_wire.c
+++ b/util/tpm_wire.c
@@ -131,9 +131,9 @@ tpm_pcr_selection(__u32 pcr_mask,
put_be32(out, 1);
put_be16(out + 4, TPM_ALG_SHA256);
out[6] = TPM_PCR_SELECT_LEN;
- out[7] = (__u8)pcr_mask;
- out[8] = (__u8)(pcr_mask >> 8);
- out[9] = (__u8)(pcr_mask >> 16);
+ out[7] = (__u8)(pcr_mask & 0xff);
+ out[8] = (__u8)(pcr_mask >> 8 & 0xff);
+ out[9] = (__u8)(pcr_mask >> 16 & 0xff);
}
int tpm_policy_pcr(const __u8 prev[32], __u32 pcr_mask,