Skip to content

eBPF-based security platform

proofs: take kernel-notes to the 64-byte limit of a build ID

Daniel Borkmannec0d8ca32be7
diff --git a/Documentation/contribute/testing/proof-coverage.rst b/Documentation/contribute/testing/proof-coverage.rst
index 4011da76..52b3ea44 100644
--- a/Documentation/contribute/testing/proof-coverage.rst
+++ b/Documentation/contribute/testing/proof-coverage.rst
@@ -1079,10 +1079,12 @@ or shorter, and "lengths 0 to 6" every input of each of those lengths.
``..``; a device as decimal major and minor
* - ``kernel-notes``
- ``kernel_build_id_from_notes()``
- - Notes of 0 to 24, 28, 32, 36 and 40 bytes
- - Reads nothing past the notes; a build ID of 1 to 64 lowercase hex
- digits that is the first GNU build ID note's, or empty, and none
- from a section whose one note is another
+ - Notes of 0 to 24, 28, 32, 36 and 40 bytes; of 80 and 84 bytes
+ with any first note header and name and fixed bytes after them
+ - Reads nothing past the notes; a build ID of 1 to 64 bytes, in 2 to
+ 128 lowercase hex digits, that is the first GNU build ID note's,
+ or empty, none from a section whose one note is another, and none
+ from a first GNU build ID of more than 64 bytes
* - ``kernel-release``
- ``kernel_release_prefix_matches()``
- Releases and prefixes up to 8 bytes
diff --git a/testing/proofs/cbmc/kernel-notes.c b/testing/proofs/cbmc/kernel-notes.c
index 72426578..30ae726e 100644
--- a/testing/proofs/cbmc/kernel-notes.c
+++ b/testing/proofs/cbmc/kernel-notes.c
@@ -4,15 +4,34 @@
*
* kernel_build_id_from_notes() of util/kernel_build_id.c on every note
* section of LEN bytes: it reads nothing outside the section, a refusal
- * leaves an empty string, and a build ID is the lowercase hex of at most
- * 64 bytes, that of the first note when it is the GNU build ID, type 3
- * named "GNU", and none from a section whose one note is anything else.
+ * leaves an empty string, and a build ID is the lowercase hex of 1 to 64
+ * bytes, that of the first note when it is the GNU build ID, type 3 named
+ * "GNU", none from a section whose one note is anything else, and none
+ * from a first GNU build ID of more than 64 bytes.
*/
#include "proof.h"
#include "../../../util/hex.c"
#include "../../../util/kernel_build_id.c"
+/*
+ * Past its first note's header and name a section longer than SYMBOLIC
+ * bytes holds a fixed pattern, there to reach the 64-byte limit with the
+ * descriptor's size still any value.
+ */
+#define SYMBOLIC 40
+
+static __u8 *any_notes(void)
+{
+ __u8 *notes = any_bytes(LEN);
+ size_t i;
+
+ if (LEN > SYMBOLIC)
+ for (i = 16; i < LEN; i++)
+ notes[i] = 0x5a;
+ return notes;
+}
+
static __u32 word(const __u8 *p)
{
__u32 v;
@@ -66,11 +85,19 @@ static void first_note(const __u8 *notes, const char *out)
void harness(void)
{
char out[KERNEL_BUILD_ID_STRING_MAX];
+ __u32 descsz;
__u8 *notes;
size_t i, n;
+ int ret;
- notes = any_bytes(LEN);
- if (kernel_build_id_from_notes(notes, LEN, out)) {
+ notes = any_notes();
+ ret = kernel_build_id_from_notes(notes, LEN, out);
+ descsz = LEN >= 16 ? word(notes + 4) : 0;
+ if (LEN >= 16 && gnu_build_id(notes) && descsz > KERNEL_BUILD_ID_MAX &&
+ descsz <= LEN && 16 + align4(descsz) <= LEN)
+ __CPROVER_assert(ret == -E2BIG,
+ "no build ID of more than 64 bytes");
+ if (ret) {
__CPROVER_assert(!out[0], "a refusal leaves an empty string");
return;
}
diff --git a/testing/proofs/cbmc/proofs.list b/testing/proofs/cbmc/proofs.list
index b32a8d0a..dfe0bd0e 100644
--- a/testing/proofs/cbmc/proofs.list
+++ b/testing/proofs/cbmc/proofs.list
@@ -56,7 +56,7 @@ image-bootstrap-certificates --unwind 64 --max-field-sensitivity-array-size 32 L
image-bootstrap --unwind 10 --unwindset bootstrap_parse.0:2,hex_decode.0:1 --max-field-sensitivity-array-size 32 --slice-formula LEN=0-8
image-path --unwind 11
dm-names --unwind 10 --unwindset dm_name_ok.0:129,name_valid.0:129,long_name.1:129
-kernel-notes --unwind 1 --unwindset kernel_build_id_from_notes.0:5,hex_encode.0:29,strnlen.0:58,harness.0:58,first_note.0:29,memcmp.0:5 LEN=0-24,28,32,36,40
+kernel-notes --unwind 1 --unwindset kernel_build_id_from_notes.0:8,hex_encode.0:65,strnlen.0:130,harness.0:130,first_note.0:65,any_notes.0:85,memcmp.0:5 LEN=0-24,28,32,36,40,80,84
kernel-release --unwind 10
log-escape --unwind 7 LEN=0-5
json-emit-string --unwind 5 --unwindset json_string.0:27,put_string_n.0:5,put_raw.0:7,well_formed.0:27,replaced.0:5,memchr.0:9,memcmp.0:13 LEN=0-4