Skip to content

shim: handle seccomp-trapped pidfd_open so bun child spawn works - #16

Open
HanSoBored wants to merge 1 commit into
Happ1ness-dev:mainfrom
HanSoBored:fix/sigsys-pidfd-fallback
Open

shim: handle seccomp-trapped pidfd_open so bun child spawn works#16
HanSoBored wants to merge 1 commit into
Happ1ness-dev:mainfrom
HanSoBored:fix/sigsys-pidfd-fallback

Conversation

@HanSoBored

Copy link
Copy Markdown

Fixes #15

Problem

On Android 10/11 (kernel < 5.3), the app-sandbox seccomp policy TRAPs pidfd_open as SIGSYS. Bun calls it when spawning child processes, so bun x, bun run <script>, and Bun.spawn() all crash:

  • bun x cowsay → exit 134
  • bun run hierror: script "hi" was terminated by signal SIGSYS
  • Bun.spawn() → exit 159

Root cause is two-fold:

  1. Android seccomp TRAPs pidfd_open as SIGSYS instead of returning ENOSYS, so Bun never falls back to waitpid.
  2. Bun installs its own SIGSYS crash handler (SA_RESETHAND) at startup, which turns the trap into an abort before the shim can do anything about it.

Fix

In shim.c:

  • handle_sigsys: a SIGSYS handler that reports seccomp-trapped syscalls (pidfd_open) as -ENOSYS, the standard "kernel does not provide this syscall" answer, so well-behaved callers fall back to older syscalls. Same technique as opencode-termux's libseccomp-shim.c.
  • sigaction() interposition: Bun's own crash reporter installs SA_RESETHAND for SIGSYS, replacing our handler. Interposing sigaction() keeps our handler installed so the fallback actually runs.

Verification

On aarch64 / Android 10 (kernel 4.9.186), Bun 1.3.14:

bun --version          → 1.3.14
bun run hi             → from-script        (was: SIGSYS crash)
bun x cowsay ...       → works              (was: exit 134)
bun --bun x cowsay ... → works
bun install            → works
bun build --compile    → binary runs
Bun.spawn / os.cpus()  → works
tests/run-tests.sh     → 9/9 PASS

Android's app-sandbox seccomp policy TRAPs pidfd_open (missing from the
whitelist on older kernels) as SIGSYS. Bun installs its own SIGSYS crash
handler (SA_RESETHAND) that turns the trap into an abort, so bun x, bun
run, and Bun.spawn all crashed with exit 134.

Install a SIGSYS handler in the shim that reports trapped syscalls as
ENOSYS so Bun falls back to waitpid, and interpose sigaction() so Bun's
own crash reporter cannot override it.
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.

bun x / bun run / Bun.spawn crash on Android 10: pidfd_open trapped by seccomp as SIGSYS

1 participant