Skip to content

install-phone: stop when cpio can't list the shipped ramdisk - #623

Merged
derekross merged 1 commit into
derekross:mainfrom
only21mil:build/install-phone-cpio-list-failure
Nov 11, 2026
Merged

derekross merged 1 commit into
derekross:mainfrom
only21mil:build/install-phone-cpio-list-failure

Conversation

@only21mil

Copy link
Copy Markdown
Contributor

What and why

Follows the maintainer's suggestion on #596: the key check still listed the decompressed ramdisk with cpio -it … 2>/dev/null | grep -c … || true, so an archive that lz4 decodes but cpio can't list was read as holding no SSH keys.

Reproduced on main through the bundle's ./install --unsigned, with only fastboot faked. In a bundle whose ramdisk is valid lz4 around a truncated cpio (cpio -it exits 2, "premature end of file"), the install appended the owner's key to the broken archive, showed the plan and flashed every partition.

The listing is now its own step with its own message, before the plan and any flash: "cpio couldn't list vendor_kernel_boot.img's ramdisk: <cpio's reason>". With --quiet, cpio still lists filenames on stdout and suppresses the block-count summary on stderr. On bytes that aren't an archive, GNU cpio 2.15 first prints a Malformed number <raw bytes> line for each offset it tries, hundreds of them, so its stderr goes to a file in the work directory and the message carries its last line, the reason. The key check greps the listing from a here-string with grep -q, so a ramdisk without authorized_keys still gets the key, with no || true. It stays inline, because the bundle ships install alone (L-497).

Before, on main (6a9251f): the ramdisk fails cpio -it, yet ./install appends the key and flashes all six partitions. Output trimmed by the grep -E shown.

Before: main's install flashes a ramdisk cpio can't list

After, on this branch (38c7e15): the same truncated-cpio case stops with the new message, and nothing is flashed.

After: this branch's install stops before the plan

Both bundles come from a local script that builds them as tests/install-phone-initramfs does (the hook's omamobile-boot-images packs the images) and copies that revision's tools/install-phone in as install. The install runs in a bwrap sandbox with the checkout at /mnt, so it prints no local paths.

Regression test (a stand-in, not the reproduction): tests/install-phone-initramfs adds cpio -it to its failing steps. With main's tool it fails at "refuses a failing cpio -it"; with the new die replaced by || true it fails there too (L-419). Its byte comparison passes with the install under umask 077, 022 and 002.

Device and build

  • Phone: none: laptop tool and its test only
  • Kernel release (uname -r): n/a
  • Packages changed, with versions: none

Checks (no phone needed)

  • tools/pr-check origin/main passes
  • tests/all passes (503 ok, 0 not ok)
  • tests/packages: no package touched
  • Each changed package has its version bumped, and the new version is in the commit subject (no package changed)
  • Commits have area prefixes and bodies that say why; any AI help is a Co-Authored-By: or Assisted-by: trailer, never a Signed-off-by:

On the phone

  • I ran this on my own phone, booted into this build: no, the change is in the laptop-side installer and its test
  • Runbook steps passed (plan, step, result): n/a
  • What I did not test: a real bundle installed on a phone; cpio implementations other than GNU cpio 2.15
  • Nothing in this change writes outside slot B and userdata, weakens the storage guard, or reads registers from userspace (AGENTS.md §1): flash() and its allowlist are unchanged, and the new stop comes before the plan
tools/phone-smoke report

Not applicable: install-phone runs on the laptop (CONTRIBUTING.md §6.5).

Generated with Claude Opus 5.5 in T3 Code Nightly

The maintainer's follow-up on derekross#596: the key check still read the
decompressed ramdisk with "cpio -it ... 2>/dev/null | grep -c ...
|| true", so an archive that lz4 decodes but cpio can't list was
counted as holding no keys, and the key was appended to it. A stand-in
that fails only the cpio -it call showed it, and so did a bundle whose
ramdisk is a truncated cpio inside valid lz4, run through ./install
--unsigned with only fastboot faked: the install appended the key to the
broken archive, showed the plan and flashed every partition.

The listing is now its own step with its own message ("cpio couldn't
list vendor_kernel_boot.img's ramdisk: <cpio's reason>"), before the
plan and before any flash. With --quiet, cpio -it says nothing when it
lists; given bytes that aren't an archive, GNU cpio 2.15 prints a
"Malformed number <raw bytes>" line for every offset it tries (786
lines for about 1 KB of text) and then its reason ("premature end of
archive"), so its stderr goes to a file in the ramdisk work directory
and the message carries the last line. The key check greps the listing
from a here-string with grep -q, so the no-match case needs no
"|| true": a ramdisk without authorized_keys still gets the key.

The flashed bytes don't change: tests/install-phone-initramfs's byte
comparison passes with install under umask 077 (the test's), 022 and
002. Its failing-step test adds cpio -it: before this change it failed
at "refuses a failing cpio -it"; with the new die replaced by
"|| true" it fails there again.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@derekross

Copy link
Copy Markdown
Owner

Thanks, @only21mil, this is the follow-up I asked for on #596, and you found the worse half of it: a ramdisk that lz4 decodes and cpio can't list was flashed with the key appended.

I checked it against today's main, since tools/install-phone changed three times today. It merges cleanly, and the new stop sits before the plan, the typed codename and the first fastboot flash. tests/install-phone-initramfs passes on the merge and fails with main's tool at "refuses a failing cpio -it". By hand, a newc archive cut short gives exit 2 and cpio: premature end of file as the last line, which is what the message shows.

One thing for a later PR, not this one: --verify-only (new in #641) stops before this step, so it won't notice a ramdisk cpio can't list. It could decompress and list the ramdisk too.

Merging.

@derekross
derekross merged commit e37f9ab into derekross:main Nov 11, 2026
2 checks passed
@only21mil

Copy link
Copy Markdown
Contributor Author

Note

🤖 Opus 5.5 replying on behalf of Victor.

#648 is that follow-up. --verify-only now extracts, decompresses and lists slot B's ramdisk before it stops. In the truncated-cpio reproduction, --verify-only and a full install both stop there with cpio couldn't list vendor_kernel_boot.img's ramdisk: cpio: premature end of file, before the phone is contacted.

One side effect: the work directory and its trap cleanup EXIT now come before the ramdisk step. So --verify-only creates the work directory, and a run that stops at --verify-only, a serial mismatch, a slot B refusal or an invalid answer now removes exactly root.img, root.simg, firstboot.conf, authorized_keys, boot-update.conf and the whole ramdisk/ directory from it, leftovers from an interrupted run included. Earlier failures behave as before.

robertzas pushed a commit to robertzas/omarchy-mobile that referenced this pull request Nov 14, 2026
…ss#623)

The key check read the decompressed ramdisk with cpio -it, discarded its errors and counted matches, so an archive cpio couldn't list counted as holding no keys, and the install went on to append the owner's key to it and flash every partition. The listing is now its own step that stops with cpio's reason, before the plan and any write. tests/install-phone-initramfs adds cpio -it to its failing steps.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants