eBPF-based security platform
proofs: split the uprobe target proof to fit in CI's memory
Daniel Borkmannf7e04bb1709c
diff --git a/Documentation/contribute/testing/proof-coverage.rst b/Documentation/contribute/testing/proof-coverage.rstindex 820da223..a658633d 100644--- a/Documentation/contribute/testing/proof-coverage.rst+++ b/Documentation/contribute/testing/proof-coverage.rst@@ -557,13 +557,23 @@ or shorter, and "lengths 0 to 6" every input of each of those lengths.uprobe fields only on a uprobe, and device classes, set andwithin the known mask, only on XDP* - ``upatch-prog-uprobes``- - The uprobe target records of ``prog_specs_parse()``- - One program and one record in 226 bytes, path and build ID up to- 9 bytes, up to 2 offsets- - An absolute path of its stated length without a NUL, a glob- without ``,`` or ``|``, one offset for a single uprobe, a build ID- of 1 to 64 bytes, offsets non-empty and strictly rising, everything- freed+ - What ``prog_specs_parse()`` makes of a uprobe target block+ - One program and one record in 226 bytes, the table's program+ count and the record's lengths fixed: a path and a build ID of one+ byte, 1 or 2 offsets+ - A uprobe program accepted with its entry valid, a glob without+ ``,`` or ``|``, and the uprobe fields of the record; a refusal of+ the block, or a block that ends before the table, leaves nothing+ allocated+ * - ``upatch-uprobe-targets``+ - ``parse_uprobe_targets()``+ - The 50 bytes after one program in a 226-byte table, path and+ build ID up to 9 bytes, up to 2 offsets, the program's entry any+ uprobe one+ - Reads only the block and changes only the uprobe fields; an+ absolute path of its stated length without a NUL, one offset for a+ single uprobe, a build ID of 1 to 64 bytes, offsets non-empty and+ strictly rising, everything freed* - ``upatch-loader``- ``loader_lddw()``, ``sys_bpf_call()``, ``map_create_slot()``,``map_update_slot()``, ``loader_store_source()``diff --git a/Documentation/security/threat-model.rst b/Documentation/security/threat-model.rstindex 18635faf..fcabc4e2 100644--- a/Documentation/security/threat-model.rst+++ b/Documentation/security/threat-model.rst@@ -984,8 +984,8 @@ test makes the two differ, which takes runtime authority.:Tests: ``t3104``, ``t6117``, ``t6138``:Proofs: ``upatch-header``, ``upatch-signed-sections``,``upatch-signed-name``, ``upatch-name``, ``upatch-prog-specs``,- ``upatch-prog-uprobes``, ``upatch-decoders``,- ``upatch-policy-labels``+ ``upatch-prog-uprobes``, ``upatch-uprobe-targets``,+ ``upatch-decoders``, ``upatch-policy-labels``:Residual: R1, R16.. _tm-t5:diff --git a/testing/proofs/cbmc/ci-skip.list b/testing/proofs/cbmc/ci-skip.listindex 329a9552..c5c5502c 100644--- a/testing/proofs/cbmc/ci-skip.list+++ b/testing/proofs/cbmc/ci-skip.list@@ -8,4 +8,3 @@ bpm-tree-sync-application no result after 7 hours, past 15 GBbpm-tree-sync-pending no result after 7 hours, past 15 GBbpm-tree-sync-walk no result after 7 hours, past 15 GBbpm-tree-recovery-model 76 to 97 minutes, once no result in 2 hours-upatch-prog-uprobes 12 GB at its peakdiff --git a/testing/proofs/cbmc/proofs.list b/testing/proofs/cbmc/proofs.listindex ee5bc68f..5801808c 100644--- a/testing/proofs/cbmc/proofs.list+++ b/testing/proofs/cbmc/proofs.list@@ -17,7 +17,8 @@ upatch-name --unwind 33upatch-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,64upatch-signed-name --refine-arithmetic --unwind 2 --unwindset parse_signed_sections.0:2,parse_decoders.0:2,parse_policy_labels.0:0 LEN=288upatch-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,uprobe_valid.0:1 LEN=3,15,16,176-upatch-prog-uprobes --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,prog_specs_parse.2:3,prog_specs_parse.3:2,uprobe_valid.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 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=50upatch-loader --unwind 50 LEN=4,5,25,49upatch-rodata-btf --refine-arithmetic --object-bits 10 --unwind 16 LEN=4,10,15upatch-btf --unwind 6 --unwindset btf_decl_printable.0:33,btf_name_printable.0:7,btf_unwrap.0:9diff --git a/testing/proofs/cbmc/upatch-prog-specs.c b/testing/proofs/cbmc/upatch-prog-specs.cindex 44be2782..d3ce22f7 100644--- a/testing/proofs/cbmc/upatch-prog-specs.c+++ b/testing/proofs/cbmc/upatch-prog-specs.c@@ -14,6 +14,11 @@#include "../../../util/malloc.c"#include "../../../util/upatch.c"+/* A harness that includes this one may fix bytes of the metadata. */+#ifndef SHAPE_METADATA+#define SHAPE_METADATA(metadata)+#endif+#define ENTRIES_LEN (LEN - (__s64)sizeof(struct upatch_prog_metadata))#define NR_PROGS (ENTRIES_LEN < 0 ? 0 : \ENTRIES_LEN / sizeof(struct upatch_prog_entry))@@ -109,6 +114,7 @@ void harness(void)int ret;metadata = any_bytes(LEN);+ SHAPE_METADATA(metadata);ret = prog_specs_parse(metadata, LEN, nr_maps, nr_progs, &specs);if (ret) {__CPROVER_assert(ret < 0 && !specs, "an error and no specs");diff --git a/testing/proofs/cbmc/upatch-prog-uprobes.c b/testing/proofs/cbmc/upatch-prog-uprobes.cindex f2c88888..1989e7f2 100644--- a/testing/proofs/cbmc/upatch-prog-uprobes.c+++ b/testing/proofs/cbmc/upatch-prog-uprobes.c@@ -2,8 +2,34 @@/** Copyright (c) 2026 Authors of shirudo*- * The attach metadata proof for metadata long enough to hold a uprobe- * target block, which proofs.list runs with the bounds its records need.+ * The attach metadata proof for a table of one program and a uprobe+ * target block, with the table's program count and the record's lengths+ * fixed: upatch-uprobe-targets proves parse_uprobe_targets() for every+ * block, and this one what prog_specs_parse() makes of each result.*/+static void uprobe_record_lengths(void *metadata);+#define SHAPE_METADATA(metadata) uprobe_record_lengths(metadata)+#include "upatch-prog-specs.c"++/*+ * A path and a build ID of one byte and one or two offsets, so that the+ * record ends 8 bytes before the table or at its end. With the lengths+ * alone fixed the proof takes 5.4 GB, and with neither it runs out of the+ * 6 GB CI gives it.+ */+static void uprobe_record_lengths(void *metadata)+{+ struct upatch_uprobe_target *record = (void *)((__u8 *)metadata ++ sizeof(struct upatch_prog_metadata) ++ NR_PROGS * sizeof(struct upatch_prog_entry) ++ sizeof(struct upatch_uprobe_targets));+ struct upatch_prog_metadata *md = metadata;+ bool two_offsets;++ md->nr_progs = cpu_to_le32(NR_PROGS);+ record->path_len = cpu_to_le32(1);+ record->build_id_len = cpu_to_le32(1);+ record->nr_offsets = cpu_to_le32(two_offsets ? 2 : 1);+}diff --git a/testing/proofs/cbmc/upatch-uprobe-targets.c b/testing/proofs/cbmc/upatch-uprobe-targets.cnew file mode 100644index 00000000..32b6be06--- /dev/null+++ b/testing/proofs/cbmc/upatch-uprobe-targets.c@@ -0,0 +1,80 @@+// SPDX-License-Identifier: BSD-2-Clause+/*+ * Copyright (c) 2026 Authors of shirudo+ *+ * parse_uprobe_targets() of util/upatch.c on a uprobe target block of LEN+ * bytes, for the program table prog_specs_parse() hands it: it reads+ * nothing outside the block, leaves what the program entry set as it was,+ * and accepts a record only with an absolute path, a build ID and rising+ * offsets.+ */++#include "proof.h"+#include "../../../util/malloc.c"+#include "../../../util/upatch.c"++/* The fields a program entry sets, which the block leaves alone. */+static void entry_kept(const struct prog_spec *s, const struct prog_spec *e)+{+ __CPROVER_assert(s->role == e->role && s->kind == e->kind &&+ s->device_classes == e->device_classes &&+ s->offset == e->offset && s->target_fd == e->target_fd &&+ !memcmp(s->target, e->target, sizeof(s->target)) &&+ !memcmp(s->map, e->map, sizeof(s->map)),+ "the fields of the program entry unchanged");+}++static void uprobe_valid(const struct prog_spec *s)+{+ __u32 j;++ __CPROVER_assert(s->uprobe_path && s->uprobe_path[0] == '/' &&+ strnlen(s->uprobe_path, s->uprobe_path_len + 1) ==+ s->uprobe_path_len, "an absolute path of its length");+ if (!kind_is_uprobe_multi(s->kind))+ __CPROVER_assert(s->nr_uprobe_offsets == 1, "one offset for a uprobe");+ __CPROVER_assert(s->build_id_len && s->build_id_len <=+ UPATCH_BUILD_ID_MAX, "a build ID");+ __CPROVER_assert(s->nr_uprobe_offsets && s->uprobe_offsets,+ "an offset");+ for (j = 1; j < s->nr_uprobe_offsets; j++)+ __CPROVER_assert(s->uprobe_offsets[j - 1] <+ s->uprobe_offsets[j], "rising offsets");+}++void harness(void)+{+ struct prog_spec entry, *specs;+ const __u8 *block, *pos;+ int ret;++ /*+ * One program of a uprobe kind, as prog_specs_parse() calls this only+ * with a uprobe among its programs: the entry's fields any value, the+ * uprobe fields as xcalloc() left them.+ */+ __CPROVER_assume(kind_has_uprobe_target(entry.kind));+ entry.uprobe_path = NULL;+ entry.uprobe_path_len = 0;+ entry.build_id_len = 0;+ entry.uprobe_offsets = NULL;+ entry.nr_uprobe_offsets = 0;+ entry.target_fd = -1;+ specs = xcalloc(1, sizeof(*specs));+ if (!specs)+ return;+ *specs = entry;++ block = any_bytes(LEN);+ pos = block;+ ret = parse_uprobe_targets(&pos, block + LEN, specs, 1, 1);+ if (ret) {+ __CPROVER_assert(ret < 0, "an error");+ } else {+ __CPROVER_assert(pos >= block && pos <= block + LEN,+ "an end within the block");+ entry_kept(specs, &entry);+ uprobe_valid(specs);+ }+ prog_specs_free(specs, 1);+}