# System-process ptrace through I/O accounting The existing Zygisk card shows **init ptrace (I/O)** and **zygote ptrace (I/O)** in its Methods section. Positive results also appear in Signals. Either traced result makes its row and the card red. Unknown results remain informational and reduce coverage. The probe does not set any root-family flag or identify an injection framework, and it does not read logcat. The readproc group warning is part of **LSPosed > Zygote permissions**. That method queries the existing shared isolated helper and warns in yellow when GID 3009 is missing. Zygisk has no separate group row or warning count. Its dedicated I/O service still checks its own readproc group before starting calibration; a missing or unknown precondition leaves the I/O result unavailable. ## Collection and ownership SystemPtraceProbe binds a fresh, non-exported SystemPtraceService instance. The manifest requires a plain isolated process and explicitly disables app zygote. The host passes Os.getppid() and the service checks that it has the same parent. This checks the system zygote for the running app ABI, not a second 32/64-bit zygote. A different parent, such as a wrapper, leaves the probe unavailable. ## Isolated readproc check The service calls getgroups before changing dumpability or forking any worker. The native payload carries a required READPROC field: 0 means unknown, 1 present, and 2 missing. Only a successful group query can produce a missing result. The existing 32-entry buffer covers the reviewed zygote group list; EINVAL from a larger group list remains unknown. Missing or invalid payload states are not treated as missing groups. The group result survives later coordinator failures. The AOSP path is: init gives system zygote the readproc group; ProcessList leaves gids null for an isolated process; SetGids leaves the inherited groups unchanged for a normal child with null gids. Relevant source locations: | Release | Zygote groups | Isolated-process gids | Native SetGids | | --- | --- | --- | --- | | Android 10 | [init.zygote64.rc:5](https://android.googlesource.com/platform/system/core/+/android10-release/rootdir/init.zygote64.rc#5) | [ProcessList.java:1462–1464](https://android.googlesource.com/platform/frameworks/base/+/android10-release/services/core/java/com/android/server/am/ProcessList.java#1462) | [Zygote.cpp:432–445](https://android.googlesource.com/platform/frameworks/base/+/android10-release/core/jni/com_android_internal_os_Zygote.cpp#432) | | Android 11 | [init.zygote64.rc:5](https://android.googlesource.com/platform/system/core/+/android11-release/rootdir/init.zygote64.rc#5) | [ProcessList.java:1763–1765](https://android.googlesource.com/platform/frameworks/base/+/android11-release/services/core/java/com/android/server/am/ProcessList.java#1763) | [Zygote.cpp:529–550](https://android.googlesource.com/platform/frameworks/base/+/android11-release/core/jni/com_android_internal_os_Zygote.cpp#529) | | Android 16 | [init.zygote64.rc:5](https://android.googlesource.com/platform/system/core/+/android16-release/rootdir/init.zygote64.rc#5) | [ProcessList.java:1879–1882](https://android.googlesource.com/platform/frameworks/base/+/android16-release/services/core/java/com/android/server/am/ProcessList.java#1879) | [Zygote.cpp:534–555](https://android.googlesource.com/platform/frameworks/base/+/android16-release/core/jni/com_android_internal_os_Zygote.cpp#534) | | Android 17 | [init.zygote64.rc:5](https://android.googlesource.com/platform/system/core/+/android17-release/rootdir/init.zygote64.rc#5) | [ProcessList.java:1869–1872](https://android.googlesource.com/platform/frameworks/base/+/android17-release/services/core/java/com/android/server/am/ProcessList.java#1869) | [Zygote.cpp:554–575](https://android.googlesource.com/platform/frameworks/base/+/android17-release/core/jni/com_android_internal_os_Zygote.cpp#554) | The reviewed Android 11+ SetGids code clears groups for a child zygote, such as app zygote, even with null gids. The service therefore keeps useAppZygote=false. Vendor changes may differ from this AOSP path. LSPosed owns the group warning, which is not proof of tracing or injection. The helper it queries and this I/O service are separate plain isolated processes, so the I/O precondition stays local. Having readproc only satisfies this group check; it cannot make failed I/O checks clean. ## I/O workers and cleanup Only the isolated service becomes non-dumpable. Its JNI worker forks a coordinator that becomes a child subreaper. It creates two single-threaded controls: an untraced non-dumpable process and a dumpable process seized by the coordinator. The coordinator itself is dumpable so crash_dump can read its cmdline as tracer. The real init and zygote are different-UID targets; the probe does not acquire a ptrace attachment to them on stock Android. Each run execs the system crash_dump, which forks internally. The coordinator reaps the outer process, drains its exec-error pipe, reads its own /proc/self/io, reaps the adopted inner process and reads its own /proc/self/io again. ACK's wait_task_zombie adds the child's I/O accounting to the reaper. One snapshot read is also included in the delta, so the inner read count is delta minus one. The two snapshots and the wait between them stay in ptrace_io/crash_run.c. Neither snapshot retries read(), because another read would change the count. Two calibration runs target the service's threads. Their exact thread IDs and untraced state are checked before the first run and after each run. Both read counts must match. A changed set or more than 128 service threads rejects the calibration; no thread is silently omitted. Both rounds of each single-thread control finish before init, then both init rounds finish before zygote. A later collection failure therefore preserves an already completed init result. On completion or failure the coordinator closes the controls' stop pipe and reaps children with bounded waits before reporting. The coordinator and controls set PR_SET_PDEATHSIG and check their parent after setting it, covering cancellation and the setup race. The app cannot send SIGKILL to children that entered the crash_dump SELinux domain. A wait timeout therefore returns an error without killing and blocking indefinitely. Unbind destroys the single-use service, which kills itself in onDestroy. ActivityManager handles its Binder death and clears the service's process cgroup, including crash_dump descendants even after setsid or reparenting. This cleanup is asynchronous. PR_SET_PDEATHSIG does not kill the whole process tree and is cleared by a SELinux domain transition. We do not rely on it or an inherited alarm to stop crash_dump. Device changes to framework/cgroup cleanup need device verification. The host wait is bounded at 180 seconds and the native report wait at 165 seconds; individual crash_dump runs have shorter deadlines. A timeout does not prove absence of tracing. ## Model Both untraced controls must agree at a positive count base, and both traced controls must equal base + 2. From the multi-thread calibration: per_thread = (calibration_reads - base) / (calibration_threads - 1) target_reads = base + per_thread * (threads - 1) + 2 * traced_threads The per-thread cost must be a positive integer. Both target rounds must agree. The domain classifier searches all possible thread counts up to 64 and accepts exactly one solution with zero to all threads traced. If the data admits a thread count above 64, it returns unknown instead of ignoring those possible solutions. For example, base=3, per_thread=7 and 59 reads fit both seven traced threads and nine untraced threads. This must not be reported as a hit or as clean. ## Version paths and reviewed source | Version | Executable directory | Arguments after executable | | --- | --- | --- | | Android 10–11 | /system/bin | target TID, pseudothread TID, dump type | | Android 12–16 | /apex/com.android.runtime/bin | same three arguments | | Android 17 / API 37 | same runtime APEX | adds the crashing process's parent PID | The ABI selects crash_dump32 or crash_dump64. Both TID arguments are the target PID and dump type is zero. API 37 receives the service PID, which is the parent of the coordinator that crash_dump sees as its crashing process. Primary sources reviewed for the mechanism: - [Android 10 crash_dump.cpp](https://android.googlesource.com/platform/system/core/+/android10-release/debuggerd/crash_dump.cpp#75), lines 75–99: get_tracer and EPERM; 210–232: fatal aborter exits with status 1. - [Android 16 crash_dump.cpp](https://android.googlesource.com/platform/system/core/+/android16-release/debuggerd/crash_dump.cpp#100), lines 100–124: tracer lookup; 571–584: opens the parent's proc directory; 597–608: inner fork and outer exit; 647–678: per-thread collection; 725–727: final pseudothread seize. The attr/current file is read relative to the coordinator's proc directory for both calibration and system targets. - [Android 17 crash_dump.cpp](https://android.googlesource.com/platform/system/core/+/android17-release/debuggerd/crash_dump.cpp#277), lines 277–305: five arguments and parsing the additional parent PID. - [Android 10 handler.cpp](https://android.googlesource.com/platform/system/core/+/android10-release/debuggerd/handler/debuggerd_handler.cpp) and [Android 12 handler.cpp](https://android.googlesource.com/platform/system/core/+/android12-release/debuggerd/handler/debuggerd_handler.cpp) select the system and runtime-APEX executable paths respectively. - [ACK android15-6.6 kernel/exit.c](https://android.googlesource.com/kernel/common/+/refs/heads/android15-6.6/kernel/exit.c#1202), lines 1202–1203: adds reaped-child I/O accounting to the parent; [fs/proc/base.c](https://android.googlesource.com/kernel/common/+/refs/heads/android15-6.6/fs/proc/base.c#3049), lines 3049–3088: whole-process I/O, including accumulated child I/O. - [ACK kernel/ptrace.c](https://android.googlesource.com/kernel/common/+/refs/heads/android15-6.6/kernel/ptrace.c#302), lines 302–367: credential and dumpable checks return EPERM before attachment. - [Android 10 Zygote native code](https://android.googlesource.com/platform/frameworks/base/+/android10-release/core/jni/com_android_internal_os_Zygote.cpp#432), lines 432–443: a null supplementary-group argument leaves groups unchanged. The implementation checks GID 3009 at runtime rather than assuming it survived. - [Android service documentation](https://developer.android.com/guide/topics/manifest/service-element#isolated) describes isolated processes; bindIsolatedService, Process.isIsolated and Os.getppid are present in the Android 10 public API surface. - [Android 10 app.te, lines 439–446](https://android.googlesource.com/platform/system/sepolicy/+/android10-release/public/app.te#439) and [Android 16 app.te, lines 583–590](https://android.googlesource.com/platform/system/sepolicy/+/android16-release/private/app.te#583) prohibit appdomain from sending sigkill, sigstop and other signals to crash_dump. - [Android 10 ActivityManagerService, lines 3702–3724](https://android.googlesource.com/platform/frameworks/base/+/android10-release/services/core/java/com/android/server/am/ActivityManagerService.java#3702) and [Android 16 ActivityManagerService, lines 3413–3435](https://android.googlesource.com/platform/frameworks/base/+/android16-release/services/core/java/com/android/server/am/ActivityManagerService.java#3413) clear the process cgroup after application Binder death. [Android 10 libprocessgroup, lines 254–325](https://android.googlesource.com/platform/system/core/+/android10-release/libprocessgroup/processgroup.cpp#254) enumerates cgroup members, including different process groups. [Android 16 libprocessgroup, lines 378–479](https://android.googlesource.com/platform/system/core/+/android16-release/libprocessgroup/processgroup.cpp#378) uses cgroup.kill or member enumeration. - [ACK SELinux hooks, lines 2498–2499 and 2542–2561](https://android.googlesource.com/kernel/common/+/refs/heads/android15-6.6/security/selinux/hooks.c#2498) clear parent-death signals on domain changes and may clear inherited timers. ## Limits and verification Normal short proc files yield an extra-thread cost of three reads on Android 10–11 and seven on the newer reviewed releases. These values are explanatory, never constants used by the classifier. Runtime calibration cannot prove that a modified ROM exposes identical proc paths for the local process, init and zygote. The tracer's cmdline must produce the same extra two reads as the traced control. Missing/empty cmdline, longer files, thread churn, signals or platform changes can hide or alter the signal. Checking exact thread IDs catches replacement threads, but cannot exclude short-lived threads that start and finish entirely between checks. Repeating the calibration filters inconsistent runs, not identical errors. False positives remain possible when target paths do not follow the calibrated model. For example, with base=3 and per_thread=7, four untraced threads normally produce 24 reads. If a target-specific failure removes one read in both rounds, 23 reads uniquely fit three traced threads. The local controls cannot distinguish those situations. Thread exit during target enumeration can also skip proc reads. Red is a traced fit under this model, not proof from the target's TracerPid. The forked coordinator uses syscall wrappers and local buffers, with no JNI, stdio formatting, heap allocation or locale work after fork. Payload formatting happens back in the service. JNI returns counts and completion flags; judgement belongs to domain and wording belongs to presentation. Regression cases cover old/new calibrated costs, independent targets, failed controls, changed calibration threads or a failed repeat, unstable counts, ambiguous fits, missing or malformed payloads, red row/card mapping and export severity. Before the move from Native Root to Zygisk on 2026-11-29, all 20 focused domain, payload and presentation tests passed. The Debug APK built with the pinned toolchain for arm64-v8a, armeabi-v7a, x86 and x86_64. APK signature verification passed, and the merged manifest retained the non-exported isolated service with app zygote disabled. Full-suite tests, lint and real-device verification were not run. Compilation, static checks and focused tests do not establish device accuracy. After the move, all seven repository static guards passed, including JNI and native ownership checks. A comparison against the previous files confirmed that sampling, cleanup, parsing and classification changed only in package/JNI names. The 24 focused regression cases now include incomplete Zygisk coverage and signal counts. They were not executed after the move; the Zygisk integration has not been compiled or tested on a device. After consolidating the group warning into LSPosed, Zygisk tests retain the native readproc payload contract and verify that missing or unknown groups only reduce I/O coverage, without another group row or warning. LSPosed and shared-helper cases cover empty versus unreadable groups, wrong parents/profiles, independent failures, existing danger precedence and yellow method/export status. These tests were not executed, and no build or device validation was performed for this change. Separate Python/ctypes experiments on WSL Linux confirmed EOF exit and reaping of both traced and untraced controls, parent-death cleanup after coordinator termination, and the parent check covering death before PR_SET_PDEATHSIG. Those experiments exercise kernel behavior, not the Android binary or its cgroup cleanup. AST checks confirm that every native waitpid uses WNOHANG and the I/O measurement window still contains only the two snapshots and the inner wait.