Skip to content

eBPF-based security platform

testing: fuzz the program metadata of a load upatch

Daniel Borkmanndc4c68d22d24
diff --git a/Makefile.shirudo b/Makefile.shirudo
index 00992241..afd6ac0b 100644
--- a/Makefile.shirudo
+++ b/Makefile.shirudo
@@ -695,6 +695,8 @@ testing/fuzz/fuzz-tree: testing/fuzz/fuzz-tree.c $(FUZZ_BASE) \
util/bpm_tree.c util/crypto_openssl.c util/io.c
testing/fuzz/fuzz-upatch: testing/fuzz/fuzz-upatch.c $(FUZZ_BASE) \
util/upatch.c
+testing/fuzz/fuzz-prog-metadata: testing/fuzz/fuzz-prog-metadata.c \
+ $(FUZZ_BASE) util/upatch.c
testing/fuzz/fuzz-bpm-tar: testing/fuzz/fuzz-bpm-tar.c $(FUZZ_BASE) \
$(FUZZ_PACKAGE)
testing/fuzz/fuzz-oci-http: testing/fuzz/fuzz-oci-http.c $(FUZZ_BASE) \
diff --git a/testing/fuzz/corpus/prog-metadata/load b/testing/fuzz/corpus/prog-metadata/load
new file mode 100644
index 00000000..c5fe6f52
Binary files /dev/null and b/testing/fuzz/corpus/prog-metadata/load differ
diff --git a/testing/fuzz/corpus/prog-metadata/uprobe-kprobe-cgroup b/testing/fuzz/corpus/prog-metadata/uprobe-kprobe-cgroup
new file mode 100644
index 00000000..44d038b9
Binary files /dev/null and b/testing/fuzz/corpus/prog-metadata/uprobe-kprobe-cgroup differ
diff --git a/testing/fuzz/corpus/upatch/uprobe-kprobe-cgroup b/testing/fuzz/corpus/upatch/uprobe-kprobe-cgroup
new file mode 100644
index 00000000..4c9c5288
Binary files /dev/null and b/testing/fuzz/corpus/upatch/uprobe-kprobe-cgroup differ
diff --git a/testing/fuzz/fuzz-prog-metadata.c b/testing/fuzz/fuzz-prog-metadata.c
new file mode 100644
index 00000000..c6010f71
--- /dev/null
+++ b/testing/fuzz/fuzz-prog-metadata.c
@@ -0,0 +1,32 @@
+// SPDX-License-Identifier: BSD-2-Clause
+/*
+ * Copyright (c) 2026 Authors of shirudo
+ *
+ * shirudo_prog_specs_parse() on a load upatch's program metadata, which
+ * the loader signature does not cover.
+ */
+
+#include <endian.h>
+#include <stdint.h>
+#include <string.h>
+
+#include "fuzz.h"
+#include "upatch.h"
+
+int LLVMFuzzerTestOneInput(const __u8 *data, size_t size)
+{
+ struct shirudo_upatch_prog_metadata md;
+ struct shirudo_prog_spec *specs;
+ __u32 nr_progs = 0;
+
+ if (size > UINT32_MAX)
+ return 0;
+ /* The header claims the count the container's header must match. */
+ if (size >= sizeof(md)) {
+ memcpy(&md, data, sizeof(md));
+ nr_progs = le32toh(md.nr_progs);
+ }
+ if (!shirudo_prog_specs_parse(data, (__u32)size, nr_progs, &specs))
+ shirudo_prog_specs_free(specs, nr_progs);
+ return 0;
+}
diff --git a/testing/fuzz/fuzz-upatch.c b/testing/fuzz/fuzz-upatch.c
index f4148e65..7761dd7f 100644
--- a/testing/fuzz/fuzz-upatch.c
+++ b/testing/fuzz/fuzz-upatch.c
@@ -10,6 +10,7 @@
int LLVMFuzzerTestOneInput(const __u8 *data, size_t size)
{
+ struct shirudo_prog_spec *specs;
struct shirudo_upatch u;
char path[64];
int fd;
@@ -18,6 +19,10 @@ int LLVMFuzzerTestOneInput(const __u8 *data, size_t size)
if (fd < 0)
return 0;
if (!shirudo_upatch_open(path, &u)) {
+ if (!shirudo_prog_specs_parse(shirudo_upatch_metadata(&u),
+ u.hdr.metadata_len,
+ u.hdr.nr_progs, &specs))
+ shirudo_prog_specs_free(specs, u.hdr.nr_progs);
shirudo_upatch_is_unload(&u);
if (shirudo_upatch_has_decoders(&u)) {
struct shirudo_upatch_decoder_view d;