Repository navigation
fix(exec,fd): gate persistent OS fd mutations on process_replacement_enabled to spare host fds (Fixes #4225) - #4231
Merged
caomengxuan666 merged 1 commit intoNov 27, 2026
Conversation
Member
Author
Member
Author
|
CAPTAIN-VERIFY — 证据达合入门,但 master 已前进、现冲突,待作者 rebase。 运行时复验(devin-mac,head 但队长刚合入十张 PR、master 已前进,本 PR 现 |
…enabled to spare host fds (Fixes #4225)
caomengxuan666
force-pushed
the
fix/4225-issue1838-adopted-fd-close-sigabrt
branch
from
November 27, 2026 08:39
c546ead to
9b332b4
Compare
Member
Author
|
CAPTAIN-VERIFY(rebase 校验):新 head |
This was referenced Nov 27, 2026
Merged
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 #4225: eliminates the
SIGABRT(IO Safety violation: owned file descriptor already closed) inissue1838_shell_close_of_adopted_fd_spares_host_original(the soleSIGABRTin themasterCI pin census).Root cause & GNU contract
GNU
redir.c:1017/:1120/:1190/:1239/:1267mutates kernel descriptors directly because a standalone Bash process IS the shell. When rubash runs embedded inside a host process (!crate::builtins::exec::process_replacement_enabled(), e.g.,niubashor an in-process Rust test harness usingExecutor::new()/Session), the host owns the process's original OS descriptors (#1838).Previously,
execute_exec,execute_stdio_only_exec_redirect, andclose_orphaned_process_fdinsrc/executor/trap_exec.rsarmedkernel_place_persistent/kernel_close_persistent(and invokedlibc::close) without checkingprocess_replacement_enabled(). Runningexec N>&-on an adopted hoststd::fs::Filetherefore calledlibc::close(N)on the host's owned descriptor, triggering Rust's IO SafetySIGABRTonFile::drop.Changes
src/executor/trap_exec.rs:Executor::owns_process_fd_mutations(&self) -> boolrequiringprocess_replacement_enabled() && self.owns_process_image && self.emulated_child_depth.get() == 0 && self.shell_state.subshell_depth.get() <= self.bashpid_origin_depth && self.compound_redirect_scope_depth == 0.owns_process_fd_mutations()intoexecute_execandexecute_stdio_only_exec_redirect, keeping persistentexecplacements and closes virtual inFdTablefor embedded/non-process-owning executors while preserving standalone CLI real-fd semantics.!crate::builtins::exec::process_replacement_enabled()toclose_orphaned_process_fd.tests/issue1838_executor_host_fd_ownership_regressions.rs:exec N>file), move-close (exec M>&N-),Session-levelexec N>&-, and embeddedexec >&-sparing host stdio (no new top-leveltests/issue*.rsbinary).What this PR deletes
execute_execandexecute_stdio_only_exec_redirectwith the sharedowns_process_fd_mutations()predicate.Verification
RUSTFLAGS='-D warnings' cargo check --lib --locked— pass (0 warnings)issue1838_executor_host_fd_ownership_regressions— 7/7 passed (zeroSIGABRT)issue3560_numbered_fd_close_delivery— 6/6 passedissue4044_nested_exec_stdio_close_isolation— 9/9 passedissue4131_builtin_redirect_handle_retire— 3/3 passedsession_api— 20/20 passedissue3640(9/9),issue3938(7/7),issue4181(12/12),issue1557(14/14),issue3578(14/14).RUSTFLAGS="-D warnings" cargo check --lib --locked— pass (0 warnings)check-api-ledger.py(298/298),check-marker-literals.py,check-rustfmt.py(1864/1864) — all pass.