Skip to content

eBPF-based security platform

eventlog, measured: keep a set entry's fields out of the caller's context

Daniel Borkmann6fe7c4a043a6
diff --git a/util/eventlog.c b/util/eventlog.c
index 1d7a2084..5ac93869 100644
--- a/util/eventlog.c
+++ b/util/eventlog.c
@@ -609,18 +609,24 @@ 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 fields one line's set entries are parsed into, for that line only. */
+struct upatches_set {
+ struct upatches_ctx *u;
+ const struct json_field *entry;
+};
+
/* 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;
+ struct upatches_set *s = arg;
+ struct upatches_ctx *u = s->u;
- if (!u->entry[0].seen || !u->entry[1].seen ||
+ if (!s->entry[0].seen || !s->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);
@@ -639,7 +645,8 @@ static int upatches_line(const char *line, size_t len, bool is_init,
{ "payload_sha256", JSON_T_STRING, u->payload_hex,
sizeof(u->payload_hex), 0, NULL, 0 },
};
- struct json_array set = { upatches_set_entry, u };
+ struct upatches_set entries = { u, entry };
+ struct json_array set = { upatches_set_entry, &entries };
__u32 payload_type;
char type[32];
bool load;
@@ -653,7 +660,6 @@ 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 7e33650a..2f648eec 100644
--- a/util/measured.c
+++ b/util/measured.c
@@ -99,18 +99,24 @@ struct record_fields {
__s64 seq;
struct measured_upatch *set;
size_t n;
- const struct json_field *entry;
bool init, upatch, key, tree;
};
+/* The fields one record's set entries are parsed into, for that record only. */
+struct record_set {
+ struct record_fields *r;
+ const struct json_field *entry;
+};
+
/* 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;
+ struct record_set *s = arg;
+ struct record_fields *r = s->r;
__u32 type;
int ret;
- if (!r->entry[0].seen || !r->entry[1].seen)
+ if (!s->entry[0].seen || !s->entry[1].seen)
ret = -EINVAL;
else
ret = measured_member_type(r->member_type, &type);
@@ -146,7 +152,8 @@ static int record_parse(const char *line, size_t len, struct record_fields *r)
{ "operation_digest", JSON_T_STRING, r->operation,
sizeof(r->operation), 0, NULL, 0 },
};
- struct json_array set = { record_set_entry, r };
+ struct record_set entries = { r, entry };
+ struct json_array set = { record_set_entry, &entries };
struct json_field f[] = {
{ "type", JSON_T_STRING, r->type, sizeof(r->type), 0, NULL, 0 },
{ "digest", JSON_T_STRING, r->digest_hex, sizeof(r->digest_hex),
@@ -162,7 +169,6 @@ 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;