fix: compare getppid() against actual parent pid, not hardcoded 1#53
Open
mrsimpson wants to merge 1 commit into
Open
fix: compare getppid() against actual parent pid, not hardcoded 1#53mrsimpson wants to merge 1 commit into
mrsimpson wants to merge 1 commit into
Conversation
The check 'getppid() == 1' intends to detect parent death (where the child is reparented to init/PID 1). In containers the entrypoint process commonly runs as PID 1 itself, so a child forked from it legitimately has getppid() == 1 — causing a false positive and silent child exit. Fix: capture getpid() in the parent before fork and pass it through ChildSpawnArgs so the child compares against the actual parent pid. Fixes: sandlock running from within a containerized server process (e.g. uvicorn as PID 1) where direct Sandbox.run() calls always failed with 'read notif fd from child: pipe closed before 4 bytes read'.
3 tasks
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.
Summary
Fixes
Sandbox.run()failure in containerized server processes (e.g. uvicorn running as PID 1). The child'sconfine_childcheckedgetppid() == 1to detect parent death, but in containers the entrypoint process commonly runs as PID 1 itself — causing a false positive and silent child exit withread notif fd from child: pipe closed before 4 bytes read.Root cause
context.rsline 788:if unsafe { libc::getppid() } == 1 { fail!("parent died before confinement"); }When the server process is PID 1 (container entrypoint), any forked child legitimately has
getppid() == 1. Sandlock interprets this as "parent was reparented to init" and aborts the child.Fix
Capture the actual parent PID with
getpid()before the fork and pass it throughChildSpawnArgs. The child compares against that value instead of hardcoded1.Testing
RuntimeDefaultseccomp, Landlock ABI v7, uvicorn running as PID 1Sandbox.run()now succeeds directly from the uvicorn process without any subprocess workaroundRelated