From 7f1bd32a4ddb6f3a433116dc949880ccbe4bc58c Mon Sep 17 00:00:00 2001 From: Victor Vogel Date: Tue, 10 Nov 2026 02:19:27 +0000 Subject: [PATCH] install-phone: stop at a failing decompress of the shipped ramdisk The maintainer's follow-up on #576: the failing-step test fails install, cpio's pack and lz4's compress, but not the decompress of the ramdisk the bundle ships (lz4 -dc). A stand-in that fails only that call showed what happens: - the key check (lz4 -dc | cpio -it | grep -c ... || true) swallowed the failure and counted the ramdisk as holding no keys; - the append's { lz4 -dc ... && cat extra.cpio; } | lz4 -l failed under pipefail, so the install did stop before anything was flashed, but its message blamed the recompress ("lz4 couldn't recompress ..."). The ramdisk is now decompressed once, by its own step with its own message ("lz4 couldn't decompress vendor_kernel_boot.img's ramdisk"), and the key check and the append read that file. lz4 gets the same stream as before (the shipped archive, then the key's cpio), so the image is the hook's byte for byte: the byte comparison passes with install under umask 077 (the test's), 022 and 002. tests/install-phone-initramfs adds lz4 -dc to the failing steps: before this change it failed on the message; with the new die replaced by "|| true" the install carries on and the test fails at "refuses". Co-Authored-By: Claude Opus 5.5 --- tests/install-phone-initramfs | 6 ++++-- tools/install-phone | 5 +++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/tests/install-phone-initramfs b/tests/install-phone-initramfs index 0f36f6a22..6f837a861 100755 --- a/tests/install-phone-initramfs +++ b/tests/install-phone-initramfs @@ -241,8 +241,10 @@ pass "an image the owner's key makes too large for its partition is refused befo # Each step of the append that fails (a stand-in that exits 1 on that call) # stops the install with a message, rather than flashing the ramdisk without -# the key: copying the key, cpio packing it, lz4 recompressing +# the key: copying the key, cpio packing it, lz4 decompressing the shipped +# ramdisk, lz4 recompressing for step in "install 600 can't stage the owner's key" "cpio -o cpio couldn't pack the owner's key" \ + "lz4 -dc lz4 couldn't decompress vendor_kernel_boot.img's ramdisk" \ "lz4 -l lz4 couldn't recompress vendor_kernel_boot.img's ramdisk"; do read -r tool arg why <<<"$step" mkdir -p "$t/bad-$tool" @@ -250,7 +252,7 @@ for step in "install 600 can't stage the owner's key" "cpio -o cpio couldn't pac chmod +x "$t/bad-$tool/$tool" PATH=$t/bad-$tool:$PATH refused "a failing $tool $arg in the key's append" "$why" done -pass "a failing step of the key's append (install, cpio or lz4) stops the install before anything is flashed" +pass "a failing step of the key's append (install, cpio, lz4 -dc or lz4 -l) stops the install before anything is flashed" # The ramdisk image under an AVB footer can't take the key: refused printf 'AVB_FOOTERS="vendor_kernel_boot:0x4000000"\nAVB_ROLLBACK_INDEX=1\nAVB_SECURITY_PATCH=2026-07-05\n' >> "$BUNDLE/device.conf" diff --git a/tools/install-phone b/tools/install-phone index 6c727a255..00bcafdd4 100755 --- a/tools/install-phone +++ b/tools/install-phone @@ -628,7 +628,8 @@ if [[ -n $ramdisk_image ]]; then [[ -z ${avb_size[$ramdisk_image]:-} ]] || die "$conf: AVB_FOOTERS names $ramdisk_image, which carries the ramdisk: the owner's key can't be added to a signed image" rm -rf "$ramdisk_dir" && mkdir -p "$ramdisk_dir" vendor_ramdisk get "$images/$ramdisk_image.img" "$ramdisk_dir/shipped.cpio.lz4" || die "can't read the ramdisk of $ramdisk_image.img" - keyfiles=$(lz4 -dc "$ramdisk_dir/shipped.cpio.lz4" 2>/dev/null | cpio -it --quiet 2>/dev/null \ + lz4 -dc "$ramdisk_dir/shipped.cpio.lz4" > "$ramdisk_dir/shipped.cpio" || die "lz4 couldn't decompress $ramdisk_image.img's ramdisk" + keyfiles=$(cpio -it --quiet < "$ramdisk_dir/shipped.cpio" 2>/dev/null \ | grep -cE '^(\./)?root/\.ssh/authorized_keys$' || true) if [[ $keyfiles != 0 ]]; then note "$ramdisk_image.img's initramfs already holds SSH keys (a development build): left as built" @@ -644,7 +645,7 @@ if [[ -n $ramdisk_image ]]; then cpio --help 2>/dev/null | grep -c -- --reproducible >/dev/null && reproducible=(--reproducible) (cd "$extra" && find . -mindepth 1 | LC_ALL=C sort | cpio -o -H newc --owner=0:0 --quiet "${reproducible[@]}") > "$ramdisk_dir/extra.cpio" || die "cpio couldn't pack the owner's key for the initramfs" - { lz4 -dc "$ramdisk_dir/shipped.cpio.lz4" && cat "$ramdisk_dir/extra.cpio"; } | lz4 -l -9 -q > "$ramdisk_dir/initramfs.cpio.lz4" || + cat "$ramdisk_dir/shipped.cpio" "$ramdisk_dir/extra.cpio" | lz4 -l -9 -q > "$ramdisk_dir/initramfs.cpio.lz4" || die "lz4 couldn't recompress $ramdisk_image.img's ramdisk with the owner's key" vendor_ramdisk set "$images/$ramdisk_image.img" "$ramdisk_dir/initramfs.cpio.lz4" "$ramdisk_dir/$ramdisk_image.img" || die "rewriting $ramdisk_image.img with the new ramdisk failed"