Repository navigation
fix(executor): fork-boundary fd snapshots keep live descriptor handles - #3849
Merged
Merged
Conversation
…s (Refs #3814) GNU's subshell and command substitution are real forks (execute_cmd.c:1576 execute_in_subshell; subst.c:7143 command_substitute): the child owns copies of the parent's descriptors, so `( : ) 8<&-` closes only the child's fd 8 and the parent's stays readable. Rubash emulates the boundary with `fd_table.clone()`, which shares every `Rc<FileFd>` — an in-region close_input retires the kernel descriptor the parent's restored entry still names, and the follow-up read fails EBADF. Add FdTable::saved_table() — the whole-table form of the existing per-slot saved_entry — duplicating each kernel-backed endpoint via dup_file_endpoints (dup(2): shared open file description, region- local closed flag), and use it at every snapshot/restore fork boundary: subshell, command substitution, and the scoped-redirect / function-call / trap / exec-scoped saves that emulate the same boundary. Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Member
Author
|
g3 lane: WSL Linux-native verified. Pin stem issue3814_subshell_close_fd_isolation 5/5 pass; GNU 5.3.20 script-file comparison byte-identical (subshell/comsub/nested/file-fd/double-close); -D warnings clean; rustfmt applied. Fail-first reproduced on base a41909d (script mode: P5min rc=1 l2=[] EBADF). |
This was referenced Nov 17, 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.
Fixes #3814
Summary
execute_cmd.c:1576 execute_in_subshell;subst.c:7143 command_substitute): the child owns copies of the parent's descriptors, so( : ) 8<&-closes only the child's fd 8 — the parent's stays readable (P5min rc=0 l2=[a]).fd_table.clone(), sharing everyRc<FileFd>; an in-regionclose_inputretires the kernel descriptor the parent's restored entry still names → parentreadfails EBADF.FdTable::saved_table()— the whole-table form of the existing per-slotsaved_entry/dup_file_endpoints— and uses it at every snapshot/restore fork boundary (subshell, comsub, scoped-redirect, function-call, trap, exec-scoped saves).GNU anchors
execute_cmd.c:1576 execute_in_subshell— forked child gets its own descriptor table.subst.c:7143 command_substitute— same fork boundary for$( ).redir.csave_fd/restore_fd/undo_partial_redirects— descriptor save/restore discipline the scope snapshots mirror.Verification (WSL, GNU bash 5.3.20 script-file oracle)
( : ) 8<&-+ parentread <&8→P5min rc=0 l2=[a]identical; file-backed fd, nested subshell,$( )comsub, and double-close variants all byte-identical.tests/issue3814_subshell_close_fd_isolation.rs(5 tests, cfg(unix)).read: 0: read error: Bad file descriptor,P5min rc=1 l2=[]).Generated with Devin