Repository navigation
waze-on-cluster: apply the CarPlay patch in memory; carplay stays stock on disk - #233
Draft
robertnisipeanu wants to merge 1 commit into
Draft
robertnisipeanu wants to merge 1 commit into
robertnisipeanu wants to merge 1 commit into
Conversation
…disk libwocpatch.so, preloaded into carplay.service next to BMW's libschedconfig, applies the six edits to carplay's memory before its own code runs. carplay_patch.js plan makes the plan from the stock file with the locator and an apply's checks; the library verifies the build-id and every site's shipped bytes and writes all edits or none. Boot recovery arms each start through /run/woc-preload/carplay.env (the drop-in's EnvironmentFile=-) from a record that describes the file as it is, counts armed starts with the existing thresholds and records (a crash restart counts even after a healthy run), and at the threshold stops arming: no write of / and no remount. An earlier release's file patch is reverted from its verified backup and the plan armed in one install step. Android Auto's patch stays in the file. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
waze-on-cluster applies CarPlay's cluster-map patch in CarPlay's memory at each start.
/usr/bin/carplaystays as it ships, and nothing on/is remounted or written to patch, unpatch or recover CarPlay. Android Auto's patch is unchanged, still written toaapdandaapd.conf; the same mechanism can take it later.Draft: this waits for a car test before it can merge or release.
Design
Where and when the edits apply.
libwocpatch.sois preloaded intocarplay.service. Its constructor runs after the shared libraries' own constructors and before carplay's static initialisers andmain, so none of the edited code has run yet. One of the edits is a static initialiser'slea. It runs in every armed start, the startspatchdmakes with SIGKILL+start included.How sites are found and verified. There is one pattern description: the existing locator in
carplay_locate.js.carplay_patch.js planruns as root on the stock file on disk, with every check an apply's first edit runs (head unit, coding, locator, proven build or--unproven). It builds the edited image with the same codeapplyuses (edited(), shared by both). It writes a plan with one line per edit region: virtual address, shipped bytes, bytes to write. Regions the edit leaves stock are listed too. The plan is then laid back over the file (overlay) and kept only if that reproduces the edited image exactly. The C library locates nothing. It only verifies:PT_NOTE; any other program, such as a child inheritingLD_PRELOAD, is left alone;PT_LOAD, outsidePT_GNU_RELRO, and reads exactly its stock bytes.All or nothing. All sites are verified before any write. Each page is made writable; code pages stay executable for that moment, because libdlt's constructor has already started two threads, though neither runs carplay's code. Then the library writes, restores each segment's protection and reads every region back. Any failure puts the stock bytes back and restores the protections. Only a page that cannot get its protection back ends carplay (
abort), which boot recovery counts as a crash. The result goes to/run/woc-preload/carplay.resultand the journal:{pid, applied, edits, why}, in a file the boot step created for carplay's user. The library never creates files.Arming. The drop-in written at install has
EnvironmentFile=-/run/woc-preload/carplay.env. Without that file carplay starts stock. Boot recovery's boot step (and the watcher, andpatchdafter a change) decides per boot from the record and the crash counts, then writes the plan copy, the empty result file and, last, the env file.LD_PRELOADis read from the unit (/usr/lib/libschedconfig.so.1), with this version's library appended: anEnvironmentFilevalue replacesEnvironment=, so BMW's preload is kept explicitly. The record (/var/opt/waze-on-cluster/inmem-carplay.json) arms only while carplay's inode, size, mtime and the plan's SHA-256 match. A firmware update or any other write of the file arms nothing.Crash accounting. An armed start is counted exactly like a patched start today: thresholds of 1 on trial or unproven, 2 when proven, unknown boots counted in pairs, and the shutdown mark plus the recmgr/crashhandler restart records. One rule is stricter. For an armed start, a recorded crash restart counts even after the 60 s healthy mark, because a reset that beats the shutdown mark leaves only that record. At the threshold the restore removes the env file and turns the record off (
by: "recovery"). No file on/is written and there is no remount, and the next start, this boot or the next, is stock. A trial becomes proven after a healthy run in which the running carplay's memory (/proc/<pid>/mem, read-only) holds the plan and the library's result names its PID. The boot-recovery state is written through a per-process temporary file, since the boot step, the watcher andpatchdall write it.Restarts to get the map.
activatepatchdmay restart CarPlay (recmgr's entry and the drop-in loaded), SIGKILL+startDuring a migration, every later start of that boot is armed, a crash restart included, so the map is never off between the two patches. Where the file holds another change besides our patch, or a patch that would start on trial while boot recovery counts a failure, or arming cannot work here, the earlier patch stays in the file under this version's boot recovery. An earlier patch whose bytes equal the plan's, and which its record says ran healthy on this car coded 7, keeps its proven state; anything else starts on trial.
Status.
patchdreads the plan's overlay forres,safe,mapurland the mode, and checks the running carplay's memory at every plan region. The app seesPatchedwhile that memory holds the plan,Patched after restartwhile it does not, the conflictnot applied in memory: <why>when the library refused for that PID, andRemoved after restartafter Remove patch while the patch still runs. The existing conflicts (untested build, coding, another launcher) are unchanged.Rollback.
deactivateremoves the env file, record and plan, and reverts any earlier on-disk patch. A release installed afterwards finds a stock carplay with no backup and patches the file as it always did. Older drop-ins have noEnvironmentFile, so an env file left in/runis never read. Coming back, this version never arms its plan over an older release's file patch, because the record no longer describes that file; its disk-patch boot recovery handles it.rollback_test.jspart 6 runs every release from 0.5.0 on over the in-memory layout: crash loop, Remove patch and activate, then this version's recovery and removal.Room to grow (not built here)
SO_PEERCRED), and be reached only throughpatchd.Not done
aapd.confwould need a per-unit bind mount or an open interposition./run, then installs this build.AI: Claude Code, Claude Opus 5.5
Tested:
make test-preload(new):libwocpatch.soagainst a test PIE, built with the unit's gcc 7.5 / glibc 2.27 toolchain in Docker. It covers .rodata and .text edits, another program's build-id, one site not stock, a cut-short plan, an unknown line kind, a count mismatch, an address outside the program, no plan, no env, a thread from another library's constructor, a crash build aborting after it applies, the result file never created, and nothing exported.make testhost suites with carplay 22.28.3 (CARPLAY_BIN):inmem_test.js: plan and overlay, proven carry-over rules, arm and disarm, the memory check, boot recovery counting armed starts, the stricter tally, a firmware update;patchd_patch_test,patchd_activate_test(migration cases included) andpatchd_reboot_test, updated for the in-memory behaviour;recovery_test, androllback_testwith part 6 over every release;Human review: no
Screenshots: n/a
🤖 Generated with Claude Code