Skip to content

eBPF-based security platform

fuzz: cover the config image parsers

Daniel Borkmannd0606623facd
diff --git a/Documentation/contribute/testing/test-coverage.rst b/Documentation/contribute/testing/test-coverage.rst
index b3d24fa6..6c942f1c 100644
--- a/Documentation/contribute/testing/test-coverage.rst
+++ b/Documentation/contribute/testing/test-coverage.rst
@@ -520,12 +520,17 @@ run.
- Certificates and detached CMS signatures
* - ``config``
- ``shirudo.conf``, registry sources and ``upatch-tree.conf``
+ * - ``config-update``
+ - The config activation history in the target's state
* - ``decoder``
- Map data a Lua decoder reads
* - ``elf``
- The build ID of a uprobe target binary
* - ``eventlog``
- The eventlog and its replay
+ * - ``image``
+ - Runtime image bootstrap settings and a config image's verity
+ superblock
* - ``json``
- The JSON parser
* - ``kconfig``
@@ -619,7 +624,8 @@ Coverage by area
``t6126``
* - Config images
- ``t4004``, ``t5001`` to ``t5008``, ``t5101`` to ``t5105``,
- ``t6112``, ``t6127``, ``t6130``, ``t6132``. Fuzz: ``config``
+ ``t6112``, ``t6127``, ``t6130``, ``t6132``. Fuzz: ``config``,
+ ``config-update``, ``image``
* - Packages and repositories
- ``t7001``, ``t7002``, ``t7003``, ``t7004``, ``t7005``,
``t7006``. Fuzz:
diff --git a/Makefile.shirudo b/Makefile.shirudo
index 2ba3cd35..c2d65793 100644
--- a/Makefile.shirudo
+++ b/Makefile.shirudo
@@ -1058,6 +1058,15 @@ testing/fuzz/fuzz-registry-auth: testing/fuzz/fuzz-registry-auth.c \
testing/fuzz/fuzz-config: testing/fuzz/fuzz-config.c $(FUZZ_BASE) \
$(FUZZ_CONFIG) util/seal.c util/io.c \
util/bpm_source_config.c
+testing/fuzz/fuzz-image: testing/fuzz/fuzz-image.c $(FUZZ_BASE) \
+ util/image_bootstrap.c util/config_image.c \
+ util/config_measure.c util/crypto_openssl.c \
+ util/io.c util/paths.c \
+ $(FUZZ_SEAL)
+testing/fuzz/fuzz-config-update: testing/fuzz/fuzz-config-update.c \
+ $(FUZZ_BASE) util/config_update.c \
+ util/config_measure.c testing/fuzz/chain.c \
+ util/crypto_openssl.c util/io.c $(FUZZ_SEAL)
FUZZ_TREE_STATE := util/bpm_tree_state.c util/bpm_tree.c util/io.c $(FUZZ_SEAL) \
util/kernel_build_id.c util/kernel_release.c \
util/crypto_openssl.c testing/fuzz/chain.c
@@ -1074,6 +1083,7 @@ testing/fuzz/fuzz-tree-state testing/fuzz/fuzz-kconfig: \
testing/fuzz/fuzz-otel: FUZZ_INCLUDED := util/upatch_maps_otel.c
testing/fuzz/fuzz-serializer: FUZZ_INCLUDED := util/upatch_maps.c
testing/fuzz/fuzz-decoder: FUZZ_INCLUDED := util/upatch_decode.c
+testing/fuzz/fuzz-config-update: FUZZ_INCLUDED := util/config_update.c
$(FUZZ_TARGETS): testing/fuzz/fuzz.h
@printf ' FUZZ $@\n'
diff --git a/testing/fuzz/chain.c b/testing/fuzz/chain.c
index ca119bfb..a1046d69 100644
--- a/testing/fuzz/chain.c
+++ b/testing/fuzz/chain.c
@@ -13,3 +13,12 @@ int sha256_calc(const void *data, size_t len,
{
return sha256_buffer(data, len, out);
}
+
+int chain_fold(__u8 chain[32], const __u8 event[32])
+{
+ __u8 cat[64];
+
+ memcpy(cat, chain, 32);
+ memcpy(cat + 32, event, 32);
+ return sha256_calc(cat, sizeof(cat), chain);
+}
diff --git a/testing/fuzz/corpus/config-update/events b/testing/fuzz/corpus/config-update/events
new file mode 100644
index 00000000..3a6f8a43
--- /dev/null
+++ b/testing/fuzz/corpus/config-update/events
@@ -0,0 +1,2 @@
+{"schema":1,"sequence":1,"reset_count":3,"restart_count":0,"pcr":14,"kind":1,"root_hash":"abababababababababababababababababababababababababababababababab","initial_pcr":"0000000000000000000000000000000000000000000000000000000000000000"}
+{"schema":1,"sequence":2,"reset_count":3,"restart_count":0,"pcr":14,"kind":2,"root_hash":"abababababababababababababababababababababababababababababababab","initial_pcr":"0000000000000000000000000000000000000000000000000000000000000000"}
diff --git a/testing/fuzz/corpus/config-update/state b/testing/fuzz/corpus/config-update/state
new file mode 100644
index 00000000..7746db46
--- /dev/null
+++ b/testing/fuzz/corpus/config-update/state
@@ -0,0 +1 @@
+{"schema":1,"sequence":2,"reset_count":3,"restart_count":0,"pcr":14,"kind":2,"root_hash":"abababababababababababababababababababababababababababababababab","initial_pcr":"0000000000000000000000000000000000000000000000000000000000000000","prefix":"/var/lib/shirudo/images/config","pending":false}
\ No newline at end of file
diff --git a/testing/fuzz/corpus/image/bootstrap b/testing/fuzz/corpus/image/bootstrap
new file mode 100644
index 00000000..7072bf03
--- /dev/null
+++ b/testing/fuzz/corpus/image/bootstrap
@@ -0,0 +1,5 @@
+runtime.image = /run/shirudo/runtime/image
+runtime.root_hash = abababababababababababababababababababababababababababababababab
+config.verification_key = /run/shirudo/runtime/etc/shirudo/config-cert.der
+config.pcr = 14
+config.image = /var/lib/shirudo/images/config
diff --git a/testing/fuzz/corpus/image/superblock b/testing/fuzz/corpus/image/superblock
new file mode 100644
index 00000000..6ea37337
Binary files /dev/null and b/testing/fuzz/corpus/image/superblock differ
diff --git a/testing/fuzz/fuzz-config-update.c b/testing/fuzz/fuzz-config-update.c
new file mode 100644
index 00000000..72424169
--- /dev/null
+++ b/testing/fuzz/fuzz-config-update.c
@@ -0,0 +1,62 @@
+// SPDX-License-Identifier: BSD-2-Clause
+/*
+ * Copyright (c) 2026 Authors of shirudo
+ *
+ * The config activation history the target keeps in its state: one
+ * record as the state file and as an event holds it, and the events file
+ * as the replay reads it, line by line.
+ */
+
+#include <fcntl.h>
+#include <stdlib.h>
+
+#include "fuzz.h"
+
+#include <shirudo/string.h>
+
+#include "config_update.c"
+
+static char dir[4096];
+static int dir_fd = -1;
+
+static void remove_dir(void)
+{
+ unlinkat(dir_fd, "events", 0);
+ rmdir(dir);
+}
+
+int LLVMFuzzerInitialize(int *argc, char ***argv)
+{
+ const char *tmp = getenv("TMPDIR");
+
+ if (strsprintf(dir, sizeof(dir), "%s/shirudo-fuzz-config-update-XXXXXX",
+ tmp && tmp[0] ? tmp : "/tmp") < 0 || !mkdtemp(dir))
+ abort();
+ dir_fd = open(dir, O_RDONLY | O_DIRECTORY | O_CLOEXEC);
+ if (dir_fd < 0 || atexit(remove_dir))
+ abort();
+ return 0;
+}
+
+int LLVMFuzzerTestOneInput(const __u8 *data, size_t size)
+{
+ struct config_update update = { .dir_fd = dir_fd, .lock_fd = -1 };
+ struct config_update_record record, last;
+ __u8 value[32];
+ int fd;
+
+ record_decode((const char *)data, size, true, &record);
+ record_decode((const char *)data, size, false, &record);
+ fd = openat(dir_fd, "events", O_WRONLY | O_CREAT | O_TRUNC | O_CLOEXEC,
+ 0600);
+ if (fd < 0)
+ return 0;
+ if (write_complete(fd, data, size)) {
+ close(fd);
+ return 0;
+ }
+ close(fd);
+ events_scan(&update, &last, value, NULL, false, NULL, NULL);
+ events_scan(&update, &last, value, NULL, true, NULL, NULL);
+ return 0;
+}
diff --git a/testing/fuzz/fuzz-image.c b/testing/fuzz/fuzz-image.c
new file mode 100644
index 00000000..566e01f6
--- /dev/null
+++ b/testing/fuzz/fuzz-image.c
@@ -0,0 +1,28 @@
+// SPDX-License-Identifier: BSD-2-Clause
+/*
+ * Copyright (c) 2026 Authors of shirudo
+ *
+ * The bootstrap settings of a runtime image, as the initial image and as
+ * a later one carries them, and the verity superblock of a config image.
+ */
+
+#include "fuzz.h"
+#include "config_image.h"
+#include "image_bootstrap.h"
+
+int LLVMFuzzerTestOneInput(const __u8 *data, size_t size)
+{
+ struct image_bootstrap boot;
+ struct config_image image;
+ char path[64];
+ int fd;
+
+ fd = fuzz_file(data, size, path, sizeof(path));
+ if (fd < 0)
+ return 0;
+ image_bootstrap_read_fd(fd, &boot, true);
+ image_bootstrap_read_fd(fd, &boot, false);
+ config_image_read_header(fd, &image);
+ close(fd);
+ return 0;
+}