Repository navigation
Conversation
hook_strip and hook_add wrote each line of install-recovery.sh and qb_runtime.sh again with echo, which expands backslashes in mksh as in dash: \\ became \, and a \c ended the output, so V="x\cY"; echo ok lost its closing quote and joined the next line. Lines now go through hook_line: mksh's print -r on the unit, or (a shell without print, as dash in the off-car tests) echo with backslashes doubled and a leading - escaped, checked on a test line when lib.sh loads. hook_add checks the new file before it goes in: without the block it must be the file as it was, or the file is left alone. Tests with backslashes, \c, -n lines and no last newline, in the test shell and in mksh when it's installed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The Method, ClassObject and ArrayObject offsets are the EV6 libdvm's, with no check that a unit's libdvm matches. Before Bridge.init they're read back from Bridge's own handleHookedMethod and invokeOriginalMethodNative (class, name, shorty, flags, argument count, the nativeFunc dvmSetNativeFunc just wrote), the primitive types of int, void and Bridge, and an Object[3]'s length. On a mismatch the loader logs which one and doesn't run Bridge.init, so nothing is hooked. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
An update only checked that app_process.hmgapi-stock started like a binary, so a copy cut short, zero-filled or otherwise damaged passed. It's now checked against stock.txt; an unknown copy comes back from the stock backup when that is a known build (the RESCUE path), and with neither known the update is refused with nothing changed, as a new install is. HMGAPI_FORCE=1 stays for maintainers. Tests: a short copy, a zero-filled one, one that starts with ELF but has the wrong md5, each with and without a stock backup. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
When exec of app_process.hmgapi-stock fails, the wrapper runs the install's backup, /data/hmgapi/stock/system/bin/app_process, if it starts like an ELF binary, after making it 700 (it's 600 under the install's umask). On a unit where SELinux refuses an exec from /data it fails too and the wrapper exits 127 as before. The EV6 boots with SELinux disabled (permissive). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…, zygote fallback Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Each log line goes to the start of the test's kmsg (a plain file, not /dev/kmsg), so the second exec failure's line writes over the first and counting both always found one. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
VysseCodes
reviewed
Nov 30, 2026
VysseCodes
left a comment
Collaborator
There was a problem hiding this comment.
Careful work. The /data fallback only checks for an ELF header, which is fine as a last resort.
Merge order: after #426 (this is based on it).
DY-Jeong
added a commit
to DY-Jeong/HMG-API
that referenced
this pull request
Dec 1, 2026
…, Dalvik layout check, update md5 check, zygote fallback From AwsomeFox/fix/boot-hardening (Open-HMG#436).
6 of 67 tasks
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What this changes
Boot hardening from the 2026-11-26 review. Stacked on #426 (
fix/sync-stock-copy, thesyncafter the stock copy is made), so this PR's diff is only the commits after it; it moves tomainonce #426 lands.install/common/lib.sh).hook_stripandhook_addwrote each line ofinstall-recovery.shandqb_runtime.shagain withecho, which expands backslashes in mksh as in dash:\\became\, and\cended the output, soV="x\cY"; echo oklost its closing quote and joined the next line. Lines now go throughhook_line: mksh'sprint -ron the unit, or in a shell withoutprint(dash in the off-car tests)echowith backslashes doubled and a leading-written as\0055. Whichever is used is checked on a test line whenlib.shloads. If neither is exact,hook_addfails.hook_addalso checks the new file before it goes in: without the block it must be the file as it was (by md5), or the file is left alone. Noprintf(tools/check-scripts.sh: not on the unit).core/loader/loader.c). The offsets are the EV6 libdvm's. BeforeBridge.initthey're read back from Bridge's ownhandleHookedMethodandinvokeOriginalMethodNative: class (0x00), name (0x10), shorty (0x1c), flags, insSize/registersSize, insns, and the nativeFunc (0x28) thatdvmSetNativeFuncjust wrote. It also checks the primitive types of int, void and Bridge (0x44) and anObject[3]'s length (0x08). On a mismatch it logs which field and doesn't runBridge.init: no hooks. If the name offset is wrong, reading it could still crash the zygote, which the boot guard catches; apps are no longer at risk.install/common/install.sh). An update only rannot_stockonapp_process.hmgapi-stock, so a copy cut short, zero-filled, or starting with ELF but changed passed. It's now checked againststock.txt. An unknown copy comes back from/data/hmgapi/stock/system/bin/app_processwhen that is a known build (the RESCUE path). With neither known, the update is refused with nothing changed, as a new install is.HMGAPI_FORCE=1stays maintainers-only. The catalogue'sengine update hmgapi(Catalogue, dependencies and updates in the engine #423) runs this installer.core/zygote/zygote.c). When exec of the stock copy fails, it runs/data/hmgapi/stock/system/bin/app_processif it starts like an ELF binary, afterchmod 700(it's 600 under the install's umask 077). This brings back a unit whose/systemstock copy was lost. SELinux: the EV6 boots withandroidboot.selinux=disabled(permissive), and/data/local/tmp/nemesis-dalready runs from/data. On an Enforcing unit the exec is probably refused and the wrapper exits 127 as before.CHANGELOG.mdandCLAUDE.mdupdated.The related fix on
catalog/app(the HTTPS library kept before/systemchanges) is pushed to #424 as its own commit.Tested on
tools/test-all.shpasses: only part of it so far (below). The full run is going: https://github.com/Open-HMG/HMG-API/actions/runs/46022026240Off-car, on macOS:
install/common/test.sh: 48 checks pass in dash and macOSsh. Against the oldlib.shthe new checks fail (10), withsh -nreporting the unclosed quote. The backslash checks also run in mksh when it's installed (CI); there was no mksh here.install/common/install-test.sh: 295 checks pass, with a stand-in payload (placeholder binaries, this tree's scripts and maps). Against the oldinstall.sh, 17 of the new update checks fail.install/common/orders-test.sh: 8 pass.tools/test-all.sh --fast: 30 ok, 1 skipped (mkicon: no ImageMagick).loader.candzygote.ccompile for the ARM target.core/zygote/test.sh(11 new fallback checks) needs qemu-arm and runs only in CI.Tested on cars
Off-car only. Still to try on a car:
qb_runtime.sh)HMGAPI_SELFTESTChecklist
tools/check-scripts.shpasses/systemkeeps a stock check, a backup and an exact restoreCHANGELOG.mdupdated;wiki/not updated🤖 Generated with Claude Code