Skip to content

eBPF-based security platform

tpm: leave a missing TPM to the probes' own report

Daniel Borkmann5afbb3c2d820
diff --git a/builtin-bpm.c b/builtin-bpm.c
index 958d0ec6..8735bf38 100644
--- a/builtin-bpm.c
+++ b/builtin-bpm.c
@@ -1311,13 +1311,6 @@ static bool tree_digest_valid(const char *digest)
return !tree_digest_hex(digest, raw);
}
-static bool tree_tpm_available(void)
-{
- __u8 value[32];
-
- return !chain_read(value);
-}
-
static int tree_fetch_publication(const struct bpm_tree_config *cfg,
struct shirudo_tree_publication *pub,
char *manifest_digest, size_t digest_sz)
@@ -1834,7 +1827,7 @@ static int cmd_bpm_tree_sync(int argc, const char **argv)
tree_sync_report_error("pending_recovery", NULL, rc);
goto out;
}
- tpm_available = tree_tpm_available();
+ tpm_available = chain_bound();
for (int i = 0; i < pub.n_operations; i++) {
struct shirudo_tree_operation *op = &pub.operations[i];
__u8 digest[32], previous[32], next[32];
diff --git a/util/chain.c b/util/chain.c
index a3ef0b36..88352d33 100644
--- a/util/chain.c
+++ b/util/chain.c
@@ -396,6 +396,20 @@ int chain_read(__u8 out[32])
return rc ? -ENODEV : 0;
}
+bool chain_bound(void)
+{
+ struct shirudo_tpm *tpm = NULL;
+ struct tpm_nv_info nv;
+ bool bound;
+
+ if (tpm_open_quiet(&tpm))
+ return false;
+ bound = tpm_nv_info(tpm, SHIRUDO_NV_INDEX, &nv) == 0 &&
+ nv.defined && nv.written;
+ tpm_close(tpm);
+ return bound;
+}
+
int chain_status(struct chain_status *st)
{
struct tpm_nv_info nv;
@@ -406,7 +420,7 @@ int chain_status(struct chain_status *st)
memset(st, 0, sizeof(*st));
st->logged = eventlog_boot_init(&st->init) == 0;
st->rebound = st->logged && st->init.records_epoch > 1;
- rc = tpm_open(&tpm);
+ rc = tpm_open_quiet(&tpm);
if (rc)
return -ENODEV;
st->tpm = true;
diff --git a/util/chain.h b/util/chain.h
index b16ece1d..d952daed 100644
--- a/util/chain.h
+++ b/util/chain.h
@@ -106,6 +106,9 @@ int chain_extend(const __u8 event[SHIRUDO_CHAIN_DIGEST_LEN],
/* The live value; -ENODEV when no register is written this boot. */
int chain_read(__u8 out[SHIRUDO_CHAIN_DIGEST_LEN]);
+/* For a probe: a TPM that does not answer is not logged. */
+bool chain_bound(void);
+
struct chain_status {
bool tpm; /* a TPM answered */
bool defined;
diff --git a/util/tpm.c b/util/tpm.c
index 1eb85ed3..aeff1c68 100644
--- a/util/tpm.c
+++ b/util/tpm.c
@@ -53,7 +53,7 @@ int tpm_tcti(char *buf, size_t size)
return n < 0 ? (int)n : 0;
}
-int tpm_open(struct shirudo_tpm **out)
+static int open_tpm(struct shirudo_tpm **out, bool quiet)
{
char tcti[SHIRUDO_TPM_TCTI_MAX];
struct shirudo_tpm *t;
@@ -70,8 +70,9 @@ int tpm_open(struct shirudo_tpm **out)
err = tpm_tcti(tcti, sizeof(tcti));
if (err) {
- pr_err("tpm: the TCTI is longer than %d bytes",
- SHIRUDO_TPM_TCTI_MAX - 1);
+ if (!quiet)
+ pr_err("tpm: the TCTI is longer than %d bytes",
+ SHIRUDO_TPM_TCTI_MAX - 1);
return err;
}
@@ -80,14 +81,16 @@ int tpm_open(struct shirudo_tpm **out)
return -ENOMEM;
rc = Tss2_TctiLdr_Initialize(tcti, &t->tcti);
if (rc != TSS2_RC_SUCCESS) {
- pr_err("tpm: TctiLdr_Initialize(%s): rc=0x%08x", tcti,
- (__u32)rc);
+ if (!quiet)
+ pr_err("tpm: TctiLdr_Initialize(%s): rc=0x%08x", tcti,
+ (__u32)rc);
xfree(t, sizeof(*t));
return -EIO;
}
rc = Esys_Initialize(&t->esys, t->tcti, NULL);
if (rc != TSS2_RC_SUCCESS) {
- pr_err("tpm: Esys_Initialize: rc=0x%08x", (__u32)rc);
+ if (!quiet)
+ pr_err("tpm: Esys_Initialize: rc=0x%08x", (__u32)rc);
Tss2_TctiLdr_Finalize(&t->tcti);
xfree(t, sizeof(*t));
return -EIO;
@@ -96,6 +99,16 @@ int tpm_open(struct shirudo_tpm **out)
return 0;
}
+int tpm_open(struct shirudo_tpm **out)
+{
+ return open_tpm(out, false);
+}
+
+int tpm_open_quiet(struct shirudo_tpm **out)
+{
+ return open_tpm(out, true);
+}
+
void tpm_close(struct shirudo_tpm *t)
{
if (!t)
diff --git a/util/tpm.h b/util/tpm.h
index a5349835..e6436cf1 100644
--- a/util/tpm.h
+++ b/util/tpm.h
@@ -24,6 +24,7 @@ struct shirudo_tpm;
int tpm_tcti(char *buf, size_t size);
int tpm_open(struct shirudo_tpm **out);
+int tpm_open_quiet(struct shirudo_tpm **out);
void tpm_close(struct shirudo_tpm *t);
int tpm_pcr_read(struct shirudo_tpm *t, __u32 pcr,