Skip to content

eBPF-based security platform

fuzz: read the decoder target's sources from the tree it was built in

Daniel Borkmann3c58b17cfd18
diff --git a/Makefile.shirudo b/Makefile.shirudo
index b0ff3b60..972599c5 100644
--- a/Makefile.shirudo
+++ b/Makefile.shirudo
@@ -1235,7 +1235,8 @@ $(FUZZ_OUT)/fuzz-cms: testing/fuzz/fuzz-cms.c $(FUZZ_BASE) util/keys.c \
$(FUZZ_OUT)/fuzz-decoder: testing/fuzz/fuzz-decoder.c $(FUZZ_BASE) \
util/upatch_decode.c util/upatch.c util/io.c \
util/crypto_openssl.c $(FUZZ_SEAL)
-$(FUZZ_OUT)/fuzz-decoder: FUZZ_CFLAGS += $(LUAJIT_CFLAGS) -DHAVE_LUAJIT
+$(FUZZ_OUT)/fuzz-decoder: FUZZ_CFLAGS += $(LUAJIT_CFLAGS) -DHAVE_LUAJIT \
+ -DFUZZ_SOURCE_TREE='"$(CURDIR)"'
$(FUZZ_OUT)/fuzz-decoder: FUZZ_LIBS += $(LUAJIT_LIBS)
$(FUZZ_OUT)/fuzz-otel: testing/fuzz/fuzz-otel.c $(FUZZ_BASE) \
util/upatch_maps_otel.c util/curl.c \
diff --git a/testing/fuzz/fuzz-decoder.c b/testing/fuzz/fuzz-decoder.c
index e2908d47..a0f65145 100644
--- a/testing/fuzz/fuzz-decoder.c
+++ b/testing/fuzz/fuzz-decoder.c
@@ -7,7 +7,6 @@
* decoders and the fixture that reads fixed records.
*/
-#include <libgen.h>
#include <limits.h>
#include <stdlib.h>
@@ -16,33 +15,34 @@
#include "upatch_decode.c"
static const char * const sources[] = {
- "../../upatches/kernel-obs/decoders/dns.lua",
- "../../upatches/kernel-obs/decoders/exec.lua",
- "../../upatches/kernel-obs/decoders/file.lua",
- "../../upatches/kernel-obs/decoders/listen.lua",
- "../../upatches/kernel-obs/decoders/net.lua",
- "../../upatches/kernel-obs/decoders/priv.lua",
- "../../upatches/kernel-obs/decoders/watch.lua",
- "../../upatches/kernel-obs/decoders/watch_stat.lua",
- "../fixtures/decoders/counters.lua",
+ "upatches/kernel-obs/decoders/dns.lua",
+ "upatches/kernel-obs/decoders/exec.lua",
+ "upatches/kernel-obs/decoders/file.lua",
+ "upatches/kernel-obs/decoders/listen.lua",
+ "upatches/kernel-obs/decoders/net.lua",
+ "upatches/kernel-obs/decoders/priv.lua",
+ "upatches/kernel-obs/decoders/watch.lua",
+ "upatches/kernel-obs/decoders/watch_stat.lua",
+ "testing/fixtures/decoders/counters.lua",
};
static struct upatch_decoder_view views[ARRAY_SIZE(sources)];
-/* The decoders sit beside the target in the tree, wherever it runs from. */
+/*
+ * The decoders are read from the tree the target was built from, which
+ * the build names: the target itself may be built anywhere, AFL++'s in
+ * build/fuzz-afl.
+ */
int LLVMFuzzerInitialize(int *argc, char ***argv)
{
- char self[PATH_MAX], path[PATH_MAX];
+ char path[PATH_MAX];
size_t len;
char *src;
- if (strscpy(self, (*argv)[0], sizeof(self)) < 0)
- abort();
for (size_t i = 0; i < ARRAY_SIZE(sources); i++) {
- if (strsprintf(path, sizeof(path), "%s/%s", dirname(self),
+ if (strsprintf(path, sizeof(path), "%s/%s", FUZZ_SOURCE_TREE,
sources[i]) < 0)
abort();
- strscpy(self, (*argv)[0], sizeof(self));
if (read_file(path, 1 << 20, &src, &len))
abort();
views[i].source = src;