Skip to content

eBPF-based security platform

proofs: give sysinfo-image root hashes of 63 and 65 bytes too

Daniel Borkmanndc4385989956
diff --git a/Documentation/contribute/testing/proof-coverage.rst b/Documentation/contribute/testing/proof-coverage.rst
index 52b3ea44..3026fd00 100644
--- a/Documentation/contribute/testing/proof-coverage.rst
+++ b/Documentation/contribute/testing/proof-coverage.rst
@@ -1180,7 +1180,8 @@ or shorter, and "lengths 0 to 6" every input of each of those lengths.
``cmdline_image_root()``
- Values and texts of 0 to 6 bytes; values of 255, 256 and 257
bytes; command lines of a word, ``usrhash=`` and ``roothash=``,
- each there or not, with hashes of any 64 bytes but blanks
+ each there or not, with hashes of any 63, 64 or 65 bytes but
+ blanks
- A value taken exactly when one or more printable bytes remain
after one pair of quotes and the escapes of double quotes, at
most 255 of them; of a key's lines the last; the root
diff --git a/testing/proofs/cbmc/proofs.list b/testing/proofs/cbmc/proofs.list
index dfe0bd0e..c620be39 100644
--- a/testing/proofs/cbmc/proofs.list
+++ b/testing/proofs/cbmc/proofs.list
@@ -152,5 +152,5 @@ bpm-tree-state-pending --unwind 5 --unwindset upatch_name_valid.0:10,strnlen.0:7
bpm-tree-state-match --unwind 4 --unwindset read_config_stream.0:7,read_config_stream.1:9,read_config_stream.2:9,read_config_stream.3:9,read_config_stream.4:9,read_text_line.0:9,strlen.0:9,strchr.0:9,strnlen.0:9,memcpy.0:9,memcmp.0:26 LEN=0-3
bpm-tree-state-options --unwind 4
keepalive-pack --unwind 9 --unwindset strcmp.0:18,keepalive_mask.0:514,mask.0:514,mask.1:514 LEN=0-9,512,513
-sysinfo-image --unwind 8 --unwindset strcmp.0:8,memcmp.0:10,os_release_unquote.0:258,cmdline_image_root.0:8,cmdline_image_root.1:76,cmdline_image_root.2:5,strlen.0:11,all_hex.0:65,image_root_normalise.0:65,command_line.0:65,command_line.1:65 LEN=0-6
+sysinfo-image --unwind 8 --unwindset strcmp.0:8,memcmp.0:10,os_release_unquote.0:258,cmdline_image_root.0:8,cmdline_image_root.1:76,cmdline_image_root.2:5,strlen.0:11,all_hex.0:66,image_root_normalise.0:65,command_line.0:66,command_line.1:65 LEN=0-6
xdp-attrs --unwind 12 --unwindset memchr.0:129 LEN=0-12,16,20,24,28,32,40
diff --git a/testing/proofs/cbmc/sysinfo-image.c b/testing/proofs/cbmc/sysinfo-image.c
index bb913933..10465969 100644
--- a/testing/proofs/cbmc/sysinfo-image.c
+++ b/testing/proofs/cbmc/sysinfo-image.c
@@ -4,7 +4,8 @@
*
* The image identity parsers of util/sysinfo.c, whose values a keepalive
* carries: an os-release value of LEN bytes unquoted, the last assignment
- * of a key in a text of LEN bytes, and the root a command line names.
+ * of a key in a text of LEN bytes, and the root a command line names, for
+ * hashes of 64 bytes and, at LEN 1 and 2, of 63 and 65.
*/
#include "proof.h"
@@ -100,9 +101,9 @@ static void last_assignment(void)
__CPROVER_assert(!strcmp(out, want), "the last assignment's value");
}
-static bool all_hex(const char *h)
+static bool all_hex(const char *h, size_t n)
{
- for (size_t i = 0; i < HASH_LEN; i++)
+ for (size_t i = 0; i < n; i++)
if (!isxdigit((__u8)h[i]))
return false;
return true;
@@ -116,18 +117,20 @@ static size_t put(char *dst, size_t at, const char *src, size_t n)
/*
* roothash= wins over usrhash= whether or not it is a hash, and the root
- * is the one it names in lowercase, or none. A value holds no separator,
- * so that the arguments are those the line was built from.
+ * is the one it names in lowercase, when it is 64 digits, or none. A value
+ * holds no separator, so that the arguments are those the line was built
+ * from.
*/
-static void command_line(void)
+static void command_line(size_t hash_len)
{
- char root[HASH_LEN], usr[HASH_LEN], out[SYSINFO_IMAGE_ROOT_MAX];
- char line[2 + 8 + HASH_LEN + 1 + 9 + HASH_LEN];
+ char root[HASH_LEN + 1], usr[HASH_LEN + 1];
+ char line[2 + 8 + HASH_LEN + 1 + 1 + 9 + HASH_LEN + 1];
+ char out[SYSINFO_IMAGE_ROOT_MAX];
bool junk, has_usr, has_root;
const char *named;
size_t at = 0;
- for (size_t i = 0; i < HASH_LEN; i++)
+ for (size_t i = 0; i < hash_len; i++)
__CPROVER_assume(!cmdline_space(root[i]) &&
!cmdline_space(usr[i]));
@@ -135,16 +138,16 @@ static void command_line(void)
at = put(line, at, "x ", 2);
if (has_usr) {
at = put(line, at, "usrhash=", 8);
- at = put(line, at, usr, HASH_LEN);
+ at = put(line, at, usr, hash_len);
at = put(line, at, " ", 1);
}
if (has_root) {
at = put(line, at, "roothash=", 9);
- at = put(line, at, root, HASH_LEN);
+ at = put(line, at, root, hash_len);
}
cmdline_image_root(line, at, out);
named = has_root ? root : has_usr ? usr : NULL;
- if (!named || !all_hex(named)) {
+ if (!named || hash_len != HASH_LEN || !all_hex(named, hash_len)) {
__CPROVER_assert(!out[0], "no root");
return;
}
@@ -160,6 +163,8 @@ void harness(void)
last_assignment();
if (!LEN) {
bounds();
- command_line();
+ command_line(HASH_LEN);
}
+ if (LEN == 1 || LEN == 2)
+ command_line(LEN == 1 ? HASH_LEN - 1 : HASH_LEN + 1);
}