Repository navigation
fix(executor): revoke delivered fd N on command-local N>&- / N<&- (Refs #3560) - #3858
Merged
Merged
Conversation
…awn strip (Refs #3856) 0a405d8 (#3736) added __RUBASH_FD_ to fork_respawn_transport_key, so Executor::new_inner deleted every fd-delivery stamp for any birth that is not a validated internal respawn — before init.rs could collect them into inherited_fd_handles. exec/external/comsub/pipeline children are never respawns, so all fd>=3 delivery through the env channel died on Windows (unix masks it via pin+adoption). The keys are per-spawn delivery minted fresh for THIS child and consumed+stripped at entry — not respawn residue — so they do not belong to the #3049 family. Verified: tests/issue3311_exec_child_fd_delivery 4/4 red->green; exec-own/exec-amb/plain-own fd>=3 writes reach children again.
#3560) The external fd delivery stamped every ambient fd>=3 into the child's __RUBASH_FD_* env keys (and unix pins) before the redirect walk, and the walk's close arm only skipped the entry — so `cmd 3>&-` left the ambient stamps in place and the child still saw fd 3. GNU services the close with r_close_this inside the ordered do_redirections walk (redir.c:237; close_buffered_fd at redir.c:1239) in the forked child. Route the numbered close through apply_pending_close_at — the same revocation a {var} pending close uses: env stamps removed, pins dropped, carriers retired to the dead list, walk bindings cleared, and the table step snapshots into fd_var_close_restore so undo_child_fd_var_redirects restores the parent's binding at command end (the close is child-scoped, never a parent exec N>&-). Depends on the __RUBASH_FD_* delivery-strip fix (#3856): on master the env channel is dead anyway, so this pin is only observable once delivery works. Verified: pin 5/5 green here, 4/5 red without this commit; GNU bash 5.3.20 script probes match byte-for-byte.
caomengxuan666
marked this pull request as ready for review
November 17, 2026 15:47
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 #3560
Summary
cmd N>&-/cmd N<&-(N >= 3) did not revoke fd N for the child:collect_external_fd_deliverystamps every ambient fd>=3 into__RUBASH_FD_*env keys (and unix pins) before the redirect walk, and the walk's close arm onlycontinued — the stamps survived and the child still saw the fd (echo c >&3wrote into the parent's file).GNU services the close with
r_close_thisinside the ordereddo_redirectionswalk (redir.c:237;close_buffered_fdatredir.c:1239) in the forked child — child-scoped, parent's binding untouched.Fix: route the numbered close through
apply_pending_close_at— the same revocation a{var}pending close uses — removing env stamps, pins, retiring carriers, clearing walk bindings, and snapshotting the table step intofd_var_close_restoresoundo_child_fd_var_redirectsrestores the parent binding at command end. Last-wins ordering falls out of the walk's list order (3>f 3>&-closes;3>&- 3>grebinds;4>&3after3>&-is a bad-fd redirect error).Dependency
Stacked on #3857 (the
__RUBASH_FD_*non-respawn strip fix, Refs #3856): on master the env channel is dead, so this pin is only observable once delivery works. This branch contains that commit; after #3857 merges the diff shrinks to the close fix + pin.Evidence
/usr/local/bin/bash, script-file probestarget/scratch-i3/gnu-3560*.sh):A rc=1 B rc=1 C rc=0 amb bytes: 2,exec-close rc=1, own-then-closerc=1 f=[], close-then-ownrc=0 g=[y], close-duprc=1+3: Bad file descriptor, parent survives.tests/issue3560_numbered_fd_close_delivery.rs: 5/5 green here; 4/5 red with only the product fix stashed (leak shapesA rc=0,amb bytes: 6,exec-close rc=0,in-close rc=0).tests/issue3311_exec_child_fd_delivery4/4; fd-var close stems (issue2281/2272/2280/1313) 34/34;cargo test --lib fd_15/15.Test plan
cargo build --locked --bin rubashcargo test --libfull diff +-D warnings+ unix leg (flagged for captain; env channel is shared so unix rubash children had the same leak)