eBPF-based security platform
eventlog: canonicalize payload hashes before folding membership
KP Singhfe0a13f6ef0a
diff --git a/Documentation/internals/measurement-register.rst b/Documentation/internals/measurement-register.rstindex 6d4fd87c..736b5c5b 100644--- a/Documentation/internals/measurement-register.rst+++ b/Documentation/internals/measurement-register.rst@@ -368,6 +368,10 @@ failure or a stop between two of them leaves.Figure 3. The steps of a load, an unload and a purge, the span eachholds the register lock, and what an interruption leaves.+The eventlog reader decodes each payload digest and gives the measured set+its lowercase spelling. A pin and a log record with the same digest bytes+therefore agree even when a record uses uppercase hex digits.+A load changes the target before it measures, and an unload or a purgemeasures before it changes it. A load that fails before its event canthen be undone, so no upatch runs unmeasured, and a stopped unloaddiff --git a/testing/unit/eventlog.c b/testing/unit/eventlog.cindex d810cd57..425e2314 100644--- a/testing/unit/eventlog.c+++ b/testing/unit/eventlog.c@@ -12,6 +12,7 @@#include "eventlog.h"#include "io.h"#include "json.h"+#include "measured.h"#include "unit.h"static char dir[4096], log_path[4200], pending_path[4200];@@ -314,7 +315,26 @@ static void set_entry_takes_only_its_own_fields(void)EXPECT_STREQ(s.last, "fix");}+#define MIXED_DIGEST_HEX "Abababababababababababababababababababababababababababababababab"++static void measured_set_uses_the_decoded_payload(void)+{+ static const char log[] =+ "{\"type\":\"init\"}\n"+ "{\"type\":\"upatch_load\",\"upatch\":{\"name\":\"fix\","+ "\"payload_sha256\":\"" MIXED_DIGEST_HEX "\"}}\n";+ struct measured_set *set;++ use_log();+ write_log(log, sizeof(log) - 1);+ ASSERT_EQ(measured_set_log(&set), 0);+ EXPECT_TRUE(measured_holds(set, "fix", DIGEST_HEX));+ measured_set_free(set);+ drop_log();+}+static const struct unit_case cases[] = {+ UNIT_CASE(measured_set_uses_the_decoded_payload),UNIT_CASE(unfinished_append_is_no_record),UNIT_CASE(nul_in_the_log_is_refused),UNIT_CASE(tree_op_measured_this_boot),diff --git a/util/eventlog.c b/util/eventlog.cindex 7ddc0251..f69b2732 100644--- a/util/eventlog.c+++ b/util/eventlog.c@@ -634,16 +634,27 @@ struct upatches_set {const struct json_field *entry;};+/* Pin and archive membership use the same bytes as measurement replay. */+static int upatches_member(struct upatches_ctx *u, enum eventlog_upatch_event event)+{+ __u8 payload[UPATCH_PAYLOAD_HASH_LEN];++ if (!upatch_name_valid(u->name) ||+ hex_decode(u->payload_hex, payload, sizeof(payload)))+ return -EINVAL;+ hex_encode(payload, sizeof(payload), u->payload_hex);+ return u->cb(event, u->name, u->payload_hex, u->ctx);+}+/* The buffers are the upatch member's too: an entry names both itself. */static int upatches_set_entry(void *arg){struct upatches_set *s = arg;struct upatches_ctx *u = s->u;- if (!s->entry[0].seen || !s->entry[1].seen ||- !upatch_member_valid(u->name, u->payload_hex))+ if (!s->entry[0].seen || !s->entry[1].seen)return -EINVAL;- u->ret = u->cb(EVENTLOG_UPATCH_LOAD, u->name, u->payload_hex, u->ctx);+ u->ret = upatches_member(u, EVENTLOG_UPATCH_LOAD);u->name[0] = '\0';u->payload_hex[0] = '\0';return u->ret;@@ -688,10 +699,9 @@ static int upatches_line(const char *line, size_t len, bool is_init,return 0;if (!eventlog_upatch_record_parse(type, &payload_type, &load))return 0;- if (!f[2].seen || !upatch_member_valid(u->name, u->payload_hex))+ if (!f[2].seen)return -EINVAL;- return u->cb(load ? EVENTLOG_UPATCH_LOAD : EVENTLOG_UPATCH_UNLOAD,- u->name, u->payload_hex, u->ctx);+ return upatches_member(u, load ? EVENTLOG_UPATCH_LOAD : EVENTLOG_UPATCH_UNLOAD);}int eventlog_boot_upatches(int (*cb)(enum eventlog_upatch_event event,