eBPF-based security platform
testing: fuzz the eventlog readers
Daniel Borkmann7b8acdbf8099
diff --git a/Makefile.shirudo b/Makefile.shirudoindex 004f6cf0..104af449 100644--- a/Makefile.shirudo+++ b/Makefile.shirudo@@ -717,6 +717,9 @@ testing/fuzz/fuzz-attest: testing/fuzz/fuzz-attest.c $(FUZZ_BASE) \util/config.c util/initrd.c util/version_id.ctesting/fuzz/fuzz-attest: FUZZ_CFLAGS += $(TSS2_CFLAGS)testing/fuzz/fuzz-attest: FUZZ_LIBS += $(TSS2_LIBS)+testing/fuzz/fuzz-eventlog: testing/fuzz/fuzz-eventlog.c $(FUZZ_BASE) \+ util/eventlog.c util/timefmt.c util/seal.c \+ util/io.c util/crypto_openssl.c testing/fuzz/chain.ctesting/fuzz/fuzz-otel: testing/fuzz/fuzz-otel.c $(FUZZ_BASE) \util/upatch_maps_otel.c util/crypto_openssl.c \util/tls_openssl.c util/io.c util/version_id.cdiff --git a/testing/fuzz/corpus/eventlog/init-and-loads b/testing/fuzz/corpus/eventlog/init-and-loadsnew file mode 100644index 00000000..75bf1fdd--- /dev/null+++ b/testing/fuzz/corpus/eventlog/init-and-loads@@ -0,0 +1,3 @@+{"schema":2,"ts":"2026-10-21T14:44:32Z","nv_index":"0x01818E00","alg":"sha256","digest":"ca9f0c66cc9654321c7969fd2b040cea422c4d7235df4c4abf4322b51af27175","type":"init","boot_id":"00000000-0000-4000-8000-000000000000","tpm_reset_count":0,"pcr":9,"pcr_before":"0000000000000000000000000000000000000000000000000000000000000000","phase_pcr":11,"phase_before":"d15b0e8e244e65c40f024e95773f2347ce4ef3ffe6b597c9a14b50bbab6df319","bound_in":"initrd","nv_name":"000b4801e0c99e669864c814bf739f09965d2e4330d6f834c4c9b18a676b337df875","anchor":"nvpcr-init:shirudo:0x1818e00:000b4801e0c99e669864c814bf739f09965d2e4330d6f834c4c9b18a676b337df875","anchor_digest":"a21386a3edd0bf458acc400578c4e6e5b53345347955b0d9ca049ad2fe71f8a1","chain":"c648942d3661a0f5c9295835db07aa68f21cccb7a25b2b354a9cf5fa86129f3d"}+{"schema":2,"ts":"2026-10-21T14:44:32Z","nv_index":"0x01818E00","alg":"sha256","digest":"2861d031c6b6048cfdad0eaa39c16a3092e7518cb86e8a95a5345f63fb66e383","type":"upatch_load","boot_id":"00000000-0000-4000-8000-000000000000","upatch":{"name":"foo"},"chain":"2cf9675aeaf6a85624d46cb74e769c0c599381c59e852e662cf8f11b112e4ff5"}+{"schema":2,"ts":"2026-10-21T14:44:33Z","nv_index":"0x01818E00","alg":"sha256","digest":"ca9f0c66cc9654321c7969fd2b040cea422c4d7235df4c4abf4322b51af27175","type":"init","boot_id":"00000000-0000-4000-8000-000000000000","tpm_reset_count":1,"pcr":9,"pcr_before":"0000000000000000000000000000000000000000000000000000000000000000","phase_pcr":11,"phase_before":"0000000000000000000000000000000000000000000000000000000000000000","bound_in":"root","nv_name":"000b49560ef5b34bc607a5a9c8cd57a29234b691a4caa60d3a55f0b7a59557c466db","anchor":"nvpcr-init:shirudo:0x1818e00:000b49560ef5b34bc607a5a9c8cd57a29234b691a4caa60d3a55f0b7a59557c466db","anchor_digest":"734e24e9a603eec70df616ab5caa78f4db2f8f7351fb585b3f6515c82a72fb8c","chain":"c648942d3661a0f5c9295835db07aa68f21cccb7a25b2b354a9cf5fa86129f3d"}diff --git a/testing/fuzz/fuzz-eventlog.c b/testing/fuzz/fuzz-eventlog.cnew file mode 100644index 00000000..00bb492c--- /dev/null+++ b/testing/fuzz/fuzz-eventlog.c@@ -0,0 +1,65 @@+// SPDX-License-Identifier: BSD-2-Clause+/*+ * Copyright (c) 2026 Authors of shirudo+ *+ * The eventlog as status, attest and init read this boot's records back:+ * the replay of the register, the init record and the lines themselves.+ */++#include <stdlib.h>+#include <string.h>++#include "eventlog.h"+#include "fuzz.h"+#include "malloc.h"++/* A boot ID in the seeds, replaced with the running one. */+static const char seed_boot[] = "00000000-0000-4000-8000-000000000000";+static char boot[64];++static int on_line(const char *line, size_t len, void *ctx)+{+ (*(size_t *)ctx) += len;+ return 0;+}++int LLVMFuzzerInitialize(int *argc, char ***argv)+{+ shirudo_eventlog_boot_id(boot, sizeof(boot));+ if (strlen(boot) != sizeof(seed_boot) - 1)+ abort();+ setenv("SHIRUDO_EVENTLOG_PENDING_PATH", "/nonexistent/eventlog", 1);+ return 0;+}++int LLVMFuzzerTestOneInput(const __u8 *data, size_t size)+{+ struct shirudo_eventlog_init init;+ size_t seen = 0;+ char path[64];+ __u8 root[32];+ char *log, *p;+ int fd;++ log = xmalloc(size + 1);+ if (!log)+ return 0;+ memcpy(log, data, size);+ log[size] = '\0';+ p = log;+ while ((p = memmem(p, size - (size_t)(p - log), seed_boot,+ sizeof(seed_boot) - 1))) {+ memcpy(p, boot, sizeof(seed_boot) - 1);+ p += sizeof(seed_boot) - 1;+ }+ fd = fuzz_file((const __u8 *)log, size, path, sizeof(path));+ xfree(log, size + 1);+ if (fd < 0)+ return 0;+ setenv("SHIRUDO_EVENTLOG_PATH", path, 1);+ shirudo_eventlog_replay(root);+ shirudo_eventlog_boot_init(&init);+ shirudo_eventlog_boot_lines(on_line, &seen);+ close(fd);+ return 0;+}