Skip to content

eBPF-based security platform

attest: take no field of an eventlog record from the one before it

Daniel Borkmann8dac59f04352
diff --git a/testing/unit/attest.c b/testing/unit/attest.c
index 928f47f2..d047d64a 100644
--- a/testing/unit/attest.c
+++ b/testing/unit/attest.c
@@ -120,11 +120,44 @@ static void report_ends_its_last_line_at_any_size(void)
}
}
+/* A record without a digest has none: it takes no digest from the last. */
+static void record_without_digest_is_refused(void)
+{
+ static const __u8 nonce[16] = {
+ 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
+ 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10,
+ };
+ struct attest_expect expect = {
+ .nonce = nonce,
+ .nonce_len = sizeof(nonce),
+ };
+ static const char key[] = "\"digest\":\"";
+ static char doc[8192], report[ATTEST_REPORT_MAX];
+ char *load, *digest = NULL, *at;
+ const char *full;
+ size_t len, cut;
+
+ full = read_evidence(&len);
+ ASSERT_TRUE(len < sizeof(doc));
+ memcpy(doc, full, len);
+ load = strstr(doc, "\"type\":\"upatch_load\"");
+ ASSERT_TRUE(load);
+ for (at = doc; (at = strstr(at, key)) && at < load; at++)
+ digest = at;
+ ASSERT_TRUE(digest);
+ cut = sizeof(key) - 1 + 64 + 2;
+ memmove(digest, digest + cut, len - (size_t)(digest - doc) - cut);
+ len -= cut;
+ EXPECT_EQ(attest_verify(doc, len, &expect, report, sizeof(report)),
+ -EINVAL);
+}
+
static const struct unit_case cases[] = {
UNIT_CASE(pcrs_are_a_list_up_to_23),
UNIT_CASE(pcr_value_is_a_pcr_and_an_equals),
UNIT_CASE(name_digest_is_a_name_and_64_digits),
UNIT_CASE(report_ends_its_last_line_at_any_size),
+ UNIT_CASE(record_without_digest_is_refused),
{}
};
diff --git a/util/attest.c b/util/attest.c
index 71c97d86..c1421ad6 100644
--- a/util/attest.c
+++ b/util/attest.c
@@ -626,6 +626,12 @@ static int on_record(void *ctx)
p->n_recs++;
/* Reset the per-element scratch the next element may not set. */
p->type[0] = '\0';
+ p->digest_hex[0] = '\0';
+ p->pcr_before_hex[0] = '\0';
+ p->phase_before_hex[0] = '\0';
+ p->nv_name_hex[0] = '\0';
+ p->anchor_digest_hex[0] = '\0';
+ p->chain_hex[0] = '\0';
p->upatch_name[0] = '\0';
p->upatch_payload_hex[0] = '\0';
p->tree_id[0] = '\0';