Skip to content

Fix process spawning with closed standard descriptors - #53

Merged
guillerodriguez merged 2 commits into
masterfrom
fix/process-exec-closed-stdio
Aug 5, 2026
Merged

Fix process spawning with closed standard descriptors#53
guillerodriguez merged 2 commits into
masterfrom
fix/process-exec-closed-stdio

Conversation

@guillerodriguez

Copy link
Copy Markdown
Contributor

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.

@guillerodriguez
guillerodriguez requested a review from phvega August 4, 2026 12:30
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
guillerodriguez force-pushed the fix/process-exec-closed-stdio branch from bdfb9f4 to 78c4f8a Compare August 4, 2026 12:40
@guillerodriguez
guillerodriguez merged commit 524ed8f into master Aug 5, 2026
5 checks passed
@guillerodriguez
guillerodriguez deleted the fix/process-exec-closed-stdio branch August 5, 2026 06:56
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.

2 participants