eBPF-based security platform
bpm: refuse a tree state without its TPM projection root
John Fastabend2253d55d2836
diff --git a/Documentation/reference/formats/bpm-formats.rst b/Documentation/reference/formats/bpm-formats.rstindex c20c34a6..6f369271 100644--- a/Documentation/reference/formats/bpm-formats.rst+++ b/Documentation/reference/formats/bpm-formats.rst@@ -538,8 +538,9 @@ not published.``projection_root`` and ``projection_root_tpm``. ``last_seq`` alsomoves past operations whose selector does not match. ``head_seq``and ``segment_base_seq`` are the ``head.seq`` and ``base.seq`` of- the publication the node last synced to; a state without either- is refused.+ the publication the node last synced to. A state without one of+ ``tree_id``, ``last_seq``, the two roots, ``head_seq`` and+ ``segment_base_seq`` is refused.* - ``tree-eventlog``- One JSON object per line and applied operation, with ``schema``(1), ``seq``, ``digest`` (the ``operation_digest``) anddiff --git a/testing/unit/bpm_tree_state.c b/testing/unit/bpm_tree_state.cindex f42b187d..fb331abe 100644--- a/testing/unit/bpm_tree_state.c+++ b/testing/unit/bpm_tree_state.c@@ -498,6 +498,29 @@ static void state_names_its_publication_head_and_base(void)drop_tree();}+#define STATE_TAIL \+ "\"manifest_digest\":\"" PENDING_DIGEST "\",\"head_seq\":7," \+ "\"segment_base_seq\":0}"+#define STATE_NO_TPM_ROOT \+ "{\"schema\":1,\"tree_id\":\"prod\",\"generation\":3,\"last_seq\":5," \+ "\"projection_root\":\"" STATE_ROOT "\","++static void state_needs_both_projection_roots(void)+{+ struct tree_state s;++ use_tree();+ EXPECT_EQ(read_state(STATE_NO_TPM_ROOT STATE_TAIL, &s), -EINVAL);+ EXPECT_EQ(read_state(STATE_NO_TPM_ROOT "\"projection_root_tpm\":\"\","+ STATE_TAIL, &s), -EINVAL);+ EXPECT_EQ(read_state(STATE_NO_TPM_ROOT "\"projection_root_tpm\":\"5c\","+ STATE_TAIL, &s), -EINVAL);+ ASSERT_EQ(read_state(STATE_NO_TPM_ROOT "\"projection_root_tpm\":\""+ STATE_ROOT "\"," STATE_TAIL, &s), 0);+ EXPECT_STREQ(s.projection_root_tpm, STATE_ROOT);+ drop_tree();+}+static const struct unit_case cases[] = {UNIT_CASE(long_line_is_one_line),UNIT_CASE(gzip_config_is_one_whole_member),@@ -510,6 +533,7 @@ static const struct unit_case cases[] = {UNIT_CASE(outcomes_longer_line_is_malformed),UNIT_CASE(outcomes_cover_the_state),UNIT_CASE(state_names_its_publication_head_and_base),+ UNIT_CASE(state_needs_both_projection_roots),{}};diff --git a/util/bpm_tree_state.c b/util/bpm_tree_state.cindex 6baae5f7..96c7c5ba 100644--- a/util/bpm_tree_state.c+++ b/util/bpm_tree_state.c@@ -606,18 +606,10 @@ int tree_state_read(struct tree_state *out)return ret;ret = json_parse((const char *)body, len, f, ARRAY_SIZE(f));if (!ret && (schema != 1 || !f[1].seen || !f[3].seen || !f[4].seen ||- !f[7].seen || !f[8].seen))+ !f[5].seen || !f[7].seen || !f[8].seen))ret = -EINVAL;- if (!ret && !f[5].seen) {- /* State written before the software projection field was added. */- memcpy(out->projection_root_tpm, out->projection_root,- sizeof(out->projection_root_tpm));- }- if (!ret && (strlen(out->projection_root) != 64 ||- !hex32_valid(out->projection_root) ||- (out->projection_root_tpm[0] &&- (strlen(out->projection_root_tpm) != 64 ||- !hex32_valid(out->projection_root_tpm)))))+ if (!ret && (!hex32_valid(out->projection_root) ||+ !hex32_valid(out->projection_root_tpm)))ret = -EINVAL;if (!ret && out->manifest_digest[0] &&sha256_digest_decode(out->manifest_digest, digest))