Fix process spawning with closed standard descriptors - #53
Merged
Conversation
The pipes that implement a child's stdio are created with pipe(), which allocates the lowest free descriptor. If a standard descriptor is closed at that moment, a pipe endpoint would land on fd 0, 1 or 2, and the child's stdio setup would then close that fd or wire a standard descriptor to the wrong pipe. Fix by relocating any endpoint that pipe() places on a standard descriptor: duplicate it above 2 with F_DUPFD and close the original. Fixes #52 (BZ#126636) Signed-off-by: Guillermo Rodríguez <grodriguez@ingelabs.com>
Report a failed dup2() through the exec-failure pipe instead of executing the target with missing or misdirected standard streams. This is hardening: with pipe endpoints kept above the standard descriptors and with signals blocked during the child's setup, dup2() should not fail in practice. If it ever does, make sure the failure is reported. Signed-off-by: Guillermo Rodríguez <grodriguez@ingelabs.com>
guillerodriguez
force-pushed
the
fix/process-exec-closed-stdio
branch
from
August 4, 2026 12:40
bdfb9f4 to
78c4f8a
Compare
phvega
approved these changes
Aug 5, 2026
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.
If a standard descriptor is closed when a process is spawned, pipe() places a pipe endpoint on fd 0, 1 or 2, and the child's stdio setup then closes that fd or wires a standard descriptor to the wrong pipe.