Repository navigation
acquire: verify the attached process matches the selected identity - #56
Merged
Merged
Conversation
The capture used to hand lldb only the numeric PID, so a PID reused between selection and `process attach` could leave the privileged debugger stopped on an unrelated process before anything noticed. The selected PID, user and start time now travel into the capture. The lldb session runs in two phases: lldb first only attaches and prints its status. Once it reports the process stopped, the PID's user and start time are read again; only when they still match is the breakpoint (with its memory read) sent. Otherwise lldb is told to detach and quit, and capture fails closed with an error that asks for preflight to be rerun. When WeChat restarts before the capture records the old process's exit, the new process already existed at that moment and is still never attached. The capture now says so as soon as it sees it, and reports this timing ambiguity at the timeout instead of a plain timeout. The sudo smoke test gains step (e): the real lldb, as root, attaches to a small program the script starts, with the matching and with a wrong start time. Closes #51 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- Without a selected app, attach only to a listed PID that runs an executable named WeChat for this user and whose identity is unchanged when read again. - At the timeout, report the restart timing ambiguity before an earlier rejected candidate. - Say only what the check withholds: the capture breakpoint and the passphrase read (lldb itself inspects a process while attaching). - Smoke test: SIGKILL the sleeper, also from the exit trap. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- The no-target path reads only kernel metadata (PID, user, start time, executable path), never the app's Info.plist as root. - Detach instead of arming the capture when the identity check finishes after the deadline. - Report restart timing ambiguity only for a conclusive process listing. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- Without a selected app, a WeChat process that was found but couldn't be verified is reported as such at the timeout, not as "not running". - A process that started before the current target is never reported as its possible restart. - Smoke test: the sleeper lives longer, and the comment explains why its PID can't be recycled while the script holds it unreaped. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Bash may reap a background child before `wait`, so an unreaped child does not reserve its PID. The sleeper's user and start time are now recorded right after launch and passed to both root attach attempts as the expected identity; a recycled PID would show up as a mismatch. Cleanup kills the sleeper only while its PID still has that identity. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- If the stopped PID's identity can't be read because the process is confirmed gone, detach and report a target exit, so the capture follows a restart instead of failing as a mismatch. A live but unreadable PID still fails closed. - Smoke test: the sleeper is the forked child of a small supervisor that doesn't reap it until cleanup, so its PID stays reserved through both root attaches; cleanup never signals a bare PID. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Keeps both sides of the CaptureError and runSingleCapture changes from #54. An lldb exit during the attach phase is reported through #54's exitError. VerifiedPassphraseCaptureTests' stand-in lldb now reports the process stopped and waits for the post-check capture commands before printing reads, as real lldb does under the two-phase attach. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…dentity # Conflicts: # CHANGELOG.md # scripts/sudo-smoke-test-acquire.sh
…oke sleeper to the script - When the stopped PID is confirmed gone at the identity check, record the exit time before `detach`, which can wait up to 3 s, so a replacement started during that wait counts as starting after the exit. Tested with a stand-in lldb that ignores `quit`. - Smoke test (g): the sleeper's supervisor no longer has a 15-minute timer; it reaps the sleeper only when the stop file appears or the script (its parent) is gone, so the PID stays reserved through the last root attach. - sleeper_running rejects a zombie (Z) as well as a stopped (T) sleeper. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- At the timeout, a process that was found but couldn't be verified is reported before earlier rejected candidates, like the timing ambiguity. - The exit-before-detach test measures the detach wait after the recorded time instead of bounding lldb's startup, so a loaded runner can't flake it. - Smoke test (g) runs the capture verbosely and checks lldb's own transcript: the matching run shows `Breakpoint 1:` (the control), the mismatched run shows `Process <pid> detached` and no breakpoint at all. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Owner
Author
|
Sudo smoke test at 62e9167 on the owner's Mac: 🤖 Generated with Claude Code |
Merged
bojieli
added a commit
that referenced
this pull request
Nov 24, 2026
Set the version to 0.12.0 in Cargo.toml, the root package in Cargo.lock, and docs/distribution-dependencies.json. Date the CHANGELOG entry and move the new preflight blocker and the --output requirement under "Changed". Add the 0.12.0 setup skill notes and a "0.12.0 publication" checklist section. Live capture against WeChat was not re-tested. The sudo smoke test passed 17/17 at the #56 head 62e9167, including the real-lldb identity check (g). 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.
Closes #51
What changed
Selected identity in the capture.
WeChatProcessTarget.attachIdentity(PID, real UID, start time) is now what the capture attaches with, not a bare PID. With no selected target (a library-only path; the CLI always selects one), the unique WeChat PID is turned into an identity using only kernel metadata: user, start time, and an executable namedWeChat. It is read twice and must not change in between.Two-phase lldb session (
LLDBCaptureScript):attach(processID:)sends the settings,process attach -p N, andprocess status, then lldb waits on stdin with the process stopped.Process N stopped, the capture re-reads the PID's UID and start time (proc_pidinfo). Only if both still match does it sendcapture(architecture:), which holds the conditional breakpoint, thememory read, andprocess continue.detach(process detach/quit) and throwsCaptureError.attachedProcessMismatch. The error message says the breakpoint was never set, no passphrase was read, no output was written, and asks the user to rerun preflight.Once lldb is attached it holds the task port, so the breakpoint commands that follow reach the verified process even if the PID is recycled later. Some other edge cases:
F_SETNOSIGPIPE, so a write to an lldb that has already exited fails instead of raising SIGPIPE.Second note: replacement already running when the exit was recorded.
WeChatProcessSelector.replacementsStartedBeforeExitRecordedlists same-app processes that started after the current target but no later than the recorded exit, and weren't excluded at selection. It returns nothing for an inconclusive listing. The capture still never attaches to those processes. As soon as it sees one, it prints a note. If nothing that started later shows up before the deadline, it throwsCaptureError.replacementTimingAmbiguous, which explains the timing and asks the user to rerun preflight. This takes precedence overnoAcceptableCandidateand over a plain timeout. I chose to report at the deadline rather than fail on first sight, so a sibling started during the capture can't preempt a genuine later restart.CHANGELOG: new Unreleased → Fixed entries.
Tests
swift testpasses locally: 163 acquire tests after merging main, run on a copy without theGreenBubblesHistoryApptarget because this Mac has only the Command Line Tools. The new tests inTests/GreenBubblesAcquireTests/AttachIdentityTests.swiftuse fake process metadata and a shell-script stand-in for lldb that logs every command it receives:process detach/quitis sent, no breakpoint,memory readorprocess continueis ever sent, no candidate is offered, andattachedProcessMismatchis thrown.targetExited, also with no capture commands. An exit before the stop never reads the identity.AttachIdentity.mismatch,Process N stoppedparsing, the no-target identity rules, and the ambiguity helper (early restart, siblings, older processes, other users and app copies, inconclusive listings, no exit recorded). The error texts are checked too.LLDBCaptureScriptTestsnow covers the two phases, including that the attach phase contains nobreakpoint,memory, orcontinue.The real PID-reuse race can't be reproduced here. It needs a privileged attach racing a PID recycle. The tests reproduce the decision logic and the command ordering, not the kernel race.
Needs manual check (sudo)
scripts/sudo-smoke-test-acquire.shgains step (e). As root, the real/usr/bin/lldbattaches to a small sleeper that the script compiles and runs as you; it never touches WeChat. The step checks two things:The sleeper is a forked child of a supervisor that doesn't reap it until cleanup, so its PID stays reserved. Only
--no-sudowas run here (3 passed, 8 skipped). Please runscripts/sudo-smoke-test-acquire.sh. It is also the first check that real lldb printsProcess N stoppedthe way the parser expects when commands come in over the stdin pipe.A live WeChat capture (logout/login, including a restart during logout) was not tested here because WeChat isn't installed.
Review
I ran five rounds of Codex review (
codex review --base origin/main), and every finding has been addressed:Info.plist; no arming after the deadline; no ambiguity reported for an inconclusive listing.Merged origin/main (#53, #54). I kept both sides of the
CaptureErrorandrunSingleCapturechanges. An lldb exit during the attach phase is now reported through #54'sexitError. #54'sVerifiedPassphraseCaptureTestsdroverunSingleCapturewith a stand-in lldb that printed reads immediately. I updated that stand-in to reportProcess 1 stoppedfirst and to wait for the commands that follow the identity check, as real lldb does under the two-phase attach. The merge was not re-reviewed by Codex (the round cap had been reached); the full test suite passes.🤖 Generated with Claude Code