From daeb6c5a0708d5c010719fe2876af21c25a4490d Mon Sep 17 00:00:00 2001 From: Victor Vogel Date: Mon, 16 Nov 2026 04:03:52 +0000 Subject: [PATCH] bundle-manifest: write only slot B's boot images and userdata MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A bundle's install plan (manifest.json, which tools/install-phone and the desktop and web installers follow) took BOOT_IMAGES and UFS_RW from the descriptor checking only a name pattern and that each image's _b partition is on the descriptor's own UFS_RW. So a descriptor naming modem in BOOT_IMAGES with modem_b in UFS_RW gave a bundle whose install.writes held modem_b, beside a "never" list naming modem; the same for vbmeta, and UFS_RW alone could carry modem_b into the storage-guard allowlist. tools/make-bundle --unsigned finished with exit 0 in each case. Only slot B's five boot images and userdata are ours (AGENTS.md §1). bundle-manifest now accepts BOOT_IMAGES only from boot, init_boot, vendor_boot, vendor_kernel_boot and dtbo, and UFS_RW only from their _b partitions and userdata, each list on its own: the set bin/omamobile's load_device and initramfs/init's ufs_rw_load already hold. It replaces the name-pattern check. make-bundle runs it before the new bundle is moved in, so a refusal keeps the earlier bundle. Tested on the laptop only, no phone: tests/make-bundle gains a case (modem, vbmeta and modem_b descriptors refused with the name, the earlier bundle unchanged) that fails on main's tool and passes here; removing either new check fails it. tools/pr-check, tests/make-bundle, tests/make-bundle-keys and tests/all pass. Every descriptor in device/ is inside the set. Co-Authored-By: Claude Opus 5.5 --- tests/make-bundle | 21 +++++++++++++++++++++ tools/bundle-manifest | 13 +++++++++++-- 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/tests/make-bundle b/tests/make-bundle index 8e7ceab1e..a092b85a3 100755 --- a/tests/make-bundle +++ b/tests/make-bundle @@ -302,3 +302,24 @@ if out=$(bundle); then fail "an install link line this tool does not know stops grep -c "install link line this tool does not know" <<<"$out" >/dev/null || fail "the refusal says why: $out" cp "$t/MANIFEST.saved" "$mf" pass "manifest.json's install_link: only for an image built for the link, with its protocol" + +# The install plan writes only slot B's five boot images and userdata +# (AGENTS.md §1): a descriptor whose BOOT_IMAGES or UFS_RW names any other +# partition, here with its own allowlist entry beside it, stops the bundle +# with the name, and the earlier bundle stays +conf=$r/device/testdev/device.conf +descriptor() { printf 'CODENAME=testdev\nNAME="Test device"\nBOOT_IMAGES="%s"\nUFS_RW="%s"\n' "$1" "$2" > "$conf"; } +printf modem > "$k/images/modem.img" +printf vbmeta > "$k/images/vbmeta.img" +before=$(cd "$b" && sha256sum SHA256SUMS) +for c in "boot dtbo modem|boot_b dtbo_b modem_b userdata|BOOT_IMAGES.* not modem" \ + "boot dtbo vbmeta|boot_b dtbo_b vbmeta_b userdata|BOOT_IMAGES.* not vbmeta" \ + "boot dtbo|boot_b dtbo_b modem_b userdata|UFS_RW.* not modem_b"; do + IFS='|' read -r images rw says <<<"$c" + descriptor "$images" "$rw" + if out=$(bundle); then fail "BOOT_IMAGES=\"$images\" UFS_RW=\"$rw\" stops the bundle: it wrote $(grep -o '"partition": "[a-z_]*"' "$b/manifest.json" | cut -d'"' -f4 | xargs)"; fi + grep -cE "^bundle-manifest: .*$says\$" <<<"$out" >/dev/null || fail "the refusal names the partition ($says): $out" + [[ $(cd "$b" && sha256sum SHA256SUMS) == "$before" ]] && intact || fail "a refused descriptor leaves the bundle as it was" +done +descriptor "boot dtbo" "boot_b dtbo_b userdata" +pass "a descriptor naming modem, vbmeta or modem_b stops the bundle, and the earlier bundle stays" diff --git a/tools/bundle-manifest b/tools/bundle-manifest index 308ed5ce9..99ef46a40 100755 --- a/tools/bundle-manifest +++ b/tools/bundle-manifest @@ -51,6 +51,11 @@ FORMAT = 1 NEVER = ["slot A (any *_a partition)", "an unsuffixed partition name", "bootloader", "radio", "persist", "efs", "modem", "devinfo", "vbmeta", "fastboot -w", "fastboot --slot", "fastboot flashing", "fastboot erase", "fastboot format", "fastboot oem"] +# What a bundle may write: slot B's boot images and userdata, nothing else +# (AGENTS.md §1). bin/omamobile's load_device, initramfs/init's +# ufs_rw_load and tools/phone-smoke hold the same set. +IMAGES = ("boot", "init_boot", "vendor_boot", "vendor_kernel_boot", "dtbo") +UFS_RW = tuple(p + "_b" for p in IMAGES) + ("userdata",) def die(msg): @@ -171,6 +176,12 @@ def main(): allow = d.get("UFS_RW", "").split() if not boot_images or not allow: die("device.conf needs BOOT_IMAGES and UFS_RW") + for p in boot_images: + if p not in IMAGES: + die("device.conf: BOOT_IMAGES may hold only %s, not %s" % (", ".join(IMAGES), p)) + for p in allow: + if p not in UFS_RW: + die("device.conf: UFS_RW may hold only %s, not %s" % (", ".join(UFS_RW), p)) avb = {} for e in d.get("AVB_FOOTERS", "").split(): m = re.match(r"^([a-z_]+):(0x[0-9a-f]{1,10}|[1-9][0-9]{0,11})$", e) @@ -199,8 +210,6 @@ def main(): writes = [] for p in boot_images: - if not re.match(r"^[a-z_]+$", p): - die("bad image name %s" % p) if p + "_b" not in allow: die("%s_b is not on the storage-guard allowlist (UFS_RW)" % p) src = "images/%s.img" % p