Repository navigation
fix(executor): carry logical_cwd in the respawn transport set - #3377
Merged
Merged
Conversation
After the parent cd'd to a real directory and forged an exported $PWD, fork-form respawn children re-derived pwd -L from the forged variable instead of the parent's logical_cwd. GNU forks inherit the_current_working_directory (common.c:589). The fix stamps __RUBASH_LOGICAL_CWD in the shared fork_context_transport_entries() used by background, coproc and both procsub paths, and the respawn child adopts it only on validated respawn (keep_shlvl) after the same_file check; explicit -c / script-file / top-level fresh shells keep deriving from $PWD as GNU does. Refs unixwin#3347 Regression pin tests/issue3347_respawn_logical_cwd_transport.rs (8 tests; fail-first 5 passed / 3 failed on the unpatched tree, 8/8 pass after; supervisor verified both rounds with the patch method). Adjacent respawn/cd/pwd families green. cargo fmt clean.
caomengxuan666
force-pushed
the
fix/issue-3347
branch
from
November 19, 2026 05:33
18e5d2d to
5af446c
Compare
caomengxuan666
marked this pull request as ready for review
November 19, 2026 05: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 #3347
What was fixed
After the parent
cd'd to a real directory and forged an exported$PWD, fork-form respawn children re-derivedpwd -Lfrom the forged variable instead of the parent'slogical_cwd.The divergent face is fork-form respawn (GNU forks; rubash re-execs a new process). GNU 5.3.20 oracle measurements:
pwd -L & wait, coproc bodies, and<(pwd -L)procsub bodies all printed the true value in GNU and the forged value in rubash. The( )/$( )/ explicit-c/ script-file faces already agreed with GNU and were left alone.The fix carries
logical_cwdin the respawn transport set: the__RUBASH_LOGICAL_CWDstamp is added to the sharedfork_context_transport_entries()(background, coproc, and both procsub paths all go through it — one change, four faces covered; the__RUBASH_CMD_FILElarge-body script-file face rides the same env map). The respawn child adopts the transported value only on validated respawn (keep_shlvl) and only after thesame_filecheck (logical_value_names_cwd, i.e. GNUset_pwd's identity check); otherwise it falls back to the existing$PWDderivation. Explicit-c/ script-file / top-level fresh shells (keep_shlvl=false, fresh exec in GNU too) keep deriving from$PWDunchanged.GNU: a fork child inherits
the_current_working_directoryas-is (builtins/common.c:589);&isexecute_cmd.c:1576 execute_in_subshell, procsub issubst.c:6362 process_substitute, coproc ismake_child.What was deleted
Nothing. No files, features, or tests were removed.
Verification (all run, per-item counts)
tests/issue3347_respawn_logical_cwd_transport.rs: 8/8 pass (Unix-only; expectations from GNU 5.3.20 measurements). Fail-first on the unpatched tree (supervisor re-ran with the patch method): 5 passed / 3 failed — the&, coproc, and procsub faces printed the forged value. (The agent's earlier 4/4 was measured on the pre-fix pin version, before a missingchmod +xin the script-file control was fixed in the pin itself.)..按物理路径解析,默认与 -L 下均偏离逻辑目录 #2796 12/12, [bug] pwd -L 照印 $PWD 变量原文,不做逻辑目录规范化 #2797 12/12, [bug] pwd -P 在 cwd 已删时不报 getcwd 错,静默印陈旧目录且 rc 0 #2798 5/5 (supervisor re-ran [bug] cd 对软链父目录的..按物理路径解析,默认与 -L 下均偏离逻辑目录 #2796 and [bug] pwd -P 在 cwd 已删时不报 getcwd 错,静默印陈旧目录且 rc 0 #2798), [bug] 子壳启动丢弃继承的逻辑 PWD,重置为物理路径 #2799 batch, respawn transport [respawn] 运输集完整性盘点:BASH_ARGV 底帧为空等 fork 状态缺口 #2058, provenance [bug] respawn 来源链可伪造:__RUBASH_SHELL_PID 冒充 $$ 并开门放行伪造位置参数 #2136, procsub positional 回归:bats 在 rubash 下零测试执行(文件名空白 + gather trace 文件消失),窗口 (46452a9e, e9802c0c](生态审计 DIV-D) #2032, fork transport env budget [bug] Background spawn E2BIG at ~3100+ functions: __RUBASH_FORK_FN_SPANS env stamp exceeds MAX_ARG_STRLEN #2423, async forgery [bug] __RUBASH_ASYNC_CHILD 环境伪造让子进程天生忽略 SIGINT/SIGQUIT(Ctrl+C 打不死) #2134 4/4, respawn history rubash 自带交互循环下 nvm ls 出现 event-not-found 与 line 13 语法噪声(niu 宿主无此面) #2072, lineno span [bug] LINENO intra-body fidelity in respawned function bodies needs per-function source-span transport #2202, transport stripping __RUBASH_TOP_LEVEL_NAME and __RUBASH_GETOPTS_OPTIND missing from init strip/transport lists — ambient state survives executor boundaries #2586, deleted-cwd 已删 cwd 下进程内路径串解析同族残差:comsub 内 cat、cd ..、壳侧输入重定向、模拟 cp 操作数面 #3268 — 70/70 + 55/55 green across the two batches.issue2259_interactive_marker_leak_regressionshas 1 failure (ambient_frame_stamps_do_not_reach_script_children), reproduced identically on the unpatched tree via the patch method — a pre-existing__RUBASH_CURRENT_LINEimport-adjudication issue, unrelated to this change.cargo build -j 2clean,cargo fmt --checkclean.src/lexer/continuation.rsuntouched.Owed
__RUBASH_CMD_FILEoversized-body (>131072 bytes) respawn script-file face: same env map and consumer as the small-body-cface, covered by mechanism but with no dedicated pin (needs a 131 KB real command; low value). Can be added if the captain asks.execute_direct_shell_script, e.g. the$THIS_SHface under virtual stdin) go throughchild_shell_environment(), whose PWD is overwritten with the physical cwd — a residual in the other direction from GNU's fork+reinit model, out of this issue's respawn-transport scope; whether to file is the captain's call.