Skip to content

eBPF-based security platform

init: refuse to measure unreadable tree state as no tree

Daniel Borkmann9c722dd5d78f
diff --git a/Documentation/reference/cli/init.rst b/Documentation/reference/cli/init.rst
index 24efa3aa..0b9c8eb0 100644
--- a/Documentation/reference/cli/init.rst
+++ b/Documentation/reference/cli/init.rst
@@ -61,7 +61,9 @@ Description
boot's register was bound is refused as tampered.
#. It binds the measurement register under PCRs 9 and 11 and records one
init event that covers the certificate set, the restored upatches and
- the upatch tree root.
+ the upatch tree root. Without tree state the root is 64 zeros; tree
+ state that cannot be read or parsed stops ``init`` before the
+ register is bound, rather than being measured as no tree.
#. It completes the config ``BOOT`` event.
Measurement: the config PCR receives one ``BOOT`` event per boot. The
diff --git a/builtin-init.c b/builtin-init.c
index c4eced17..0b15fb84 100644
--- a/builtin-init.c
+++ b/builtin-init.c
@@ -1180,14 +1180,20 @@ static bool phase_unmeasured(const __u8 pcr[32])
return true;
}
-static void tree_root_at_boot(__u8 out[32])
+static int tree_root_at_boot(__u8 out[32])
{
struct tree_state s = {};
+ int ret;
memset(out, 0, 32);
- if (tree_state_read(&s) == 0 &&
- hex_decode(s.projection_root, out, 32) != 0)
+ ret = tree_state_read(&s);
+ if (ret == -ENOENT)
+ return 0;
+ if (!ret)
+ ret = hex_decode(s.projection_root, out, 32);
+ if (ret)
memset(out, 0, 32);
+ return ret;
}
/*
@@ -1242,7 +1248,12 @@ static int chain_extend_init(struct measured_upatch *set, size_t n)
* || tree_root), the formula the operator's
* predictor shares (util/attest.c).
*/
- tree_root_at_boot(tree_root);
+ ret = tree_root_at_boot(tree_root);
+ if (ret) {
+ pr_err("chain: cannot read the upatch tree state %s: %s",
+ BPM_TREE_STATE_PATH, strerror(-ret));
+ return ret;
+ }
ret = chain_init_event(cert_sha, set, n, tree_root, set_digest,
init_digest);