8000 fix: keep CLONE_VM and CLONE_VFORK on vfork-style clones by oonid · Pull Request #56 · oonid/pr · GitHub
[go: up one dir, main page]

Skip to content

fix: keep CLONE_VM and CLONE_VFORK on vfork-style clones - #56

Merged
oonid merged 4 commits into
mainfrom
fix/proot-keep-clone-vm
Nov 8, 2026
Merged

oonid merged 4 commits into
mainfrom
fix/proot-keep-clone-vm

Conversation

@oonid
@oonid oonid commented Nov 8, 2026
Copy link
Copy Markdown
Owner

What

Audit P7, verified on the device first.

Since T8.1 (2026-04), proot's ptrace path stripped CLONE_VM | CLONE_VFORK from every clone/clone3 without CLONE_THREAD, turning vfork-style spawns into forks to work around a vfork hang. glibc's posix_spawn reports a failed exec through memory the child shares with the parent, while the parent waits for the vfork. With the flags gone it returned 0 for a program that does not exist, and the child exited 127. Rust's Command::spawn and output() returned Ok, so cargo, build scripts and tool probes on glibc distros saw "started, exit 127" instead of "not found". musl reports through a pipe, so Alpine was unaffected.

Ubuntu 26.04 (glibc 2.43) Before After
posix_spawn("/nonexistent-prog") 0, child exits 127 ENOENT
posix_spawnp("nonexistent-prog") 0, child exits 127 ENOENT
Rust Command::new("/nonexistent-prog").spawn() Ok, exit 127 Err(NotFound)

Upstream proot and Termux's proot pass these flags through, and our vfork event handling is the same as Termux's. With the stripping removed, the hang it worked around no longer reproduces.

  • src/proot/src/syscall/enter.c: the PR_clone/PR_clone3 enter handlers that stripped the flags are removed. The SIGSYS path (tracee/seccomp.c), used only on devices whose filter blocks clone/clone3, is unchanged (audit P1 covers it).
  • libproot.so rebuilt from source with NDK r27c (a clean build; the loader is unchanged).
  • Two guest tests in the gcc suite, built with the distro's cc: posix_spawn of a missing program must be ENOENT, and vfork + exec (of a real and a missing program) must return to the parent, under timeout 20 so a hang fails rather than blocking the suite. libpr-cli.so rebuilt to embed them.
  • Docs: proot-improvement.md (PR_clone/PR_clone3), a note in the historical rust-toolchain-support.md, integration-tests.md, README and AGENTS.md (59 tests, 68 runs).

Tests

On an Android 17 device:

  • Red: the new gcc tests with the old proot on Ubuntu: posix_spawn of a missing program is ENOENT fails with rc=0.
  • Green: with the new proot, the gcc suite passes 5/5 on Ubuntu and Alpine.
  • Full suite from the app: 68/68 on Ubuntu 26.04 and on Alpine (the rust suite includes cargo build, with and without git).
  • By hand on Ubuntu: vfork + exec of a real and a missing program; posix_spawn/posix_spawnp; a Rust program spawning a missing program (NotFound), capturing a child's output and exit code, and running threads; cargo new, cargo build and cargo run; apt-get install/remove of a package with maintainer scripts. None of them hang.
  • cargo clippy -D warnings and cargo fmt --check clean for the test binary.

oonid added 4 commits November 8, 2026 10:10
Both are built with the distro's cc, so they use its libc. posix_spawn
of a missing program must return ENOENT; with proot stripping
CLONE_VM and CLONE_VFORK, glibc returned 0 and the child exited 127.
vfork + exec of a real and a missing program must return to the
parent; the test runs under timeout 20 so a vfork that never returns
fails instead of hanging the suite.
The T8.1 handler stripped CLONE_VM and CLONE_VFORK from every clone
without CLONE_THREAD, turning vfork-style spawns into forks. glibc's
posix_spawn reports a failed exec through memory the child shares
with the parent while the parent waits for the vfork, so with the
flags gone it returned 0 for a program that does not exist, and
Rust's Command::spawn returned Ok. musl reports through a pipe and
was not affected.

The vfork hang the stripping worked around no longer reproduces:
vfork + exec, posix_spawn, cargo build and run, apt-get, and the
full suite on Ubuntu and Alpine pass with the flags kept, as in
upstream and Termux proot. The SIGSYS path for devices that block
clone or clone3 is unchanged.
@oonid
oonid merged commit 4869ad8 into main Nov 8, 2026
1 check passed
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

0