Skip to content

eBPF-based security platform

attest: tell a missing TPM from an unbound register

Daniel Borkmann10a263ffab14
diff --git a/builtin-attest.c b/builtin-attest.c
index 41535044..86657b23 100644
--- a/builtin-attest.c
+++ b/builtin-attest.c
@@ -748,9 +748,14 @@ static int cmd_attest_evidence(int argc, const char **argv)
rc = attest_evidence(nonce, nonce_len, mask,
challenge_path ? &challenge : NULL, &doc,
&len, &cap);
+ if (rc == -ENXIO) {
+ pr_err("attest: no TPM answered (tpm_error)");
+ return 1;
+ }
if (rc == -ENODEV) {
- pr_err("attest: no bound register (tpm_error); run shirudo "
- "init first");
+ pr_err("attest: register 0x%08X is not bound this boot "
+ "(tpm_error); run shirudo init first",
+ SHIRUDO_NV_INDEX);
return 1;
}
if (rc == -EKEYREJECTED) {
diff --git a/testing/t0034-register.sh b/testing/t0034-register.sh
index 33460b84..36051043 100644
--- a/testing/t0034-register.sh
+++ b/testing/t0034-register.sh
@@ -38,6 +38,20 @@ ENTER=$(py "import hashlib; print(hashlib.sha256(b\"enter-initrd\").hexdigest())
LEAVE=$(py "import hashlib; print(hashlib.sha256(b\"leave-initrd\").hexdigest())")
PHASE=$(sha "$Z$ENTER")
+test_expect_success 'attest names a register that is not bound yet' '
+ ! $S attest --nonce=00 >/dev/null 2>"$WORK/attest-unbound.err" &&
+ grep -qx "attest: register 0x01818E00 is not bound this boot (tpm_error); run shirudo init first" \
+ "$WORK/attest-unbound.err" &&
+ [ "$(grep -c "not bound" "$WORK/attest-unbound.err")" = 1 ]
+'
+
+test_expect_success 'attest tells no TPM apart from an unbound register' '
+ ! SHIRUDO_TPM_TCTI=device:/nonexistent/tpm $S attest --nonce=00 \
+ >/dev/null 2>"$WORK/attest-notpm.err" &&
+ grep -qx "attest: no TPM answered (tpm_error)" "$WORK/attest-notpm.err" &&
+ ! grep -q "shirudo init" "$WORK/attest-notpm.err"
+'
+
test_expect_success 'init binds the register to PCRs 9 and 11 from the initrd and anchors in PCR 9' '
./$R pcr-extend 11 "$ENTER" | grep -qx "rc=0" &&
[ "$(./$R pcr 11)" = "$PHASE" ] &&
diff --git a/util/attest.c b/util/attest.c
index 9c9a3f60..3594f3a8 100644
--- a/util/attest.c
+++ b/util/attest.c
@@ -172,13 +172,11 @@ int attest_evidence(const __u8 *nonce, size_t nonce_len,
rc = tpm_open(&tpm);
if (rc)
- return -ENODEV;
+ return -ENXIO;
rc = tpm_nv_info(tpm, SHIRUDO_NV_INDEX, &nv);
if (rc)
goto out;
if (!nv.defined || !nv.written) {
- pr_err("attest: register 0x%08x is not bound this boot; run "
- "shirudo init first", SHIRUDO_NV_INDEX);
rc = -ENODEV;
goto out;
}
diff --git a/util/attest.h b/util/attest.h
index bc71dc1b..18e0a1d8 100644
--- a/util/attest.h
+++ b/util/attest.h
@@ -45,7 +45,8 @@ int attest_challenge_read(const char *path,
/*
* Target side. The buffer is xmalloc'd to *cap and NUL-terminated;
- * -EKEYREJECTED when the TPM refuses the challenge.
+ * -ENXIO when no TPM answers, -ENODEV when no register is bound this
+ * boot, -EKEYREJECTED when the TPM refuses the challenge.
*/
int attest_evidence(const __u8 *nonce, size_t nonce_len,
__u32 pcr_mask,