Skip to content

Snapshot BASHPID before /proc fd walks in windows-vm mounts - #10262

Closed
crwirth wants to merge 1 commit into
omacom:quattrofrom
crwirth:fix/10035-windows-vm-bashpid
Closed

crwirth wants to merge 1 commit into
omacom:quattrofrom
crwirth:fix/10035-windows-vm-bashpid

Conversation

@crwirth

@crwirth crwirth commented Sep 5, 2026

Copy link
Copy Markdown

Summary

omarchy-windows-vm pins mount sources through /proc/$BASHPID/fd/N. In prepare_caller_mounts, chmod ran in the parent shell (correct PID) but the following $(stat ... "/proc/$BASHPID/fd/...") expanded BASHPID inside a command-substitution subshell. That subshell has a different PID and a different descriptor table, so the 0700 privacy check could read a stale mode (e.g. 2700) and abort launch with "Failed to start Windows VM" after a successful chmod.

This snapshots self_pid=$BASHPID before every /proc/<pid>/fd access that can run under $(...) in:

  • open_mount_source
  • pinned_dir_contains
  • pinned_tree_contains
  • bind_mount_leaf
  • prepare_caller_mounts

Fixes #10035

Test plan

  • Added test/shell.d/windows-vm-bashpid-test.sh
  • Ran bash test/shell.d/windows-vm-bashpid-test.sh (all ok)
  • Asserts no bare $BASHPID inside $(...) and that each helper snapshots self_pid

Command substitutions run in a subshell where BASHPID is not the
descriptor owner. prepare_caller_mounts chmod'd via the parent PID then
stat'd via the subshell PID, so the 0700 privacy check read the wrong
descriptor table and failed closed after a correct chmod. Capture
self_pid=$BASHPID before every /proc/<pid>/fd access that can run under
$(...).

Closes #10035

Signed-off-by: fresh3nough <[email protected]>
@omarchybot

Copy link
Copy Markdown
Collaborator

Thanks for this. I tested it, and it doesn't fix the launch failure in #10035. With ~/Windows at mode 2700 or 2777, this head rejects the launch exactly the way quattro does.

Why the snapshot doesn't change anything. $BASHPID is different inside $( ), but a command substitution is a fork, and a fork inherits the parent's descriptors. /proc/<subshell>/fd/N therefore points at the same directory as /proc/<parent>/fd/N. On the worker, readlink on both paths gave the same directory. The 2700 in the issue's trace is the directory's real mode. GNU chmod keeps a directory's setgid bit when given a numeric mode of four digits or fewer, so chmod 0700 turns 2700 or 2777 into 2700. The guard at bin/omarchy-windows-vm:603 then rejects it. chmod 00700 gives 700. That is the defect behind #9334, and the earlier reply on #10035 explains the same thing.

What ran, on a disposable worker built from the Omarchy ISO (bash 5.3.15, coreutils 9.11). I pulled the chmod/stat/guard lines of prepare_caller_mounts out of each revision and ran them on fresh directories:

shared dir starts at quattro 4930677 this PR 132490e
0755 passes, 700 passes, 700
2777 rejected, left at 2700 rejected, left at 2700
2700 rejected, left at 2700 rejected, left at 2700

./test/cli and the existing windows-vm-test.sh, windows-vm-mount-boundary-test.sh and windows-vm-compose-test.sh pass on the head, and so does the new test. The new test fails on the base only because it greps for the spelling $BASHPID inside $( ). Its runtime probe stats / and accepts any octal mode, 2700 included, so it never exercises the failing case.

Second opinion. Codex Medium reviewed the same head and reached the same conclusion. Since its independence isn't guaranteed, its agreement adds less than the measurements above. It added two points that hold: the snapshots don't break anything (each function captures its own PID, and nested local self_pid declarations scope correctly), and the right test would start the shared directory at 2700 and 2777 and expect the preflight to pass.

What happens next. Nothing was pushed here, because the change has nothing to fix. This now waits on the maintainer, and my recommendation is to close it. The setgid bug has open fixes in #9605, #9783 and #10113, and the maintainer will choose among them.

@omarchybot

Copy link
Copy Markdown
Collaborator

Thank you for this, @fresh3nough. Closing because tested on a worker, the setgid launch failure happens with and without this change, so it does not fix the bug.

Closed at the maintainer's request. The review comment above has the details; it was done by Claude Opus 5.5 with Codex Medium as a second opinion, whose agreement is not independent.

@omarchybot omarchybot closed this Oct 3, 2026
@omarchybot

Copy link
Copy Markdown
Collaborator

Update: #12323 has merged into quattro. The actual setgid launch failure is now fixed. Forked command substitutions inherit the pinned descriptors, so caching BASHPID was not the missing fix; clearing directory set-ID bits is.

Scope checked by GPT-6 in Codex and Codex Medium against the discussion and landed change; review independence is not guaranteed. No tests were rerun for this cleanup.

Omabot on behalf of DHH

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Windows VM launch fails: $BASHPID bug in prepare_caller_mounts causes shared_mode check to read wrong fd

2 participants