eBPF-based security platform
status: size the JSON document by the loaded upatches
Daniel Borkmann5ddfa6b64be4
diff --git a/builtin-status.c b/builtin-status.cindex b71e77a2..5199efd9 100644--- a/builtin-status.c+++ b/builtin-status.c@@ -707,10 +707,12 @@ int cmd_status(int argc, const char **argv)/** The events[] dump re-emits the log, so size the buffer* from it with headroom for the fixed fields and the- * optional sections; the clamp below keeps it under- * SHIRUDO_JSON_MAX_BYTES.+ * optional sections; every loaded upatch adds a row whose+ * strings JSON escaping can grow sixfold. The clamp below+ * keeps it under SHIRUDO_JSON_MAX_BYTES.*/- json_cap = 16384;+ json_cap = 16384 + (size_t)n_ups *+ (6 * sizeof(struct shirudo_upatch_table_row) + 256);if (include_eventlog && ev_rc == 0)json_cap = 65536 + 3 * (size_t)ev_bytes;if (include_kernel_log)@@ -1007,6 +1009,7 @@ int cmd_status(int argc, const char **argv)if (e.err) {fprintf(stderr, "status: json encode failed: %s\n",strerror(-e.err));+ ret = 1;} else {if (otel && otel_endpoint_configured) {__s64 refused = tamper_rc == 0 ?diff --git a/testing/fixtures/status-many.bpf.c b/testing/fixtures/status-many.bpf.cnew file mode 100644index 00000000..11ef13b5--- /dev/null+++ b/testing/fixtures/status-many.bpf.c@@ -0,0 +1,13 @@+// SPDX-License-Identifier: GPL-2.0 OR BSD-2-Clause+#include "vmlinux.h"+#include <bpf/bpf_helpers.h>+#include <bpf/bpf_tracing.h>++char _license[] SEC("license") = "Dual BSD/GPL";++/* A raw tracepoint takes any number of programs; a trampoline does not. */+SEC("tp_btf/sched_process_free")+int BPF_PROG(shirudo_test_many)+{+ return 0;+}diff --git a/testing/functional/upatch/t3108-status-many.sh b/testing/functional/upatch/t3108-status-many.shnew file mode 100644index 00000000..1928a5a6--- /dev/null+++ b/testing/functional/upatch/t3108-status-many.sh@@ -0,0 +1,51 @@+#!/bin/sh+# SPDX-License-Identifier: BSD-2-Clause+# Copyright (c) 2026 Authors of shirudo+#+# t3108 -- status --json reports every loaded upatch however many there+# are: with eighty loaded, more than a fixed-size document holds, the+# report still parses, lists all of them and exits 0.++cd "$(dirname "$0")/../.."+. ./integration-lib.sh+target_guard+command -v python3 >/dev/null 2>&1 || test_skip_all "no python3"++MANY=${SHIRUDO_TEST_FIXTURES_DIR:?target fixture directory is not set}/many+[ -s "$MANY/shirudo-test-many-80.upatch" ] ||+ test_skip_all "missing the many fixtures"+W=$(mktemp -d) || exit 1++cleanup()+{+ for f in "$MANY"/shirudo-test-many-*.unload.upatch; do+ n=$(basename "$f" .unload.upatch)+ [ -e "/run/shirudo/bpffs/upatches/$n" ] || continue+ "$SHIRUDO_BIN" upatch unload "$f" --no-precheck >/dev/null 2>&1 ||+ echo "cleanup: cannot unload $n" >&2+ done+ rm -rf "$W"+}+trap cleanup EXIT HUP INT TERM++test_expect_success 'eighty upatches load' '+ failed=0 &&+ for f in "$MANY"/shirudo-test-many-??.upatch; do+ "$SHIRUDO_BIN" upatch load "$f" --no-precheck >/dev/null 2>&1 ||+ failed=$((failed + 1))+ done &&+ [ "$failed" -eq 0 ]+'++test_expect_success 'status --json lists every loaded upatch' '+ "$SHIRUDO_BIN" status --json >"$W/status.json" &&+ python3 - "$W/status.json" <<"PY"+import json, sys+with open(sys.argv[1], encoding="utf-8") as stream:+ loaded = json.load(stream)["upatches_loaded"]+many = [u["name"] for u in loaded if u["name"].startswith("shirudo-test-many-")]+assert len(many) == 80, many+PY+'++test_donediff --git a/testing/vm/build-bundle.sh b/testing/vm/build-bundle.shindex 617e006a..39626aa8 100755--- a/testing/vm/build-bundle.sh+++ b/testing/vm/build-bundle.sh@@ -677,6 +677,29 @@ done-o "$TMP_DIR/fixtures/shirudo-test-basic-mismatch.unload.upatch" \--key "$FIXTURE_WORK/trusted/signing_key.pem" \--cert "$FIXTURE_WORK/trusted/cert.der"+# Enough loaded upatches to outgrow the fixed part of a status document.+mkdir -p "$TMP_DIR/fixtures/many"+for i in $(seq -w 1 80); do+ name="shirudo-test-many-$i"+ (+ cd "$REPO_ROOT"+ "$REPO_ROOT/tools/shirudo-build/shirudo-build" \+ "$REPO_ROOT/testing/fixtures/status-many.bpf.c" \+ -o "$TMP_DIR/fixtures/many/$name.upatch" \+ --name "$name" --vmlinux "$REPO_ROOT/vendor/linux/vmlinux.h" \+ --extra-cflags "-I$REPO_ROOT/vendor/libbpf" \+ --key "$FIXTURE_WORK/trusted/signing_key.pem" \+ --cert "$FIXTURE_WORK/trusted/cert.der" >/dev/null+ )+ payload="$($REPO_ROOT/shirudo upatch info \+ "$TMP_DIR/fixtures/many/$name.upatch" --json |+ python3 -c 'import json,sys; print(json.load(sys.stdin)["payload_sha256"])')"+ "$REPO_ROOT/tools/shirudo-build/shirudo-build" --unload \+ "$name" --payload-sha256 "$payload" \+ -o "$TMP_DIR/fixtures/many/$name.unload.upatch" \+ --key "$FIXTURE_WORK/trusted/signing_key.pem" \+ --cert "$FIXTURE_WORK/trusted/cert.der" >/dev/null+done"$REPO_ROOT/tools/shirudo-build/shirudo-build" --unload \shirudo-test-marker --payload-sha256 "$marker_payload" \-o "$TMP_DIR/fixtures/shirudo-test-marker.unload.upatch" \