Skip to content

feat: add zygote handoff for seccomp-free root execution - #1054

Open
NKU100 wants to merge 7 commits into
LSPosed:mainfrom
NKU100:feat/zygote-handoff
Open

NKU100 wants to merge 7 commits into
LSPosed:mainfrom
NKU100:feat/zygote-handoff

Conversation

@NKU100

@NKU100 NKU100 commented Dec 3, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds an opt-in, generic zygote handoff for devices where the App process still has a seccomp filter after W1/W2.

After W1 makes SELinux permissive and W2 obtains temporary root, the victim child can execute a small arm64 PIE helper. The helper attaches to zygote64, creates a child with clone(SIGCHLD), injects execve, and runs the existing root script from that zygote child. The script therefore executes without the App process's seccomp filter.

The handoff is selected only when all of the following are true:

  • The session Zygote switch is enabled. recommend_zygote only seeds the switch at startup.
  • The current native process still has a seccomp filter.
  • The packaged libzygote_exec.so helper is executable.

Otherwise, the existing W1/W2/W3 flow is unchanged. The existing Shizuku entry is also unchanged. A UserService process with Seccomp: 0 continues to skip W3 and use the direct root-script handoff without invoking zygote.

Background

This work started while investigating a PICO 4 Ultra device whose W3 completion was unreliable. The resulting handoff is device-independent and contains no PICO-specific profile, firmware, carrier, or KernelSU changes. The generic path was independently verified on a Xiaomi MIX Fold 3.

Motivation

Some devices complete W1 and W2 but cannot reliably complete W3. Shizuku avoids this problem because its UserService runs as shell without the App seccomp filter, but requiring an external Shizuku process adds a separate setup and authorization dependency.

This change provides another seccomp-free handoff using the platform zygote64 process after temporary root has been obtained. It does not require a device-specific KernelSU build or a modified zygoted.

Changes

  • Add the recommend_zygote profile field with a default of 0.
  • Add the runtime zygote_enabled value to the existing PRIV1 v2 meta section.
  • Add a main-screen Zygote switch with the same startup recommendation lifecycle as Shizuku.
  • Allow recommend_shizuku = 1 and recommend_zygote = 1 in the same profile.
  • Package an independently executable arm64 libzygote_exec.so.
  • Resolve the helper from the APK native library directory with a CLI fallback.
  • Skip W3 only when the zygote predicate is true.
  • Re-evaluate the predicate in the victim child after W2 obtains root.
  • Restore zygote registers and detach on helper failures.
  • Preserve the Shizuku UID, seccomp, authorization, and Run-button gates.
  • Add profile-wire tests, native decision tests, recommendation tests, templates, schemas, and device gate records.

No new profile-wire version is introduced. Existing profiles omit the new fields and decode them as 0.

Device verification

Device: Xiaomi MIX Fold 3, Android 16, kernel 5.15.194-android13-8-00019-gf4321180a397-ab15212794. Device serial numbers are omitted from the records.

Direct zygote handoff

  • App process: Seccomp=2, Seccomp_filters=1
  • CPU pair: main=3, consumer=4
  • Route: multicast_waiter
  • W1/W2 completed
  • W3 remained not_start
  • Zygote child executed the root script
  • Root script reported Seccomp: 0
  • KernelSU late-load completed successfully

Gate record: ZYGOTE-01

Shizuku compatibility

  • UserService: uid=2000, Seccomp=0
  • W3 was skipped by the existing no-seccomp branch
  • Zygote helper was not invoked
  • Root script reported Seccomp: 0
  • KernelSU late-load completed successfully

Gate record: ZYGOTE-02

Both final gates required three attempts because of the repository's documented W1 nondeterminism and KERNEL-PANIC-01 behavior. Attempts that exhausted prepare_kernel_page or rebooted during W1 are recorded in the gate documents. The successful runs completed without panic or reboot.

Static verification

  • make -C src native-host-tests passes
  • make -C src host-attack-dataflow-test passes
  • make -C src lsprivilege passes with NDK 29
  • make -C src zygote-exec passes with zero warnings
  • make -C src lint-tidy passes
  • tools/cmp_disasm.py returns PASS
  • ./gradlew exportKernelProfiles passes
  • ./gradlew :app:assembleDebug passes
  • ./gradlew :app:assembleRelease passes
  • Both APKs contain liblsprivilege.so and libzygote_exec.so

All seven commits were checked independently in isolated worktrees. Every commit compiled, and native host and attack dataflow tests passed at every commit.

Android unit-test baseline

The complete Android suite currently reports:

95 tests completed, 2 failed

The two remaining failures also reproduce on unmodified upstream:

  • ExporterAgreementTest
  • ProfileMigrationEquivalenceTest

The clean upstream baseline additionally fails NativeDocumentEquivalenceTest. This PR updates that golden fixture after intentionally adding the two new profile meta fields. No Zygote-specific test failure remains.

The upstream Build workflow does not currently run testDebugUnitTest, so the local results above are included as manual validation evidence.

Review notes

  • The helper is arm64-only and reports unavailable on other architectures.
  • The Zygote path is opt-in and a profile recommendation alone cannot bypass the session switch.
  • Helper availability is checked separately from the profile recommendation.
  • The helper runs only after W2 provides temporary root.
  • PICO-specific profiles, firmware assets, Sparrow carrier changes, and custom KernelSU patches are outside this PR.
  • Design and compatibility notes are in the handoff plan.

Checklist

  • Profile fields and runtime switch are implemented.
  • Existing Shizuku behavior is covered by a device gate.
  • Direct Zygote behavior is covered by the successful final-build gate and earlier candidate runs.
  • Native, lint, disassembly, debug APK, and release APK checks pass.
  • Every commit was built independently.
  • Device gate records and logs are archived.
  • Device serial numbers and credentials are absent from the branch history.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant