Skip to content

eBPF-based security platform

proofs: refuse a program count the metadata cannot hold

Daniel Borkmann268a9ca768bf
diff --git a/Documentation/contribute/testing/proof-coverage.rst b/Documentation/contribute/testing/proof-coverage.rst
index 72cfb0e4..96f955ca 100644
--- a/Documentation/contribute/testing/proof-coverage.rst
+++ b/Documentation/contribute/testing/proof-coverage.rst
@@ -616,6 +616,12 @@ or shorter, and "lengths 0 to 6" every input of each of those lengths.
uprobe fields only on a uprobe, kprobe names only on a kprobe
multi program, and device classes, set and within the known
mask, only on XDP
+ * - ``upatch-prog-count``
+ - The program count ``prog_specs_parse()`` takes from the header
+ - Tables of 3, 16, 176 and 336 bytes, any count larger than they
+ hold
+ - Refused before the program table is allocated or an entry read,
+ with nothing returned
* - ``upatch-prog-uprobes``
- What ``prog_specs_parse()`` makes of a uprobe target block
- One program and one record in 226 bytes, the table's program
diff --git a/testing/proofs/cbmc/proofs.list b/testing/proofs/cbmc/proofs.list
index 7185c51f..a0246518 100644
--- a/testing/proofs/cbmc/proofs.list
+++ b/testing/proofs/cbmc/proofs.list
@@ -18,6 +18,7 @@ upatch-name --unwind 33
upatch-signed-sections --refine-arithmetic --unwind 2 --unwindset parse_signed_sections.0:4,parse_decoders.0:0,parse_policy_labels.0:0 LEN=15,16,40,64
upatch-signed-name --refine-arithmetic --unwind 2 --unwindset parse_signed_sections.0:2,parse_decoders.0:2,parse_policy_labels.0:0 LEN=288
upatch-prog-specs --refine-arithmetic --memory-leak-check --malloc-may-fail --malloc-fail-null --unwind 3 --unwindset memchr.0:129,memcmp.0:129,strchr.0:129,strnlen.0:1,strlen.0:1,parse_uprobe_targets.0:0,parse_uprobe_targets.1:0,parse_kprobe_targets.0:0,parse_kprobe_syms.0:0,uprobe_valid.0:1,kprobe_multi_valid.0:1,strcmp.0:1 LEN=3,15,16,176
+upatch-prog-count --unwind 2 LEN=3,16,176,336
upatch-prog-uprobes --refine-arithmetic --max-field-sensitivity-array-size 226 --memory-leak-check --malloc-may-fail --malloc-fail-null --unwind 2 --unwindset memchr.0:129,memcmp.0:129,strchr.0:129,strnlen.0:3,strlen.0:3,parse_uprobe_targets.0:3,parse_kprobe_targets.0:2,parse_kprobe_syms.0:0,kprobe_sym_valid.0:0,kprobe_multi_valid.0:0,strcmp.0:1 LEN=226
upatch-uprobe-targets --memory-leak-check --malloc-may-fail --malloc-fail-null --unwind 2 --unwindset parse_uprobe_targets.0:3,memchr.0:10,strnlen.0:11,strlen.0:11,memcmp.0:129 LEN=50
upatch-prog-kprobes --refine-arithmetic --max-field-sensitivity-array-size 210 --memory-leak-check --malloc-may-fail --malloc-fail-null --unwind 3 --unwindset memchr.0:129,memcmp.0:129,strchr.0:129,strnlen.0:12,strlen.0:12,parse_uprobe_targets.0:1,parse_uprobe_targets.1:0,uprobe_valid.0:1,parse_kprobe_targets.0:2,parse_kprobe_syms.0:4,kprobe_sym_valid.0:7,kprobe_multi_valid.0:4,strcmp.0:7 LEN=206-210
diff --git a/testing/proofs/cbmc/upatch-prog-count.c b/testing/proofs/cbmc/upatch-prog-count.c
new file mode 100644
index 00000000..7390530f
--- /dev/null
+++ b/testing/proofs/cbmc/upatch-prog-count.c
@@ -0,0 +1,39 @@
+// SPDX-License-Identifier: BSD-2-Clause
+/*
+ * Copyright (c) 2026 Authors of shirudo
+ *
+ * prog_specs_parse() of util/upatch.c with the program count of a header
+ * no signature covers, any count larger than the LEN bytes of metadata
+ * hold: it refuses before it allocates the table or reads an entry.
+ */
+
+#include "proof.h"
+#include "../../../util/malloc.c"
+
+/* upatch-prog-specs proves the table that fits; this one never gets one. */
+#define xcalloc table_for_a_count_that_does_not_fit
+static void *table_for_a_count_that_does_not_fit(size_t n, size_t size)
+{
+ __CPROVER_assert(false, "no table for a count the metadata cannot hold");
+ return NULL;
+}
+
+#include "../../../util/upatch.c"
+#undef xcalloc
+
+#define ENTRIES_LEN (LEN - (__s64)sizeof(struct upatch_prog_metadata))
+#define NR_FIT (ENTRIES_LEN < 0 ? 0 : \
+ ENTRIES_LEN / sizeof(struct upatch_prog_entry))
+
+void harness(void)
+{
+ struct prog_spec *specs = (void *)1;
+ __u32 nr_progs, nr_maps;
+ __u8 *metadata;
+ int ret;
+
+ __CPROVER_assume(nr_progs > NR_FIT);
+ metadata = any_bytes(LEN);
+ ret = prog_specs_parse(metadata, LEN, nr_maps, nr_progs, &specs);
+ __CPROVER_assert(ret < 0 && !specs, "refused, with no specs");
+}