Skip to content

eBPF-based security platform

proofs: prove the tree manifest round trip

Daniel Borkmann365787dfcd3a
diff --git a/Documentation/contribute/testing/proof-coverage.rst b/Documentation/contribute/testing/proof-coverage.rst
index d297e2db..3fb6c395 100644
--- a/Documentation/contribute/testing/proof-coverage.rst
+++ b/Documentation/contribute/testing/proof-coverage.rst
@@ -264,6 +264,15 @@ or shorter, and "lengths 0 to 6" every input of each of those lengths.
base of 0 without the segment keys or a later one with an
operation, a ``sha256:`` digest and a root of 64 hex digits, and
operations that run from the base to the head
+ * - ``bpm-tree-manifest``
+ - ``bpm_tree_manifest()``, ``tree_manifest_canonical()``, against
+ ``bpm_oci_parse_manifest()``
+ - Payload and signature layers of fixed digests and sizes of 0 and
+ 0, 1 and 4096, and 2\ :sup:`63` - 1 and 1; the SHA-256 of the
+ empty config a stub
+ - The manifest bpm tree append writes reads back as its two
+ layers, and a node takes it as their canonical form; the layers
+ swapped, or two payloads in the publisher's own form, refused
* - ``bpm-tree-reserve``
- ``tree_operations_reserve()``, the allocator a stub that may fail
- Every count and capacity up to ``TREE_MAX_OPS``
diff --git a/testing/proofs/cbmc/bpm-tree-manifest.c b/testing/proofs/cbmc/bpm-tree-manifest.c
new file mode 100644
index 00000000..babb2983
--- /dev/null
+++ b/testing/proofs/cbmc/bpm-tree-manifest.c
@@ -0,0 +1,130 @@
+// SPDX-License-Identifier: BSD-2-Clause
+/*
+ * Copyright (c) 2026 Authors of shirudo
+ *
+ * The manifest of a tree publication, from bpm_tree_manifest() as bpm tree
+ * append writes it to tree_manifest_canonical() as a node takes it, both
+ * of util/bpm_package.c, for the payload and signature layers LEN picks:
+ * bpm_oci_parse_manifest() reads back the two layers as written, and the
+ * node takes those bytes as the canonical form; the layers swapped, or two
+ * payloads in the publisher's own form, it refuses. The SHA-256 of the
+ * empty config is a stub.
+ */
+
+/* As proof.h, before the system headers can include <ctype.h>. */
+#define __NO_CTYPE 1
+
+#include <fcntl.h>
+#include <limits.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <strings.h>
+#include <sys/stat.h>
+#include <time.h>
+#include <unistd.h>
+#include <zlib.h>
+#include <curl/curl.h>
+#include <openssl/bio.h>
+#include <openssl/evp.h>
+#include <openssl/pem.h>
+#include <openssl/x509.h>
+
+#define PROOF_MEMCPY_BYTEWISE
+#include "proof.h"
+#include "../../../util/string.c"
+#include "../../../util/hex.c"
+#include "../../../util/json.c"
+#include "../../../util/bpm_oci.c"
+#include "../../../util/bpm_package.c"
+
+/* Past the manifest, of the 8 KiB its callers ask for. */
+#define DOC_MAX 768
+
+#define DIGEST_A \
+ "sha256:0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"
+#define DIGEST_B \
+ "sha256:fedcba9876543210fedcba9876543210fedcba9876543210fedcba9876543210"
+
+int sha256_buffer(const void *data, size_t len, __u8 out[32])
+{
+ memset(out, 0x5a, 32);
+ return 0;
+}
+
+/*
+ * The allocator hands out objects of their sizes, so that the bytes
+ * written are the bytes read back: the canonical form in DOC_MAX bytes of
+ * the 8 KiB asked for, and two layers of the 512 the reader asks for.
+ */
+void *xmalloc(size_t size)
+{
+ static char want[DOC_MAX];
+
+ __CPROVER_assert(size == BPM_TREE_MANIFEST_CAP,
+ "only the canonical form is allocated so");
+ return want;
+}
+
+void *xcalloc(size_t nmemb, size_t size)
+{
+ static struct bpm_descriptor layers[2];
+
+ __CPROVER_assert(nmemb == BPM_MAX_ENTRIES &&
+ size == sizeof(layers[0]), "only layers allocated so");
+ return layers;
+}
+
+void xfree(void *p, size_t size)
+{
+}
+
+static bool same(const struct bpm_descriptor *a,
+ const struct bpm_descriptor *b)
+{
+ return !strcmp(a->media, b->media) && !strcmp(a->digest, b->digest) &&
+ a->size == b->size;
+}
+
+void harness(void)
+{
+ static const __s64 sizes[][2] = {
+ { 0, 0 }, { 1, 4096 }, { INT64_MAX, 1 },
+ };
+ static char doc[DOC_MAX];
+ struct bpm_descriptor payload = { .size = sizes[LEN][0] };
+ struct bpm_descriptor sig = { .size = sizes[LEN][1] };
+ struct bpm_descriptor layers[2], swapped[2];
+ struct bpm_buffer manifest;
+ size_t len;
+ int n = 0;
+
+ bpm_copy_string(payload.media, sizeof(payload.media), BPM_TREE_MEDIA);
+ bpm_copy_string(payload.digest, sizeof(payload.digest), DIGEST_A);
+ bpm_copy_string(sig.media, sizeof(sig.media), BPM_TREE_SIG_MEDIA);
+ bpm_copy_string(sig.digest, sizeof(sig.digest), DIGEST_B);
+ __CPROVER_assert(!bpm_tree_manifest(&payload, &sig, doc, sizeof(doc),
+ &len) && len < sizeof(doc),
+ "the manifest written");
+ __CPROVER_assert(!bpm_oci_parse_manifest((const __u8 *)doc, len, layers,
+ 2, &n, NULL, 0) &&
+ n == 2 && same(&layers[0], &payload) &&
+ same(&layers[1], &sig),
+ "which reads back as its two layers");
+ manifest = (struct bpm_buffer){ (__u8 *)doc, len, sizeof(doc) };
+ __CPROVER_assert(!tree_manifest_canonical(&manifest, layers, n),
+ "and is the canonical form of them");
+ swapped[0] = layers[1];
+ swapped[1] = layers[0];
+ __CPROVER_assert(tree_manifest_canonical(&manifest, swapped, n) ==
+ -EBADMSG, "the layers swapped refused");
+ /* Two payloads, written as the publisher would write them. */
+ bpm_copy_string(sig.media, sizeof(sig.media), BPM_TREE_MEDIA);
+ __CPROVER_assert(!bpm_tree_manifest(&payload, &sig, doc, sizeof(doc),
+ &len) &&
+ !bpm_oci_parse_manifest((const __u8 *)doc, len, layers,
+ 2, &n, NULL, 0) && n == 2,
+ "a manifest of two payloads read");
+ manifest = (struct bpm_buffer){ (__u8 *)doc, len, sizeof(doc) };
+ __CPROVER_assert(tree_manifest_canonical(&manifest, layers, n) ==
+ -EBADMSG, "and refused, in its own form too");
+}
diff --git a/testing/proofs/cbmc/proofs.list b/testing/proofs/cbmc/proofs.list
index 308cce61..7185c51f 100644
--- a/testing/proofs/cbmc/proofs.list
+++ b/testing/proofs/cbmc/proofs.list
@@ -87,6 +87,7 @@ bpm-names --unwind 131
bpm-tree-selector --unwind 10 --malloc-may-fail --malloc-fail-null LEN=0,1
bpm-tree-reader --unwind 6 --unwindset hex_digits.0:65,hex_decode.0:33,strlen.0:129,strncmp.0:8 --malloc-may-fail --malloc-fail-null LEN=0,1
bpm-tree-reserve --unwind 1
+bpm-tree-manifest --max-field-sensitivity-array-size 768 --unwind 80 --unwindset memcmp.0:770 LEN=0-2
bpm-source-config --unwind 24
bpm-oci-strings --unwind 9
bpm-semver-model --slice-formula --unwind 1 --unwindset strlen.0:10,strcmp.0:10,strcspn.0:2,strcspn.1:4,digits.0:10,parse_base.0:10,parse_base.1:10,semver_parse.0:4,semver_identifiers.0:4,semver_identifiers.1:3,prerelease_compare.0:3,memchr.0:4,memcmp.0:4,bpm_semver_compare.0:4,strnlen.0:10,any_string.0:10,break_at.0:10,split_on.0:10,next_ident.0:4,numeral.0:8,numeric.0:8,ident_ok.0:4,identifiers.0:3,lex_bytes.0:10,memcmp_model.0:4,lex_idents.0:3,semver_model_compare.0:4 LEN=9