Skip to content

eBPF-based security platform

proofs: take upatch-name to the NAME_MAX limit of a pin directory

Daniel Borkmann4f7569b7c8ec
diff --git a/Documentation/contribute/testing/proof-coverage.rst b/Documentation/contribute/testing/proof-coverage.rst
index 79c107eb..84f7539f 100644
--- a/Documentation/contribute/testing/proof-coverage.rst
+++ b/Documentation/contribute/testing/proof-coverage.rst
@@ -603,7 +603,8 @@ or shorter, and "lengths 0 to 6" every input of each of those lengths.
* - ``upatch-name``
- ``upatch_name_valid()``, ``upatch_select()``,
``upatch_prog_name()``
- - Names up to 24 bytes, archive names up to 31
+ - Names up to 24 bytes; names of 250 bytes, any 8 and then
+ letters; archive names up to 31
- Valid exactly for ``[A-Za-z0-9._-]+`` not starting with a dot
whose pin directory name, each dot two bytes, fits ``NAME_MAX``;
an archive entry exactly for a name and ``.upatch``; a program
diff --git a/testing/proofs/cbmc/proofs.list b/testing/proofs/cbmc/proofs.list
index c7e2e96a..ec43e51e 100644
--- a/testing/proofs/cbmc/proofs.list
+++ b/testing/proofs/cbmc/proofs.list
@@ -14,7 +14,7 @@ paths-bpffs-name --unwind 18
upatch-header --unwind 2 --unwindset memchr.0:257
upatch-decoders --unwind 2 --unwindset memchr.0:65,parse_decoders.0:3,harness.0:3
upatch-policy-labels --unwind 3 LEN=0,19,20,4187,4188,4189,8356
-upatch-name --unwind 33
+upatch-name --unwind 33 --unwindset upatch_name_valid.0:251,long_name_valid.1:251
upatch-signed-sections --refine-arithmetic --unwind 2 --unwindset parse_signed_sections.0:4,directory_broken.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,directory_broken.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
diff --git a/testing/proofs/cbmc/upatch-name.c b/testing/proofs/cbmc/upatch-name.c
index 1da1fa5f..52cce46d 100644
--- a/testing/proofs/cbmc/upatch-name.c
+++ b/testing/proofs/cbmc/upatch-name.c
@@ -3,9 +3,10 @@
* Copyright (c) 2026 Authors of shirudo
*
* The upatch names util/upatch.c takes from outside, for every name of up
- * to LEN_MAX bytes: upatch_name_valid() accepts exactly [A-Za-z0-9._-]+
- * not starting with a dot whose pin directory, each dot two bytes, fits
- * NAME_MAX, so no path separator, "." or "..",
+ * to LEN_MAX bytes and every one of LONG_LEN bytes that ends in letters:
+ * upatch_name_valid() accepts exactly [A-Za-z0-9._-]+ not starting with a
+ * dot whose pin directory, each dot two bytes, fits NAME_MAX, so no path
+ * separator, "." or "..",
* upatch_select() exactly the archive names, something then ".upatch",
* and upatch_prog_name() gives the loader program a zero-padded name the
* kernel takes, the header's with every other byte made '_'.
@@ -45,6 +46,32 @@ static void name_valid(void)
__CPROVER_assert(!upatch_name_valid(NULL), "no name is invalid");
}
+/*
+ * A name of LONG_LEN bytes, any LONG_SYMBOLIC of them first and letters
+ * after, whose dots take its pin directory across NAME_MAX.
+ */
+#define LONG_LEN 250
+#define LONG_SYMBOLIC 8
+
+static void long_name_valid(void)
+{
+ char *name = any_bytes(LONG_LEN + 1);
+ size_t i, pin = LONG_LEN;
+ bool chars = true;
+
+ for (i = 0; i < LONG_SYMBOLIC; i++) {
+ __CPROVER_assume(name[i]);
+ chars = chars && name_char(name[i]);
+ pin += name[i] == '.';
+ }
+ for (i = LONG_SYMBOLIC; i < LONG_LEN; i++)
+ name[i] = 'a';
+ name[LONG_LEN] = '\0';
+ __CPROVER_assert(upatch_name_valid(name) ==
+ (name[0] != '.' && chars && pin <= NAME_MAX),
+ "a long name valid exactly while its pin fits");
+}
+
static void archive_name(void)
{
static const char suffix[] = ".upatch";
@@ -93,5 +120,6 @@ void harness(void)
{
prog_name();
name_valid();
+ long_name_valid();
archive_name();
}