Skip to content

eBPF-based security platform

testing: fuzz the kernel's records and the binaries uprobes name

Daniel Borkmann1f0d357e122b
diff --git a/Makefile.shirudo b/Makefile.shirudo
index 104af449..ce6af865 100644
--- a/Makefile.shirudo
+++ b/Makefile.shirudo
@@ -720,6 +720,13 @@ 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.c
+testing/fuzz/fuzz-kernel: testing/fuzz/fuzz-kernel.c $(FUZZ_BASE) \
+ util/kmsg.c util/kmodules.c util/kernel_build_id.c \
+ util/format.c util/timefmt.c
+testing/fuzz/fuzz-elf: testing/fuzz/fuzz-elf.c $(FUZZ_BASE) \
+ util/elf_target.c $(LIBBPF_A)
+testing/fuzz/fuzz-elf: FUZZ_CFLAGS += $(LIBELF_CFLAGS)
+testing/fuzz/fuzz-elf: FUZZ_LIBS += $(LIBBPF_A) $(LIBELF_LIBS)
testing/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.c
@@ -749,6 +756,7 @@ testing/fuzz/fuzz-oci-http: FUZZ_INCLUDED := util/bpm_oci.c
testing/fuzz/fuzz-tree-state testing/fuzz/fuzz-kconfig: \
FUZZ_INCLUDED := util/bpm_tree_state.c
testing/fuzz/fuzz-otel: FUZZ_INCLUDED := util/upatch_maps_otel.c
+testing/fuzz/fuzz-kernel: FUZZ_INCLUDED := util/kmsg.c
$(FUZZ_TARGETS): testing/fuzz/fuzz.h
@printf ' FUZZ $@\n'
diff --git a/testing/fuzz/corpus/elf/build-id b/testing/fuzz/corpus/elf/build-id
new file mode 100644
index 00000000..b1bf24a8
Binary files /dev/null and b/testing/fuzz/corpus/elf/build-id differ
diff --git a/testing/fuzz/corpus/kernel/kmsg b/testing/fuzz/corpus/kernel/kmsg
new file mode 100644
index 00000000..70f38f78
--- /dev/null
+++ b/testing/fuzz/corpus/kernel/kmsg
@@ -0,0 +1,2 @@
+6,1234,5678901,-,caller=T1;shirudo: init: register bound in the initrd
+ SUBSYSTEM=tpm
diff --git a/testing/fuzz/corpus/kernel/modules b/testing/fuzz/corpus/kernel/modules
new file mode 100644
index 00000000..08a427ce
--- /dev/null
+++ b/testing/fuzz/corpus/kernel/modules
@@ -0,0 +1,5 @@
+nf_tables 368640 2 nft_chain_nat,nft_compat, Live 0x0000000000000000
+nft_chain_nat 12288 1 - Live 0x0000000000000000
+nft_compat 20480 0 - Live 0x0000000000000000
+x_tables 65536 1 nft_compat, Live 0x0000000000000000
+tpm_crb 20480 0 - Live 0x0000000000000000 (E)
diff --git a/testing/fuzz/corpus/kernel/notes b/testing/fuzz/corpus/kernel/notes
new file mode 100644
index 00000000..e98036ed
Binary files /dev/null and b/testing/fuzz/corpus/kernel/notes differ
diff --git a/testing/fuzz/fuzz-elf.c b/testing/fuzz/fuzz-elf.c
new file mode 100644
index 00000000..086cbf00
--- /dev/null
+++ b/testing/fuzz/fuzz-elf.c
@@ -0,0 +1,26 @@
+// SPDX-License-Identifier: BSD-2-Clause
+/*
+ * Copyright (c) 2026 Authors of shirudo
+ *
+ * shirudo_elf_build_id_fd() on the binary a uprobe target names, which
+ * the unsigned program metadata of a upatch chooses.
+ */
+
+#include "elf_target.h"
+#include "fuzz.h"
+
+int LLVMFuzzerTestOneInput(const __u8 *data, size_t size)
+{
+ __u8 build_id[SHIRUDO_UPATCH_BUILD_ID_MAX];
+ char path[64];
+ __u32 len;
+ int fd;
+
+ fd = fuzz_file(data, size, path, sizeof(path));
+ if (fd < 0)
+ return 0;
+ len = sizeof(build_id);
+ shirudo_elf_build_id_fd(fd, build_id, &len);
+ close(fd);
+ return 0;
+}
diff --git a/testing/fuzz/fuzz-kernel.c b/testing/fuzz/fuzz-kernel.c
new file mode 100644
index 00000000..5e033d14
--- /dev/null
+++ b/testing/fuzz/fuzz-kernel.c
@@ -0,0 +1,37 @@
+// SPDX-License-Identifier: BSD-2-Clause
+/*
+ * Copyright (c) 2026 Authors of shirudo
+ *
+ * What the kernel hands status: a /dev/kmsg record, /proc/modules and the
+ * ELF notes of /sys/kernel/notes.
+ */
+
+#include "fuzz.h"
+#include "kernel_build_id.h"
+#include "kmodules.h"
+#include "kmsg.c"
+
+int LLVMFuzzerTestOneInput(const __u8 *data, size_t size)
+{
+ char build_id[SHIRUDO_KERNEL_BUILD_ID_STRING_MAX];
+ struct shirudo_kmod_set set;
+ char msg[1024], *text;
+ const char *m;
+ __u64 us;
+ size_t n;
+
+ if (!parse_record((const char *)data, size, &us, &m, &n))
+ copy_msg(msg, sizeof(msg), m, n);
+
+ text = xmalloc(size + 1);
+ if (!text)
+ return 0;
+ memcpy(text, data, size);
+ text[size] = '\0';
+ if (!shirudo_kmodules_parse(text, &set))
+ shirudo_kmodules_free(&set);
+ xfree(text, size + 1);
+
+ shirudo_kernel_build_id_from_notes(data, size, build_id);
+ return 0;
+}