Skip to content

eBPF-based security platform

proofs: hold dm_name_ok() to its rule exactly, to the 127-byte limit

Daniel Borkmann03b0eac90b87
diff --git a/Documentation/contribute/testing/proof-coverage.rst b/Documentation/contribute/testing/proof-coverage.rst
index 84f7539f..4011da76 100644
--- a/Documentation/contribute/testing/proof-coverage.rst
+++ b/Documentation/contribute/testing/proof-coverage.rst
@@ -1073,9 +1073,10 @@ or shorter, and "lengths 0 to 6" every input of each of those lengths.
components is accepted
* - ``dm-names``
- ``dm_name_ok()``, ``dm_device()``
- - Up to 7 bytes
- - A name of 1 to 127 of ``[A-Za-z0-9._-]``, not ``.`` or ``..``; a
- device as decimal major and minor
+ - Up to 7 bytes; names of 127 and 128 bytes, any 7 and then
+ letters
+ - A name exactly when 1 to 127 of ``[A-Za-z0-9._-]``, not ``.`` or
+ ``..``; 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
diff --git a/testing/proofs/cbmc/dm-names.c b/testing/proofs/cbmc/dm-names.c
index cf152814..2d410bd0 100644
--- a/testing/proofs/cbmc/dm-names.c
+++ b/testing/proofs/cbmc/dm-names.c
@@ -3,9 +3,10 @@
* Copyright (c) 2026 Authors of shirudo
*
* dm_name_ok() and dm_device() of util/dm_verity.c on every string of up to
- * LEN_MAX bytes: a device-mapper name is 1 to 127 of [A-Za-z0-9._-] and not
- * "." or "..", and a device is two decimal numbers around a ':' that the
- * device number holds unchanged.
+ * LEN_MAX bytes, and on names of 127 and 128 bytes that end in letters: a
+ * device-mapper name is exactly 1 to 127 of [A-Za-z0-9._-] and not "." or
+ * "..", and a device is two decimal numbers around a ':' that the device
+ * number holds unchanged.
*/
#define PROOF_DEVICE_NUMBERS
@@ -41,18 +42,44 @@ static bool decimal(const char *s, size_t n)
return n;
}
+#define DM_NAME_LEN 127
+
+static bool name_valid(const char *name, size_t n)
+{
+ bool chars = true;
+ size_t i;
+
+ for (i = 0; i < n; i++)
+ chars = chars && name_char(name[i]);
+ return n && n <= DM_NAME_LEN && chars && strcmp(name, ".") &&
+ strcmp(name, "..");
+}
+
+/* Any LEN_MAX bytes first, letters up to len after them. */
+static void long_name(size_t len)
+{
+ char *name = any_bytes(len + 1);
+ size_t i;
+
+ for (i = 0; i < LEN_MAX; i++)
+ __CPROVER_assume(name[i]);
+ for (i = LEN_MAX; i < len; i++)
+ name[i] = 'a';
+ name[len] = '\0';
+ __CPROVER_assert(dm_name_ok(name) == name_valid(name, len),
+ "a long name up to 127 bytes");
+}
+
void harness(void)
{
char *name = any_string(), *token = any_string(), *was;
- size_t n = strlen(name), i, colon;
+ size_t n = strlen(name), colon;
dev_t dev;
- if (dm_name_ok(name)) {
- __CPROVER_assert(n && strcmp(name, ".") && strcmp(name, ".."),
- "a name, not . or ..");
- for (i = 0; i < n; i++)
- __CPROVER_assert(name_char(name[i]), "of [A-Za-z0-9._-]");
- }
+ __CPROVER_assert(dm_name_ok(name) == name_valid(name, n),
+ "1 to 127 of [A-Za-z0-9._-], not . or ..");
+ long_name(DM_NAME_LEN);
+ long_name(DM_NAME_LEN + 1);
n = strlen(token);
was = any_bytes(n + 1);
memcpy(was, token, n + 1);
diff --git a/testing/proofs/cbmc/proofs.list b/testing/proofs/cbmc/proofs.list
index ec43e51e..b32a8d0a 100644
--- a/testing/proofs/cbmc/proofs.list
+++ b/testing/proofs/cbmc/proofs.list
@@ -55,7 +55,7 @@ config-update-follows --unwind 33
image-bootstrap-certificates --unwind 64 --max-field-sensitivity-array-size 32 LEN=0-16
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
+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-release --unwind 10
log-escape --unwind 7 LEN=0-5