eBPF-based security platform
proofs: take config-auth to the passphrase limit, from any earlier value
Daniel Borkmann776711fddd01
diff --git a/Documentation/contribute/testing/proof-coverage.rst b/Documentation/contribute/testing/proof-coverage.rstindex 3026fd00..601b3d1e 100644--- a/Documentation/contribute/testing/proof-coverage.rst+++ b/Documentation/contribute/testing/proof-coverage.rst@@ -988,9 +988,15 @@ or shorter, and "lengths 0 to 6" every input of each of those lengths.by dm-verity's own formula; nothing changed on refusal* - ``config-auth``- ``set_owner_auth()``- - Values of 0 to 16 bytes+ - Values of 0 to 16 bytes, any earlier value- A passphrase as it stands, ``hex:`` digits as the bytes they spell;a refusal keeps the value before+ * - ``config-auth-long``+ - ``set_owner_auth()``+ - Passphrases of 255 to 258 bytes, any 8 bytes and then letters,+ any earlier value+ - A passphrase of up to 256 bytes as it stands; a longer one+ refused, the value before kept* - ``config-hosts``- ``tls_classical_hosts_valid()``- Values of 0 to 7 bytesdiff --git a/testing/proofs/cbmc/config-auth-long.c b/testing/proofs/cbmc/config-auth-long.cnew file mode 100644index 00000000..cdc0cd71--- /dev/null+++ b/testing/proofs/cbmc/config-auth-long.c@@ -0,0 +1,9 @@+// SPDX-License-Identifier: BSD-2-Clause+/*+ * Copyright (c) 2026 Authors of shirudo+ *+ * config-auth at the 256-byte limit of a passphrase, with the bounds of+ * its own that values of 255 to 258 bytes need.+ */++#include "config-auth.c"diff --git a/testing/proofs/cbmc/config-auth.c b/testing/proofs/cbmc/config-auth.cindex db42dc0a..5adef7a2 100644--- a/testing/proofs/cbmc/config-auth.c+++ b/testing/proofs/cbmc/config-auth.c@@ -3,9 +3,9 @@* Copyright (c) 2026 Authors of shirudo** set_owner_auth() of util/config.c, the shirudo.conf reader, on every- * tpm.owner_auth value of up to LEN bytes and any earlier value: it stores- * the bytes an even run of hex digits after "hex:" spells, or the text- * itself, and a refusal leaves the earlier value intact.+ * tpm.owner_auth value of LEN bytes and any earlier value: it stores the+ * bytes an even run of hex digits after "hex:" spells, or the text+ * itself, each only where it fits, and a refusal leaves the earlier value.*/#define PROOF_MEMCPY_BYTEWISE@@ -14,16 +14,29 @@#include "../../../util/hex.c"#include "../../../util/config.c"-static struct config cfg;+#define AUTH_MAX OWNER_AUTH_MAX++/*+ * A value longer than SYMBOLIC bytes, there to reach the 256-byte limit+ * of a passphrase, is any SYMBOLIC bytes but NUL followed by letters, all+ * LEN bytes of it; the shorter ones are any bytes and end anywhere.+ */+#define SYMBOLIC 8void pr_warn(const char *fmt, ...){}-static char *any_string(void)+static char *any_value(void){char *s = any_bytes(LEN + 1);+ size_t i;+ if (LEN > SYMBOLIC)+ for (i = 0; i < SYMBOLIC; i++)+ __CPROVER_assume(s[i]);+ for (i = SYMBOLIC; i < LEN; i++)+ s[i] = 'p';s[LEN] = '\0';return s;}@@ -38,34 +51,43 @@ static bool hex_run(const char *s, size_t n)return !(n % 2);}+/*+ * Each byte is checked at an index k of any value below AUTH_MAX, one+ * read where a loop over all of them would cost minutes.+ */void harness(void){- char *val = any_string(), before[LEN + 1];- size_t had, n, i;+ char *val = any_value(), was;+ struct config cfg;+ size_t had, n, k;- __CPROVER_assume(had <= sizeof(cfg.tpm_owner_auth));- cfg.tpm_owner_auth_len = had;- for (i = 0; i < LEN; i++)- before[i] = cfg.tpm_owner_auth[i];+ __CPROVER_assume(cfg.tpm_owner_auth_len <= AUTH_MAX && k < AUTH_MAX);+ had = cfg.tpm_owner_auth_len;+ was = cfg.tpm_owner_auth[k];n = strlen(val);set_owner_auth(&cfg, val);if (strncmp(val, "hex:", 4)) {+ if (n > AUTH_MAX) {+ __CPROVER_assert(cfg.tpm_owner_auth_len == had &&+ cfg.tpm_owner_auth[k] == was,+ "a passphrase too long leaves the earlier value");+ return;+ }__CPROVER_assert(cfg.tpm_owner_auth_len == n &&- !memneq_explicit(cfg.tpm_owner_auth, val, n),+ (k >= n || cfg.tpm_owner_auth[k] == val[k]),"a passphrase as it stands");return;}- if (!hex_run(val + 4, n - 4)) {+ if (!hex_run(val + 4, n - 4) || (n - 4) / 2 > AUTH_MAX) {__CPROVER_assert(cfg.tpm_owner_auth_len == had &&- !memneq_explicit(cfg.tpm_owner_auth, before, LEN),+ cfg.tpm_owner_auth[k] == was,"a refusal leaves the earlier value");return;}- __CPROVER_assert(cfg.tpm_owner_auth_len == (n - 4) / 2,+ __CPROVER_assert(cfg.tpm_owner_auth_len == (n - 4) / 2 &&+ (k >= (n - 4) / 2 ||+ (__u8)cfg.tpm_owner_auth[k] ==+ (hex_nibble(val[4 + 2 * k]) << 4 |+ hex_nibble(val[5 + 2 * k]))),"the bytes the hex digits spell");- for (i = 0; i < (n - 4) / 2; i++)- __CPROVER_assert((__u8)cfg.tpm_owner_auth[i] ==- (hex_nibble(val[4 + 2 * i]) << 4 |- hex_nibble(val[5 + 2 * i])),- "each one");}diff --git a/testing/proofs/cbmc/proofs.list b/testing/proofs/cbmc/proofs.listindex c620be39..7c5b20b7 100644--- a/testing/proofs/cbmc/proofs.list+++ b/testing/proofs/cbmc/proofs.list@@ -50,6 +50,7 @@ attest-pcr --unwind 1 --unwindset harness.0:65,harness.1:33,harness.2:33,hex_deeventlog-records --unwind 34 LEN=0-32config-image --unwind 6 --unwindset memcmp.0:89,harness.0:33 LEN=0,511,512,4096config-auth --unwind 18 LEN=0-16+config-auth-long --unwind 18 --unwindset any_value.0:9,any_value.1:259,strlen.0:260,strnlen.0:260,hex_run.0:256,memcpy.0:259 LEN=255-258config-hosts --unwind 9 LEN=0-7config-update-follows --unwind 33image-bootstrap-certificates --unwind 64 --max-field-sensitivity-array-size 32 LEN=0-16