Repository navigation
Conversation
The extractor wrote straight into OUTDIR. The plans run it into the default out/vendor-firmware and tar that tree onto the phone, so a rerun for another image or device kept the earlier run's firmware and sensor registry files, and the firmware went into vendor-firmware.sha256 as if it were this run's. On ext4, debugfs exits 0 when a copy fails: for a missing file it writes nothing, so an older copy of the same name passed the size check, and for a short write (a full disk, a file size limit) it leaves a truncated file that passed too. A run that failed half way left a mix of old and new files. Each run now extracts into an empty staging directory inside OUTDIR (the -c camera APEX into a new file beside it), runs the checks there, checks that the checksum list names exactly the mapped files, and only then moves the previous outputs aside and the new ones into place: renames within OUTDIR, then the -c file. A failed run leaves the previous outputs and the -c file as they were; if a rename fails while publishing, what was already replaced is put back. The script replaces only what it writes: usr/lib/firmware/updates, usr/share/omamobile/sensors, vendor-firmware.sha256 and the -c file; the rest of OUTDIR stays. An ext4 copy fails on any debugfs message but its banner and the exact notes that it can't give a file the image's owner (as a user); the messages are read in the shell, so a nearly full disk can't hide them. A -c that names a directory, or a path inside the outputs the run replaces, is refused before anything is extracted. tools/phone-provision already extracts into a new directory per run; it calls the tool the same way as before. tests/extract-vendor-firmware (run by tests/all) runs the tool on made-up files with stand-in debugfs and fsck.erofs that print real debugfs's messages, and, where the host has mkfs.ext4 and debugfs, on a real ext4 image of the same files with a root-owned registry: a reused directory keeps no earlier firmware or registry file, a husky run drops a cheetah registry, and a missing file or registry, a short write (also under a file size limit), a failed sanity check, a missing camera APEX or a failed rename leaves the previous outputs byte for byte. Against the tool before this change, only 2 of its checks pass. No factory image was read and nothing ran on a phone. Found in an audit of the tools. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Thank you, this is a careful piece of work. Reusing I read the test, ran it (20 ok; against main's tool, 22 fail, as you said) and broke the tool on purpose in a few places. Making It's ready to merge. One practical thing: #492 also edits Two small, optional notes:
|
# Conflicts: # tests/all
Publishing moves the previous usr/lib/firmware/updates and usr/share/omamobile/sensors aside under OUTDIR and removes them once the new generation is in place. Nothing calls the tool with -o /, but an operator who did would have the host's own directories replaced. The tool now refuses an OUTDIR whose resolved path is /, right after it is resolved and before the scratch directory or anything else is written. tests/extract-vendor-firmware runs the tool with -o /, //, /usr/.. and a symlink to /, and checks the refusal message and that no scratch directory was made. Its image is all zeros, so a tool without the refusal stops at the image check before it could write under /: against the previous commit's tool these four checks fail and nothing is written there. The test header now says the checksum list is checked after a successful run; the tool's own check that the list names exactly the mapped files is a backstop no reachable state trips. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Note 🤖 Opus 5.5 replying on behalf of Victor. Implemented in 8d08b8c:
The existing checks and the original change remain unchanged; the shared tests/all merge conflict is still left for maintainer resolution. |
…s#491) The extractor wrote straight into OUTDIR. The plans run it into the default out/vendor-firmware and tar that tree onto the phone, so a rerun for another image or device kept the earlier run's firmware and sensor registry files, and the firmware went into vendor-firmware.sha256 as if it were this run's. On ext4, debugfs exits 0 when a copy fails: for a missing file it writes nothing, so an older copy of the same name passed the size check, and for a short write (a full disk, a file size limit) it leaves a truncated file that passed too. A run that failed half way left a mix of old and new files. Each run now extracts into an empty staging directory inside OUTDIR (the -c camera APEX into a new file beside it), runs the checks there, checks that the checksum list names exactly the mapped files, and only then moves the previous outputs aside and the new ones into place: renames within OUTDIR, then the -c file. A failed run leaves the previous outputs and the -c file as they were; if a rename fails while publishing, what was already replaced is put back. The script replaces only what it writes: usr/lib/firmware/updates, usr/share/omamobile/sensors, vendor-firmware.sha256 and the -c file; the rest of OUTDIR stays. An ext4 copy fails on any debugfs message but its banner and the exact notes that it can't give a file the image's owner (as a user); the messages are read in the shell, so a nearly full disk can't hide them. A -c that names a directory, or a path inside the outputs the run replaces, is refused before anything is extracted, and so is an -o that resolves to / (/, //, /usr/.., a link to /), before the scratch directory is made. tools/phone-provision already extracts into a new directory per run; it calls the tool the same way as before. tests/extract-vendor-firmware (run by tests/all) runs the tool on made-up files with stand-in debugfs and fsck.erofs that print real debugfs's messages, and, where the host has mkfs.ext4 and debugfs, on a real ext4 image of the same files with a root-owned registry: a reused directory keeps no earlier firmware or registry file, a husky run drops a cheetah registry, and a missing file or registry, a short write (also under a file size limit), a failed sanity check, a missing camera APEX or a failed rename leaves the previous outputs byte for byte. Against the tool before this change, only 2 of its checks pass. No factory image was read and nothing ran on a phone. Found in an audit of the tools. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
What and why
tools/extract-vendor-firmwarewrote straight into its output directory. The plans run it into the defaultout/vendor-firmwareand thentarthat tree onto the phone (WIFI-BATTERY-PLAN §2.2, BLUETOOTH-PLAN, AOC-PLAN C8.0). So:vendor-firmware.sha256as if this run had produced it.A run that failed half way also left old and new files mixed.
Each run now builds a whole new generation:
-ccamera APEX into a new file beside it), and runs the sanity checks there. It also checks that the checksum list names exactly the mapped files; that check is a backstop, since no reachable state trips it, so no test covers it directly (the tests check the list's contents after every successful run).-cfile. A failed run leaves the previous outputs and-cuntouched; if a rename fails while publishing, what was replaced is put back.-cthat names a directory or sits inside the replaced outputs is refused./(-o /,//,/usr/.., a symlink to/) is refused before anything is written, so a mistyped-ocan't make the run replace this machine's own/usr/lib/firmware/updatesand/usr/share/omamobile/sensors.The script replaces only what it writes:
usr/lib/firmware/updates,usr/share/omamobile/sensors,vendor-firmware.sha256and the-cfile. The rest of the output directory stays, andtar -C OUTDIR -cf - usrworks unchanged: the staging directory is hidden at the top and removed on exit. tools/phone-provision already uses a new directory per run, so it avoids stale-output effects and gains the stricter debugfs, checksum-list, and -c destination checks.tests/extract-vendor-firmware(new, added totests/all) runs the tool on made-up files, with stand-ins for debugfs and fsck.erofs that report errors the way debugfs does: on stderr, with exit 0. Where the host hasmkfs.ext4anddebugfs, it also runs on a real ext4 image of the same files, with a root-owned registry, and with debugfs under a file size limit. It checks that:-cand a failed rename;-o /,//,/usr/..and a symlink to/are refused before anything is written: no scratch directory is made and nothing is printed as done. The image in these checks is all zeros, so a tool without the refusal stops at its image check instead, and the test never writes under/.EVF=pathruns the same test against another copy of the tool.Device and build
uname -r): n/aBefore: the new test against main's tool (7172296): 2 ok and 26 not ok lines ("26 check(s) failed"). The captures below are from the first version of this PR, before the
-o /checks were added (then 2 ok, 22 failed).After: the same test against the first commit (8a456cb): 20 ok lines and exit 0. With the second commit the test has 24 ok lines and exits 0; the
-o /captures follow.The
-o /refusal, before: the test against the first commit's tool (8a456cb), which has no refusal: the four-o /checks fail ("4 check(s) failed"), each stopping at the image check, and nothing is written.After: the same test against this change: 24 ok lines and exit 0.
Checks (no phone needed)
tools/pr-check origin/mainpassestests/allpasses. Skipped on this host for reasons unrelated to this change: phone-provision's container leg (no Docker), the AOSP mkbootimg layouts, dtc overlays, lz4, repo-add, bsdtar, and the root image smoke test.tests/packages: not run; no package touchedversionbumped: none changedCo-Authored-By:trailerOn the phone
userdata, weakens the storage guard, or reads registers from userspace. It doesn't touch the phone.
Not applicable: this tools-only change never runs on a phone.tools/phone-smokereportFound in an audit of the tools by Kimi K3.1 High and Sol 6.1 xhigh.
Prior PRs: none make this change. The open modem-sit drafts (#374, #376, #378, #380) add tegu entries to the same file's map; those hunks merge with this change without a conflict, and their files land in the same generation.
Generated with Claude Opus 5.5 in T3 Code Nightly