shim: handle seccomp-trapped pidfd_open so bun child spawn works - #16
Open
HanSoBored wants to merge 1 commit into
Open
shim: handle seccomp-trapped pidfd_open so bun child spawn works#16HanSoBored wants to merge 1 commit into
HanSoBored wants to merge 1 commit into
Conversation
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.
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.
Fixes #15
Problem
On Android 10/11 (kernel < 5.3), the app-sandbox seccomp policy TRAPs
pidfd_openasSIGSYS. Bun calls it when spawning child processes, sobun x,bun run <script>, andBun.spawn()all crash:bun x cowsay→ exit 134bun run hi→error: script "hi" was terminated by signal SIGSYSBun.spawn()→ exit 159Root cause is two-fold:
pidfd_openasSIGSYSinstead of returningENOSYS, so Bun never falls back towaitpid.SIGSYScrash 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: aSIGSYShandler 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 installsSA_RESETHANDforSIGSYS, replacing our handler. Interposingsigaction()keeps our handler installed so the fallback actually runs.Verification
On aarch64 / Android 10 (kernel 4.9.186), Bun 1.3.14: