eBPF-based security platform
testing: fuzz the configuration file parsers
Daniel Borkmann39e7eb7c8629
diff --git a/Makefile.shirudo b/Makefile.shirudoindex 3ab4ef25..fa82d6b8 100644--- a/Makefile.shirudo+++ b/Makefile.shirudo@@ -703,6 +703,8 @@ testing/fuzz/fuzz-oci-ref: testing/fuzz/fuzz-oci-ref.c $(FUZZ_BASE) \$(FUZZ_OCI)testing/fuzz/fuzz-registry-auth: testing/fuzz/fuzz-registry-auth.c \$(FUZZ_BASE) $(FUZZ_OCI)+testing/fuzz/fuzz-config: testing/fuzz/fuzz-config.c $(FUZZ_BASE) \+ util/config.c util/io.c util/bpm_source_config.c# A target that reaches static parsers includes their source, which it# then depends on without linking it a second time.diff --git a/testing/fuzz/corpus/config/registry-source b/testing/fuzz/corpus/config/registry-sourcenew file mode 100644index 00000000..fb5cf395--- /dev/null+++ b/testing/fuzz/corpus/config/registry-source@@ -0,0 +1,2 @@+endpoint = oci://registry.example:5000+key_file = /etc/shirudo/bpm/keys/vendor.pemdiff --git a/testing/fuzz/corpus/config/shirudo.conf b/testing/fuzz/corpus/config/shirudo.confnew file mode 100644index 00000000..5a4a290c--- /dev/null+++ b/testing/fuzz/corpus/config/shirudo.conf@@ -0,0 +1,12 @@+# /etc/shirudo/shirudo.conf+eventlog.max_bytes = 1048576+tpm.tcti = device:/dev/tpmrm0+tpm.owner_auth = hex:0011223344556677+map_export.json_path = /var/lib/shirudo/maps.json+map_export.otel_endpoint = https://collector.example:4318+map_export.tenant_id = 6f0c2a4e-1b7d-4c39-9a52-3e8d1f7b9c10+map_export.otel_insecure = false+map_export.otel_retries = 3+map_export.s3_uri = s3://bucket/prefix+map_export.log_record_max_bytes = 65536+map_export.otlp_max_bytes = 4194304diff --git a/testing/fuzz/corpus/config/upatch-tree b/testing/fuzz/corpus/config/upatch-treenew file mode 100644index 00000000..a0e1c3b4--- /dev/null+++ b/testing/fuzz/corpus/config/upatch-tree@@ -0,0 +1,3 @@+# /etc/shirudo/upatch-tree.conf+endpoint = "oci://registry.example:5000/shirudo/trees/prod"+reference = latestdiff --git a/testing/fuzz/fuzz-config.c b/testing/fuzz/fuzz-config.cnew file mode 100644index 00000000..81c2592b--- /dev/null+++ b/testing/fuzz/fuzz-config.c@@ -0,0 +1,41 @@+// SPDX-License-Identifier: BSD-2-Clause+/*+ * Copyright (c) 2026 Authors of shirudo+ *+ * shirudo.conf, and the lines of a registry source and of upatch-tree.conf.+ */++#include <string.h>++#include "bpm_oci.h"+#include "bpm_source_config.h"+#include "config.h"+#include "fuzz.h"++int LLVMFuzzerTestOneInput(const __u8 *data, size_t size)+{+ char endpoint[BPM_MAX_ENDPOINT], reference[BPM_MAX_DIGEST];+ char line[PATH_MAX], copy[PATH_MAX], key_file[BPM_MAX_KEY];+ struct shirudo_config cfg;+ char path[64];+ FILE *fp;+ int fd;++ fd = fuzz_file(data, size, path, sizeof(path));+ if (fd < 0)+ return 0;+ shirudo_config_load_path(&cfg, path);+ /* Read as load_source() and load_tree_config() read their files. */+ fp = fopen(path, "r");+ while (fp && fgets(line, sizeof(line), fp)) {+ memcpy(copy, line, sizeof(line));+ shirudo_bpm_parse_source_line(copy, endpoint, sizeof(endpoint),+ key_file, sizeof(key_file));+ shirudo_bpm_parse_tree_line(line, endpoint, sizeof(endpoint),+ reference, sizeof(reference));+ }+ if (fp)+ fclose(fp);+ close(fd);+ return 0;+}