Skip to content

eBPF-based security platform

bpm: take a tree publication only under the manifest its publisher writes

Daniel Borkmann167c742161c6
diff --git a/Documentation/contribute/testing/test-coverage.rst b/Documentation/contribute/testing/test-coverage.rst
index 872b4b62..231532a6 100644
--- a/Documentation/contribute/testing/test-coverage.rst
+++ b/Documentation/contribute/testing/test-coverage.rst
@@ -619,6 +619,10 @@ signed config image.
:header-rows: 1
:widths: 36 64
+ * - ``t7111-bpm-tree-manifest``
+ - The signed layers of a publication served under a manifest that
+ is not the one ``bpm tree append`` writes are refused before the
+ node records anything, and the publisher's form is taken again
* - Test
- Covers
* - ``t8001-otel-map``
diff --git a/Documentation/reference/formats/bpm-formats.rst b/Documentation/reference/formats/bpm-formats.rst
index 8740bbac..c32b25cc 100644
--- a/Documentation/reference/formats/bpm-formats.rst
+++ b/Documentation/reference/formats/bpm-formats.rst
@@ -337,7 +337,14 @@ Tree objects in the registry
``--reference`` names another tag. OCI image manifest,
``schemaVersion`` 2, ``artifactType``
``application/vnd.shirudo.upatch.tree.v1``, the empty config, and
- exactly one document layer and one signature layer.
+ exactly one document layer and one signature layer, in that order.
+ Its bytes are exactly those ``bpm tree append`` writes: compact
+ JSON with the keys ``schemaVersion``, ``mediaType``,
+ ``artifactType``, ``config`` and ``layers`` in this order, and each
+ descriptor's ``mediaType``, ``digest`` and ``size``. A target and
+ ``bpm tree append`` refuse a manifest in any other form, so that the
+ manifest digest a target records and a successor names as its
+ parent or segment follows from the two signed layers.
* - Sealed segment
- A publication manifest that a later segment names in
``base.segment_manifest_digest``, unchanged since it was the
diff --git a/Documentation/security/threat-model.rst b/Documentation/security/threat-model.rst
index 61d2e5b0..fe063aed 100644
--- a/Documentation/security/threat-model.rst
+++ b/Documentation/security/threat-model.rst
@@ -1083,7 +1083,12 @@ operation, so one it stopped in the middle of is not followed by an
older one. It refuses a publication whose operations up to its last
applied one are not the ones it processed, by the history root its
``outcomes`` record holds, and a segment that does not start from that
-root at its base. A node behind the segment the tag names walks back
+root at its base. It takes a publication only under the manifest that
+``bpm tree append`` writes for its two layers, byte for byte, so that the
+manifest digest it records and a successor names follows from the signed
+layers: a registry that serves them under a manifest of its own, which
+would leave a node with one digest refusing the other for good, is
+refused before the node records anything. A node behind the segment the tag names walks back
through the sealed segments by digest, each signed and naming the one
before it, up to a limit of 65,536 operations, or 1,048,576 for a node
that has processed none, so a registry can neither splice another
@@ -1112,7 +1117,7 @@ and tree signatures accept algorithms other than ML-DSA (U4).
:Refusal: the ``bpm`` command fails and installs nothing
:Counters: none
:Tests: ``t7005``, ``t7101``, ``t7102``, ``t7103``, ``t7104``,
- ``t7105``, ``t7106``, ``t7107``, ``t7108``, ``t8005``
+ ``t7105``, ``t7106``, ``t7107``, ``t7108``, ``t7111``, ``t8005``
:Proofs: ``bpm-tar-header``, ``bpm-tar-octal``, ``bpm-archive-path``,
``bpm-oci-challenge``, ``bpm-oci-token``, ``bpm-oci-header``,
``bpm-oci-descriptor``, ``bpm-semver-model``, ``Shirudo.SemVer``,
diff --git a/testing/functional/bpm/t7111-bpm-tree-manifest.sh b/testing/functional/bpm/t7111-bpm-tree-manifest.sh
new file mode 100755
index 00000000..079b4ce9
--- /dev/null
+++ b/testing/functional/bpm/t7111-bpm-tree-manifest.sh
@@ -0,0 +1,54 @@
+#!/bin/sh
+# SPDX-License-Identifier: BSD-2-Clause
+# Copyright (c) 2026 Authors of shirudo
+#
+# t7111 -- a target takes a tree publication only under the manifest bpm
+# tree append writes for its two layers: the same signed layers served
+# under a manifest of the registry's own making are refused before the
+# node records anything, and the publisher's form is taken again after.
+# Runs after t7109, on the publication it left configured.
+
+cd "$(dirname "$0")/../.."
+. ./integration-lib.sh
+target_guard
+command -v python3 >/dev/null 2>&1 || test_skip_all "no python3"
+
+FIXTURES=${SHIRUDO_TEST_FIXTURES_DIR:?target fixture directory is not set}
+WORK=$(mktemp -d)
+# The fixtures are read-only; the registry serves a copy of them.
+REGISTRY="$WORK/tree-oci"
+MANIFEST="$REGISTRY/shirudo/upatch-tree/manifests/unmatched"
+
+[ -s "$FIXTURES/tree-oci/shirudo/upatch-tree/manifests/unmatched" ] ||
+ test_skip_all "missing tree fixture: unmatched"
+[ -s "$TREE_STATE_FILE" ] || test_skip_all "no tree state to keep"
+cleanup()
+{
+ tree_registry_stop
+ rm -rf "$WORK"
+}
+trap cleanup EXIT
+cp -R "$FIXTURES/tree-oci" "$REGISTRY"
+cp "$MANIFEST" "$WORK/manifest"
+tree_registry_start "$REGISTRY" "$WORK"
+cp "$TREE_STATE_FILE" "$WORK/state"
+
+test_expect_success 'the publication syncs under the publisher manifest' '
+ tree_sync "$WORK/before.json" &&
+ cmp -s "$TREE_STATE_FILE" "$WORK/state"
+'
+test_expect_success 'the same layers under a re-wrapped manifest are refused' '
+ python3 -c "
+import json, sys
+manifest = json.load(open(sys.argv[1]))
+open(sys.argv[1], \"w\").write(json.dumps(manifest, indent=1))
+" "$MANIFEST" &&
+ ! tree_sync "$WORK/wrapped.json" &&
+ cmp -s "$TREE_STATE_FILE" "$WORK/state"
+'
+test_expect_success 'and the publisher manifest is taken again after it' '
+ cp "$WORK/manifest" "$MANIFEST" &&
+ tree_sync "$WORK/after.json" &&
+ cmp -s "$TREE_STATE_FILE" "$WORK/state"
+'
+test_done
diff --git a/testing/unit/bpm_package.c b/testing/unit/bpm_package.c
index e2e9f307..8e83395e 100644
--- a/testing/unit/bpm_package.c
+++ b/testing/unit/bpm_package.c
@@ -2,6 +2,7 @@
/* Copyright (c) 2026 Authors of shirudo */
#include <errno.h>
+#include <string.h>
#include <shirudo/string.h>
@@ -185,7 +186,45 @@ static void upatch_member_goes_by_suffix(void)
EXPECT_EQ(bpm_upatch_pair("x.upatch", 8, out, 16), 0);
}
+#define MANIFEST \
+ "{\"schemaVersion\":2," \
+ "\"mediaType\":\"application/vnd.oci.image.manifest.v1+json\"," \
+ "\"artifactType\":\"application/vnd.shirudo.upatch.tree.v1\"," \
+ "\"config\":{\"mediaType\":\"application/vnd.oci.empty.v1+json\"," \
+ "\"digest\":\"sha256:44136fa355b3678a1146ad16f7e8649e94fb4fc21fe77e8310c060f61caaff8a\"," \
+ "\"size\":2}," \
+ "\"layers\":[{\"mediaType\":\"application/vnd.shirudo.upatch.tree.v1+json\"," \
+ "\"digest\":\"sha256:1111111111111111111111111111111111111111111111111111111111111111\"," \
+ "\"size\":123}," \
+ "{\"mediaType\":\"application/vnd.shirudo.upatch.tree.signature.v1\"," \
+ "\"digest\":\"sha256:2222222222222222222222222222222222222222222222222222222222222222\"," \
+ "\"size\":45}]}"
+
+static void tree_manifest_is_the_publisher_form(void)
+{
+ struct bpm_descriptor payload = {
+ .media = BPM_TREE_MEDIA,
+ .digest = "sha256:1111111111111111111111111111111111111111111111111111111111111111",
+ .size = 123,
+ };
+ struct bpm_descriptor sig = {
+ .media = BPM_TREE_SIG_MEDIA,
+ .digest = "sha256:2222222222222222222222222222222222222222222222222222222222222222",
+ .size = 45,
+ };
+ char out[BPM_TREE_MANIFEST_CAP], small[64];
+ size_t len;
+
+ ASSERT_EQ(bpm_tree_manifest(&payload, &sig, out, sizeof(out), &len), 0);
+ EXPECT_EQ(len, strlen(out));
+ EXPECT_STREQ(out, MANIFEST);
+ EXPECT_LT(bpm_tree_manifest(&payload, &sig, small, sizeof(small), &len),
+ 0);
+ EXPECT_EQ(len, 0);
+}
+
static const struct unit_case cases[] = {
+ UNIT_CASE(tree_manifest_is_the_publisher_form),
UNIT_CASE(index_entry_needs_its_package_size),
UNIT_CASE(semver_valid_is_semver_alone),
UNIT_CASE(semver_follows_its_precedence),
diff --git a/testing/vm/build-bundle-payload.sh b/testing/vm/build-bundle-payload.sh
index fa55de8f..75e483a2 100755
--- a/testing/vm/build-bundle-payload.sh
+++ b/testing/vm/build-bundle-payload.sh
@@ -375,6 +375,10 @@ def write(path, body):
path.parent.mkdir(parents=True, exist_ok=True)
path.write_bytes(body)
+# The manifest in the form bpm tree append writes, which a target takes
+# and no other: the same keys in the same order, with the empty config.
+empty_config = b"{}"
+write(repo / "blobs" / digest(empty_config), empty_config)
for reference in ("stable", "updated", "deleted", "restored", "kconfig",
"reloaded", "outcomes", "stopped", "fetched", "fixes",
"keepalive", "unmatched"):
@@ -388,6 +392,10 @@ for reference in ("stable", "updated", "deleted", "restored", "kconfig",
manifest = {
"schemaVersion": 2,
"mediaType": "application/vnd.oci.image.manifest.v1+json",
+ "artifactType": "application/vnd.shirudo.upatch.tree.v1",
+ "config": {"mediaType": "application/vnd.oci.empty.v1+json",
+ "digest": digest(empty_config),
+ "size": len(empty_config)},
"layers": [
{"mediaType": "application/vnd.shirudo.upatch.tree.v1+json",
"digest": payload_digest, "size": len(payload)},
@@ -583,11 +591,16 @@ def digest(body):
payload = (work / (name + ".json")).read_bytes()
signature = (work / (name + ".sig")).read_bytes()
-for body in (payload, signature):
+empty_config = b"{}"
+for body in (payload, signature, empty_config):
(repo / "blobs" / digest(body)).write_bytes(body)
+# In the form bpm tree append writes, the one a target takes.
manifest = json.dumps({
"schemaVersion": 2,
"mediaType": "application/vnd.oci.image.manifest.v1+json",
+ "artifactType": "application/vnd.shirudo.upatch.tree.v1",
+ "config": {"mediaType": "application/vnd.oci.empty.v1+json",
+ "digest": digest(empty_config), "size": len(empty_config)},
"layers": [
{"mediaType": "application/vnd.shirudo.upatch.tree.v1+json",
"digest": digest(payload), "size": len(payload)},
diff --git a/tools/shirudo-build/bpm-publish.c b/tools/shirudo-build/bpm-publish.c
index fc5ba6a3..e75e25fa 100644
--- a/tools/shirudo-build/bpm-publish.c
+++ b/tools/shirudo-build/bpm-publish.c
@@ -1164,13 +1164,12 @@ static int cmd_bpm_tree_append(int argc, char **argv)
size_t n_fixes = 0;
struct tree_publication pub = {};
struct tree_operation *op = NULL;
- size_t len, payload_len = 0, sig_len = 0;
+ size_t len, payload_len = 0, sig_len = 0, manifest_len;
char *payload = NULL, *manifest = NULL;
struct bpm_build_spec *spec = NULL;
__u8 *beefile = NULL, *sig = NULL;
struct bpm_package_info info = {};
struct bpm_oci_client c __cleanup(bpm_oci_client_clear) = {};
- struct json_emit e;
char empty_config[] = "{}";
char package_dir[101];
int appended = 0, ret;
@@ -1485,34 +1484,24 @@ static int cmd_bpm_tree_append(int argc, char **argv)
&sig_layer);
if (ret)
goto out;
- manifest = xmalloc(BPM_MANIFEST_CAP);
+ manifest = xmalloc(BPM_TREE_MANIFEST_CAP);
if (!manifest) {
ret = -ENOMEM;
goto out;
}
- e = (struct json_emit){ .buf = manifest, .cap = BPM_MANIFEST_CAP };
- json_obj_open(&e);
- json_kv_int(&e, "schemaVersion", 2);
- json_kv_string(&e, "mediaType", BPM_MANIFEST_MEDIA);
- json_kv_string(&e, "artifactType", BPM_TREE_ARTIFACT);
- bpm_oci_emit_descriptor(&e, "config", &config, NULL);
- json_arr_open(&e, "layers");
- bpm_oci_emit_descriptor(&e, NULL, &payload_layer, NULL);
- bpm_oci_emit_descriptor(&e, NULL, &sig_layer, NULL);
- json_arr_close(&e);
- json_obj_close(&e);
- ret = e.err;
+ ret = bpm_tree_manifest(&payload_layer, &sig_layer, manifest,
+ BPM_TREE_MANIFEST_CAP, &manifest_len);
if (!ret && sealed)
ret = tree_tag_sealed(&c, repository, parent);
if (!ret)
ret = bpm_oci_put_manifest(&c, repository, reference,
- (const __u8 *)manifest, e.len,
+ (const __u8 *)manifest, manifest_len,
digest, sizeof(digest));
if (!ret)
printf("oci://%s/%s:%s %s\n", c.registry, repository, reference,
digest);
out:
- xfree(manifest, BPM_MANIFEST_CAP);
+ xfree(manifest, BPM_TREE_MANIFEST_CAP);
sig_free(sig);
xfree(payload, payload_len);
if (op)
diff --git a/util/bpm_package.c b/util/bpm_package.c
index d8f3eb95..35c84ba0 100644
--- a/util/bpm_package.c
+++ b/util/bpm_package.c
@@ -892,6 +892,68 @@ out:
return ret;
}
+int bpm_tree_manifest(const struct bpm_descriptor *payload,
+ const struct bpm_descriptor *sig, char *out, size_t cap,
+ size_t *len)
+{
+ static const char empty_config[] = "{}";
+ struct bpm_descriptor config = { .size = sizeof(empty_config) - 1 };
+ struct json_emit e = { .buf = out, .cap = cap };
+ int ret;
+
+ *len = 0;
+ if (strscpy(config.media, BPM_EMPTY_CONFIG_MEDIA,
+ sizeof(config.media)) < 0)
+ return -E2BIG;
+ ret = bpm_sha256_digest(empty_config, sizeof(empty_config) - 1,
+ config.digest, sizeof(config.digest));
+ if (ret)
+ return ret;
+ json_obj_open(&e);
+ json_kv_int(&e, "schemaVersion", 2);
+ json_kv_string(&e, "mediaType", BPM_MANIFEST_MEDIA);
+ json_kv_string(&e, "artifactType", BPM_TREE_ARTIFACT);
+ bpm_oci_emit_descriptor(&e, "config", &config, NULL);
+ json_arr_open(&e, "layers");
+ bpm_oci_emit_descriptor(&e, NULL, payload, NULL);
+ bpm_oci_emit_descriptor(&e, NULL, sig, NULL);
+ json_arr_close(&e);
+ json_obj_close(&e);
+ if (e.err)
+ return e.err;
+ *len = e.len;
+ return 0;
+}
+
+/*
+ * A registry may serve the signed layers under a manifest of its own
+ * making: the manifest digest a node records and a successor names as
+ * its parent would then be of bytes no signature covers, and a node that
+ * recorded one form refuses the other for good. Only the form the
+ * publisher writes is taken.
+ */
+static int tree_manifest_canonical(const struct bpm_buffer *manifest,
+ const struct bpm_descriptor *layers, int nl)
+{
+ size_t len;
+ char *want;
+ int ret;
+
+ if (nl != 2 || strcmp(layers[0].media, BPM_TREE_MEDIA) ||
+ strcmp(layers[1].media, BPM_TREE_SIG_MEDIA))
+ return -EBADMSG;
+ want = xmalloc(BPM_TREE_MANIFEST_CAP);
+ if (!want)
+ return -ENOMEM;
+ ret = bpm_tree_manifest(&layers[0], &layers[1], want,
+ BPM_TREE_MANIFEST_CAP, &len);
+ if (!ret && (len != manifest->len ||
+ memcmp(want, manifest->data, len)))
+ ret = -EBADMSG;
+ xfree(want, BPM_TREE_MANIFEST_CAP);
+ return ret;
+}
+
int bpm_tree_fetch_document(struct bpm_oci_client *c,
const char *repository, const char *reference,
const char *cert_path,
@@ -925,6 +987,8 @@ int bpm_tree_fetch_document(struct bpm_oci_client *c,
}
ret = bpm_oci_parse_manifest(manifest.data, manifest.len, layers,
BPM_MAX_ENTRIES, &nl, NULL, 0);
+ if (!ret)
+ ret = tree_manifest_canonical(&manifest, layers, nl);
if (ret)
goto out;
ret = bpm_oci_get_signed(c, repository, layers, nl, BPM_TREE_MEDIA,
diff --git a/util/bpm_package.h b/util/bpm_package.h
index 7b22d0c1..64ea379a 100644
--- a/util/bpm_package.h
+++ b/util/bpm_package.h
@@ -95,11 +95,26 @@ int bpm_pkg_read_member(const char *archive, const char *member,
int bpm_pkg_extract(const char *archive, const char *dest);
int bpm_pkg_load_info(const char *archive, struct bpm_package_info *info);
+/* Room for the manifest of a tree publication, in bytes. */
+#define BPM_TREE_MANIFEST_CAP 8192u
+
+/*
+ * The manifest of a tree publication whose payload and signature are the
+ * layers payload and sig, as bpm tree append writes it, into out of cap
+ * bytes with its length in *len. 0 or -errno.
+ */
+int bpm_tree_manifest(const struct bpm_descriptor *payload,
+ const struct bpm_descriptor *sig, char *out, size_t cap,
+ size_t *len);
+
/*
* Fetch the signed tree publication at repository:reference, check every
* layer against its descriptor and the payload against trusted, or
* cert_path when trusted is NULL, and
- * parse it. -ENOENT when the reference does not exist yet.
+ * parse it. The manifest must be exactly bpm_tree_manifest() of its two
+ * layers, -EBADMSG otherwise, so that the digest a node records and a
+ * successor names follows from the signed layers alone. -ENOENT when the
+ * reference does not exist yet.
* bpm_tree_fetch_document() stops before the parse and hands over the
* checked bytes, which the caller frees with bpm_buffer_free().
*/