Skip to content

eBPF-based security platform

proofs: prove the quote keepalive_quote_format() writes

Daniel Borkmannf0e6973ec021
diff --git a/Documentation/contribute/testing/proof-coverage.rst b/Documentation/contribute/testing/proof-coverage.rst
index 6a4fbfea..d297e2db 100644
--- a/Documentation/contribute/testing/proof-coverage.rst
+++ b/Documentation/contribute/testing/proof-coverage.rst
@@ -845,6 +845,15 @@ or shorter, and "lengths 0 to 6" every input of each of those lengths.
that try saw pending.json, ``UNSETTLED`` exactly when no try's
reads agreed; ``collect()``'s error returned at once with no flag
set
+ * - ``keepalive-quote``
+ - ``keepalive_quote_format()``, ``base64_encode()`` a stub that may
+ fail
+ - Every outcome of the three encodings, rooms of 1, 19, 20 and 21
+ bytes
+ - ``attest=``, ``sig=`` and ``ak=`` with the encodings of the
+ attestation, its signature and the key, each in that order and
+ into all its room, terminated; ``-E2BIG`` with nothing written
+ when it does not fit; the first failed encoding's error
* - ``otel-header-fields``
- The OTLP header checks and ``percent_decode()``
- Strings up to 32 bytes
@@ -1512,8 +1521,8 @@ a proof covers.
* - :src:`util/crypto_openssl.c`, :src:`util/curl.c`,
:src:`util/elf_target.c`, :src:`util/kernel_abi.c`,
:src:`util/nv_writer.c`, :src:`util/sign.c`,
- :src:`util/keepalive_quote.c`, :src:`util/tls_openssl.c`,
- :src:`util/tpm.c`, :src:`util/upatch_decode.c`
+ :src:`util/tls_openssl.c`, :src:`util/tpm.c`,
+ :src:`util/upatch_decode.c`
- Mostly calls into a library a harness would have to model whole:
OpenSSL, libcurl, libelf, the BTF reader of libbpf, tpm2-tss and
LuaJIT
diff --git a/testing/proofs/cbmc/keepalive-quote.c b/testing/proofs/cbmc/keepalive-quote.c
new file mode 100644
index 00000000..49ac6b4a
--- /dev/null
+++ b/testing/proofs/cbmc/keepalive-quote.c
@@ -0,0 +1,81 @@
+// SPDX-License-Identifier: BSD-2-Clause
+/*
+ * Copyright (c) 2026 Authors of shirudo
+ *
+ * keepalive_quote_format() of util/keepalive_quote.c, the quote a
+ * keepalive carries and the backend's checker splits, for every outcome of
+ * its three encodings and a room of LEN bytes: exactly
+ * "attest=<a>;sig=<s>;ak=<k>" with its terminator when it fits, -E2BIG
+ * with nothing written when it does not, and the first encoding's error
+ * when one fails. base64_encode() is OpenSSL's; the stub here encodes each
+ * of the three as one letter after it checks what it is handed.
+ */
+
+/* util/string.c is included behind a file that includes its header. */
+#define STRING_INTERNAL
+
+#include "proof.h"
+#include "../../../util/keepalive_quote.c"
+#include "../../../util/string.c"
+
+#define QUOTE "attest=a;sig=b;ak=c"
+
+static const struct tpm_attestation *att;
+static const struct tpm_key *ak;
+static int fails[3], calls;
+
+int base64_encode(const __u8 *data, size_t len, char *out, size_t out_sz)
+{
+ static const size_t room[] = {
+ BASE64_SIZE(TPM_ATTEST_MAX), BASE64_SIZE(TPM_SIGNATURE_MAX),
+ BASE64_SIZE(TPM_PUBLIC_MAX),
+ };
+ const __u8 *const from[] = { att->attest, att->signature, ak->public };
+ const size_t lens[] = { att->attest_len, att->signature_len,
+ ak->public_len };
+ int k = calls++;
+
+ __CPROVER_assert(k < 3 && data == from[k] && len == lens[k] &&
+ out_sz == room[k],
+ "each part encoded from its field into all its room");
+ if (fails[k])
+ return fails[k];
+ out[0] = (char)('a' + k);
+ out[1] = '\0';
+ return 0;
+}
+
+void harness(void)
+{
+ struct tpm_attestation any_att;
+ struct tpm_key any_ak;
+ int any_fails[3], k, ret, failed = 0;
+ const size_t room = LEN;
+ size_t i;
+ char *out;
+
+ att = &any_att;
+ ak = &any_ak;
+ for (k = 0; k < 3; k++) {
+ fails[k] = any_fails[k];
+ __CPROVER_assume(fails[k] <= 0);
+ if (!failed)
+ failed = fails[k];
+ }
+ out = any_bytes(LEN);
+ ret = keepalive_quote_format(att, ak, out, LEN);
+ if (failed) {
+ __CPROVER_assert(ret == failed,
+ "the first failed encoding's error");
+ return;
+ }
+ if (room < sizeof(QUOTE)) {
+ __CPROVER_assert(ret == -E2BIG && !out[0],
+ "-E2BIG when it does not fit, nothing written");
+ return;
+ }
+ __CPROVER_assert(!ret, "the quote written");
+ for (i = 0; i < sizeof(QUOTE); i++)
+ __CPROVER_assert(out[i] == QUOTE[i],
+ "attest=, sig= and ak= with their parts");
+}
diff --git a/testing/proofs/cbmc/proofs.list b/testing/proofs/cbmc/proofs.list
index 090b9b7b..308cce61 100644
--- a/testing/proofs/cbmc/proofs.list
+++ b/testing/proofs/cbmc/proofs.list
@@ -62,6 +62,7 @@ json-emit-buffer --unwind 1 --unwindset json_raw_value.0:5,harness.0:5 --malloc-
json-emit-nest --object-bits 12 --unwind 1 --unwindset json_text.0:57,sequences.0:4,sequences.1:5,any_depth.0:4,any_depth.1:4,strcmp.0:12,memchr.0:9,put_string_n.0:2,put_string_n.1:2,put_raw.0:8,json_kv_raw.0:3,json_raw_value.0:3,json_raw.0:5,strlen.0:3,vsnprintf.2:5,vsnprintf.0:2,format_number.0:3,format_number.2:5,format_number.3:3
keepalive-emit --object-bits 12 --max-field-sensitivity-array-size 960 --unwind 1 --unwindset json_members.0:961,power_of_ten.0:6,put_string_n.0:5,put_string_n.1:66,put_raw.0:7,strlen.0:66,hex_is_lower.0:66,kv_counters.0:43,kv_no_tree.0:8,json_raw_value.0:21,vsnprintf.2:4,vsnprintf.0:2,format_number.0:21,format_number.2:5,format_number.3:21,ends_in_any_number.0:6,ends_in_any_number.1:961,ends_in_any_number.2:5 LEN=0-3
keepalive-snapshot --unwind 4 --unwindset strcmp.0:2
+keepalive-quote --unwind 24 LEN=1,19,20,21
json-string --unwind 5 --unwindset json_string.0:7,parse_string.0:5,parse_string.1:7,memchr.0:9,memcmp.0:7,harness.0:8 LEN=0-6
json-escape --unwind 5 --unwindset parse_string.0:4,memcmp.0:9
json-roundtrip --unwind 1 --unwindset put_string_n.0:5,put_string_n.1:5,put_raw.0:7,vsnprintf.2:4,vsnprintf.0:2,format_number.0:3,format_number.2:5,format_number.3:3,parse_string.1:6,parse_string.0:4,hex4.0:5,utf8_width.0:4,memcmp.0:5 LEN=0-4