Skip to content

eBPF-based security platform

proofs: keep attach metadata parsing within the CI memory cap

Andrea Lattuada2af56b86a83c
diff --git a/Documentation/contribute/testing/proof-coverage.rst b/Documentation/contribute/testing/proof-coverage.rst
index b5465edd..3caaadc9 100644
--- a/Documentation/contribute/testing/proof-coverage.rst
+++ b/Documentation/contribute/testing/proof-coverage.rst
@@ -578,8 +578,12 @@ or shorter, and "lengths 0 to 6" every input of each of those lengths.
strictly rising, everything freed
* - ``upatch-prog-kprobes``
- The kprobe multi target records of ``prog_specs_parse()``
- - One program and one record in 206 to 210 bytes, 2 to 6 bytes of
- names
+ - Arbitrary tables of 206 to 210 bytes, one program, 2 to 6 bytes
+ of names, every allocation allowed to fail. Allocation requests
+ dispatch to the original allocator at the same constant extent:
+ one program, a buffer of 2 to 6 bytes or 1 to 3 symbol pointers;
+ a request outside those bounds fails an assertion, as does an
+ attempt to allocate a uprobe path, whose payload cannot fit
- At least one name, each terminated inside the record's buffer,
the names strictly rising, everything freed
* - ``upatch-loader``
diff --git a/testing/proofs/cbmc/proofs.list b/testing/proofs/cbmc/proofs.list
index ba4371bd..64cdce27 100644
--- a/testing/proofs/cbmc/proofs.list
+++ b/testing/proofs/cbmc/proofs.list
@@ -17,9 +17,9 @@ 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-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 LEN=226
+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 --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
+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
upatch-loader --unwind 50 LEN=4,5,25,49
upatch-rodata-btf --refine-arithmetic --object-bits 10 --unwind 16 LEN=4,10,15
upatch-btf --unwind 6 --unwindset btf_decl_printable.0:33,btf_name_printable.0:7,btf_unwrap.0:9
diff --git a/testing/proofs/cbmc/upatch-prog-kprobes.c b/testing/proofs/cbmc/upatch-prog-kprobes.c
index 6fe3711e..68e70cd1 100644
--- a/testing/proofs/cbmc/upatch-prog-kprobes.c
+++ b/testing/proofs/cbmc/upatch-prog-kprobes.c
@@ -2,9 +2,56 @@
/*
* Copyright (c) 2026 Authors of shirudo
*
- * The attach metadata proof for metadata long enough to hold a kprobe
- * multi target block, which proofs.list runs with the bounds its records
- * need.
+ * The attach metadata parser on arbitrary one-program tables large
+ * enough for a kprobe multi block, with exact constant-size allocations
+ * for every request these table lengths permit.
*/
+#include <stddef.h>
+
+static void *kprobe_malloc(size_t size);
+static void *kprobe_calloc(size_t nmemb, size_t size);
+static char *kprobe_strndup(const char *s, size_t len);
+#define PROOF_XMALLOC kprobe_malloc
+#define PROOF_XCALLOC kprobe_calloc
+#define PROOF_XSTRNDUP kprobe_strndup
+
#include "upatch-prog-specs.c"
+
+static void *kprobe_malloc(size_t size)
+{
+ if (size == 2)
+ return xmalloc(2);
+ if (size == 3)
+ return xmalloc(3);
+ if (size == 4)
+ return xmalloc(4);
+ if (size == 5)
+ return xmalloc(5);
+ if (size == 6)
+ return xmalloc(6);
+ __CPROVER_assert(false, "a symbol buffer of 2 to 6 bytes");
+ return NULL;
+}
+
+static void *kprobe_calloc(size_t nmemb, size_t size)
+{
+ if (nmemb == 1 && size == sizeof(struct prog_spec))
+ return xcalloc(1, sizeof(struct prog_spec));
+ if (size == sizeof(const char *)) {
+ if (nmemb == 1)
+ return xcalloc(1, sizeof(const char *));
+ if (nmemb == 2)
+ return xcalloc(2, sizeof(const char *));
+ if (nmemb == 3)
+ return xcalloc(3, sizeof(const char *));
+ }
+ __CPROVER_assert(false, "one program or 1 to 3 symbol pointers");
+ return NULL;
+}
+
+static char *kprobe_strndup(const char *s, size_t len)
+{
+ __CPROVER_assert(false, "no uprobe payload fits these metadata lengths");
+ return NULL;
+}
diff --git a/testing/proofs/cbmc/upatch-prog-specs.c b/testing/proofs/cbmc/upatch-prog-specs.c
index 26bb1d7f..0c1d9177 100644
--- a/testing/proofs/cbmc/upatch-prog-specs.c
+++ b/testing/proofs/cbmc/upatch-prog-specs.c
@@ -13,7 +13,25 @@
#include "proof.h"
#include "../../../util/malloc.c"
+#ifdef PROOF_XMALLOC
+#define xmalloc PROOF_XMALLOC
+#endif
+#ifdef PROOF_XCALLOC
+#define xcalloc PROOF_XCALLOC
+#endif
+#ifdef PROOF_XSTRNDUP
+#define xstrndup PROOF_XSTRNDUP
+#endif
#include "../../../util/upatch.c"
+#ifdef PROOF_XMALLOC
+#undef xmalloc
+#endif
+#ifdef PROOF_XCALLOC
+#undef xcalloc
+#endif
+#ifdef PROOF_XSTRNDUP
+#undef xstrndup
+#endif
/* A harness that includes this one may fix bytes of the metadata. */
#ifndef SHAPE_METADATA