Repository navigation
linux: Refuse to attach to processes frozen by the cgroup freezer - #1317
Merged
Merged
Conversation
Contributor
Author
|
The remaining red job, |
A process frozen by the cgroup v2 freezer, e.g. by Android's cached-apps freezer, still enters ptrace-stop, but PTRACE_CONT does not run it. Our first remote call thus timed out, and since SETREGS fails on a running thread the target kept the call's registers, crashing once thawed. Fail early when the process is frozen, and re-stop the thread before restoring its registers after a failed remote call.
MinGW's winternl.h lacks PROCESS_BASIC_INFORMATION.Reserved3, so define our own struct for the parent PID lookup.
oleavr
force-pushed
the
fix/frozen-attach
branch
from
December 3, 2026 09:53
905c9a4 to
1ffe97b
Compare
Member
|
Thanks! 🙌 |
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.
Problem
Attaching to a process that is suspended by the cgroup v2 freezer — as used
by Android's cached-apps freezer for backgrounded apps — fails and, worse,
corrupts the target:
Device.attach()times out after ~5 s, and theprocess then crashes with
SIGSEGVthe moment it is thawed.Reproduction (rooted Android 15 arm64 emulator, frida-server 17.30.0)
am freeze --sticky <pid>(the framework's cached-apps freezer does thesame automatically after ~70 s). The task is now in
do_freezer_trap(
/proc/<pid>/cgroup→0::/…,cgroup.events: frozen 1).device.attach(pid)→ after ~5 s:TimedOutError: unexpectedly timed out while waiting for stop from process with PID <pid>.am unfreeze --sticky <pid>→ within a second the process dies:signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x320,backtrace
#00 pc 0000000000000320 <unknown>.The same sequence also reproduced 4/4 on a physical Pixel running Android 17, with the framework's
freezer freezing the app on its own (no
am freeze).Spawning (
-f+ resume) and attaching to a non-frozen process both work; sodoes unfreezing first and then attaching.
Cause
PTRACE_SEIZE+PTRACE_INTERRUPTdo place a frozen task in a ptrace-stop,so
SeizeSession.init_async()succeeds and the injector proceeds to set up itsbootstrap
mmap()remote call inRemoteCall.execute()(
src/linux/frida-helper-backend.vala): it saves the original registers, writesthe call's registers (on arm64
lr = DUMMY_RETURN_ADDRESS = 0x320,pc = mmap,x8 = __NR_mmap, args inx0..x5) and issuesPTRACE_CONT.But a cgroup-frozen task does not actually run on
PTRACE_CONT— it goesstraight back to sleep in the freezer — so the call never reaches the dummy
return address, and
wait_for_signals({SEGV, STOP})times out. The restore inthe failure path then silently fails:
PTRACE_SETREGSonly works while thethread is in a ptrace-stop, and after the
PTRACE_CONTit is not, so thecatch (Error e) {}swallows theESRCHand the target is left with the remotecall's registers in place. When the app is later thawed it runs the abandoned
call and faults at the
0x320return sentinel — exactly the observed crash(the crash register dump shows
x8=0xde(mmap),x2=0x7(RWX),x3=0x22(
MAP_PRIVATE|ANON),x0=a freshly-mapped address,pc=lr=0x320).Fix
Two parts, one concern — a frozen process cannot be driven through ptrace
remote calls, so never leave it mutated:
init_async()now detects the cgroup v2 freezer upfront (via
/proc/<pid>/cgroup→cgroup.events: frozen 1), beforePTRACE_SEIZE, and throws a clearError.INVALID_OPERATIONnaming thefreezer. No ptrace call is made, so the process is left exactly as it was.
RemoteCall.execute()now re-stops the thread beforerestoring the saved registers if the plain
SETREGSfails, so a target thatgets frozen mid-injection (a race) is restored in every case instead of being
left with a half-applied call frame.
Detection is read-only (
/proc+/sys/fs/cgroup), needs no elevatedpermission, and is a no-op on systems without the cgroup v2 freezer (the reads
fail and it returns
false, so normal attaches are unaffected).Testing
Rooted
google_apisAndroid 15 (API 35) arm64 emulator; stock frida-python17.30.0 client. Server built from this branch for
android-arm64.TimedOutErrorafter 5.49 sInvalidOperationErrornaming the freezer, 0.02 sam unfreezeSIGSEGV … fault addr 0x320New error message:
(The cgroup-freezer scenario needs a rooted device plus cgroup delegation, so
it is not expressible as a portable unit test in the suite; verified with a
scripted emulator reproduction that fails before and passes after.)
A second commit fixes the MinGW builds that main has been failing since
86f584e:
frida_create_loader_tokenread the parent pid asPROCESS_BASIC_INFORMATION.Reserved3, a name only MSVC's winternl.h has.It now reads a local struct with the documented layout, checked against
MinGW's header on i686 and x86_64. Happy to split it out into its own PR.