Skip to content

eBPF-based security platform

eventlog: take a set entry's name and payload only from that entry

Daniel Borkmannf745c7facc1d
diff --git a/testing/unit/eventlog.c b/testing/unit/eventlog.c
index 9f23a3b0..d810cd57 100644
--- a/testing/unit/eventlog.c
+++ b/testing/unit/eventlog.c
@@ -290,6 +290,30 @@ static void java_records_count_as_upatch_events(void)
drop_log();
}
+#define PAYLOAD \
+ "00112233445566778899aabbccddeeff00112233445566778899aabbccddeeff"
+
+/* A set entry names its upatch itself, not through another member. */
+static void set_entry_takes_only_its_own_fields(void)
+{
+ static const char init[] =
+ "{\"type\":\"init\",\"upatch\":{\"name\":\"other\","
+ "\"payload_sha256\":\"" PAYLOAD "\"},"
+ "\"set\":[{\"payload_sha256\":\"" PAYLOAD "\"}]}";
+ static const char named[] =
+ "{\"type\":\"init\",\"set\":[{\"name\":\"fix\","
+ "\"payload_sha256\":\"" PAYLOAD "\"}]}";
+ struct seen_upatches s = {};
+
+ EXPECT_EQ(eventlog_upatches_record(init, strlen(init), true,
+ count_upatch, &s), -EINVAL);
+ EXPECT_EQ(s.loads, 0);
+ EXPECT_EQ(eventlog_upatches_record(named, strlen(named), true,
+ count_upatch, &s), 0);
+ EXPECT_EQ(s.loads, 1);
+ EXPECT_STREQ(s.last, "fix");
+}
+
static const struct unit_case cases[] = {
UNIT_CASE(unfinished_append_is_no_record),
UNIT_CASE(nul_in_the_log_is_refused),
@@ -297,6 +321,7 @@ static const struct unit_case cases[] = {
UNIT_CASE(set_counts_in_an_init_record_alone),
UNIT_CASE(upatch_records_name_type_and_direction),
UNIT_CASE(java_records_count_as_upatch_events),
+ UNIT_CASE(set_entry_takes_only_its_own_fields),
{}
};
diff --git a/util/eventlog.c b/util/eventlog.c
index 8a9471b0..1d7a2084 100644
--- a/util/eventlog.c
+++ b/util/eventlog.c
@@ -609,16 +609,19 @@ struct upatches_ctx {
int (*cb)(enum eventlog_upatch_event event, const char *name,
const char *payload_hex, void *ctx);
void *ctx;
+ const struct json_field *entry;
char name[UPATCH_NAME_MAX + 1];
char payload_hex[2 * UPATCH_PAYLOAD_HASH_LEN + 1];
int ret;
};
+/* The buffers are the upatch member's too: an entry names both itself. */
static int upatches_set_entry(void *arg)
{
struct upatches_ctx *u = arg;
- if (!upatch_member_valid(u->name, u->payload_hex))
+ if (!u->entry[0].seen || !u->entry[1].seen ||
+ !upatch_member_valid(u->name, u->payload_hex))
return -EINVAL;
u->ret = u->cb(EVENTLOG_UPATCH_LOAD, u->name, u->payload_hex, u->ctx);
u->name[0] = '\0';
@@ -650,6 +653,7 @@ static int upatches_line(const char *line, size_t len, bool is_init,
};
int ret;
+ u->entry = entry;
u->name[0] = '\0';
u->payload_hex[0] = '\0';
type[0] = '\0';
diff --git a/util/measured.c b/util/measured.c
index ee8d7c62..7e33650a 100644
--- a/util/measured.c
+++ b/util/measured.c
@@ -99,16 +99,21 @@ struct record_fields {
__s64 seq;
struct measured_upatch *set;
size_t n;
+ const struct json_field *entry;
bool init, upatch, key, tree;
};
+/* The buffers are the upatch member's too: an entry names both itself. */
static int record_set_entry(void *arg)
{
struct record_fields *r = arg;
__u32 type;
int ret;
- ret = measured_member_type(r->member_type, &type);
+ if (!r->entry[0].seen || !r->entry[1].seen)
+ ret = -EINVAL;
+ else
+ ret = measured_member_type(r->member_type, &type);
if (!ret)
ret = measured_set_add(r->set, &r->n, MEASURED_MAX, r->name,
r->payload_hex, type);
@@ -157,6 +162,7 @@ static int record_parse(const char *line, size_t len, struct record_fields *r)
{ "tree", JSON_T_OBJECT, NULL, 0, 0, tree, ARRAY_SIZE(tree) },
};
+ r->entry = entry;
if (json_parse(line, len, f, ARRAY_SIZE(f)) || !f[0].seen ||
!f[1].seen)
return -EINVAL;