Skip to content

eBPF-based security platform

proofs: reach the copy of a Beefile array's element

Daniel Borkmann0511e28fc324
diff --git a/Documentation/contribute/testing/proof-coverage.rst b/Documentation/contribute/testing/proof-coverage.rst
index d10c5e7d..1fe52bcc 100644
--- a/Documentation/contribute/testing/proof-coverage.rst
+++ b/Documentation/contribute/testing/proof-coverage.rst
@@ -462,6 +462,12 @@ or shorter, and "lengths 0 to 6" every input of each of those lengths.
- One string or more up to the limit, each terminated, between
brackets; no row past the limit written; a refused array is not
counted
+ * - ``bpm-beefile-array-long``
+ - ``build_parse_string_array()``
+ - One element of 1023 to 1025 bytes with its quotes, around the
+ 1024 its copy holds
+ - Refused, as too long for the copy or for its row, and not
+ counted
* - ``bpm-beefile-fixes``
- ``build_parse_fixes()``, ``bpm_fix_id_ok()``,
``bpm_strings_sort()``
diff --git a/testing/proofs/cbmc/bpm-beefile-array-long.c b/testing/proofs/cbmc/bpm-beefile-array-long.c
new file mode 100644
index 00000000..344c9630
--- /dev/null
+++ b/testing/proofs/cbmc/bpm-beefile-array-long.c
@@ -0,0 +1,12 @@
+// SPDX-License-Identifier: BSD-2-Clause
+/*
+ * Copyright (c) 2026 Authors of shirudo
+ *
+ * build_parse_string_array() of tools/shirudo-build/bpm-build.c on one
+ * element of LEN bytes, its quotes included, around the 1024 bytes of the
+ * copy the parser takes of it: refused, as too long for the copy or for
+ * its row, with nothing counted.
+ */
+
+#define BEEFILE_ARRAY_LONG 1
+#include "bpm-beefile-array.c"
diff --git a/testing/proofs/cbmc/bpm-beefile-array.c b/testing/proofs/cbmc/bpm-beefile-array.c
index c5f5c98d..4350f675 100644
--- a/testing/proofs/cbmc/bpm-beefile-array.c
+++ b/testing/proofs/cbmc/bpm-beefile-array.c
@@ -6,6 +6,8 @@
* build_parse_string_array() of tools/shirudo-build/bpm-build.c takes one
* string or more up to its limit, each terminated in its row, between
* brackets, and counts none of an array it refuses.
+ * bpm-beefile-array-long.c includes this file for an element as long as
+ * the parser's copy of it.
*/
/* As proof.h, before the system headers can include <ctype.h>. */
@@ -38,6 +40,33 @@ static bool blank(char c)
return c == ' ' || (c >= '\t' && c <= '\r');
}
+#ifdef BEEFILE_ARRAY_LONG
+/* The copy build_parse_string_array() takes of an element. */
+#define ITEM_COPY 1024
+
+/*
+ * One element of LEN bytes, its quotes included, of a constant byte:
+ * refused, as too long for the copy or for its row, with nothing counted.
+ */
+void harness(void)
+{
+ char out[1][TREE_STRING_MAX], v[LEN + 3];
+ const size_t len = LEN;
+ size_t i;
+ int n = 0;
+
+ v[0] = '[';
+ v[1] = '"';
+ for (i = 2; i < LEN; i++)
+ v[i] = 'x';
+ v[LEN] = '"';
+ v[LEN + 1] = ']';
+ v[LEN + 2] = '\0';
+ __CPROVER_assert(build_parse_string_array(v, out, 1, &n) ==
+ (len >= ITEM_COPY ? -ENAMETOOLONG : -EINVAL) && !n,
+ "an element too long for its copy or its row refused");
+}
+#else
void harness(void)
{
char out[ROWS][TREE_STRING_MAX], was_byte;
@@ -70,3 +99,4 @@ void harness(void)
__CPROVER_assert(last - first >= 2 && v[first] == '[' &&
v[last - 1] == ']', "between brackets");
}
+#endif
diff --git a/testing/proofs/cbmc/proofs.list b/testing/proofs/cbmc/proofs.list
index 032bef3e..052ee515 100644
--- a/testing/proofs/cbmc/proofs.list
+++ b/testing/proofs/cbmc/proofs.list
@@ -118,6 +118,7 @@ vouch-payload --malloc-may-fail --malloc-fail-null --unwind 3 --unwindset memcm
bpm-tar-writer --unwind 24 --unwindset tar_entry.0:513,bpm_tar_header_ok.0:513,memchr.0:101,memcpy.0:101,strlen.0:101,strnlen.0:101,strcmp.0:102,harness.0:101 --max-field-sensitivity-array-size 512 LEN=1,99,100
bpm-beefile-string --unwind 15 LEN=0-12
bpm-beefile-array --unwind 12 --unwindset build_parse_string_array.4:5
+bpm-beefile-array-long --max-field-sensitivity-array-size 1028 --unwind 12 --unwindset harness.0:1024,memcpy.0:1025,build_parse_string_array.2:1026,build_parse_string.1:257 LEN=1023-1025
bpm-beefile-lines --unwind 14 LEN=0-10
bpm-beefile-tables --unwind 40 LEN=0-7
bpm-beefile-names --unwind 131