Skip to content

windows-vm: clear setgid on mount sources so launch survives the first run - #11994

Closed
jonwash wants to merge 2 commits into
omacom:quattrofrom
jonwash:fix-windows-vm-setgid-chmod
Closed

jonwash wants to merge 2 commits into
omacom:quattrofrom
jonwash:fix-windows-vm-setgid-chmod

Conversation

@jonwash

@jonwash jonwash commented Sep 15, 2026 •

Copy link
Copy Markdown

Fixes #9630
Fixes #11490
Fixes #11575
Fixes #11741
Fixes #11940
Fixes #12134
Fixes #12153
Refs #11879 (the setgid half only — the KVM: entry failed, hardware error 0x0 half of that report is unrelated and not addressed here)

The earliest and fullest diagnosis is #9630 (2026-09-01), which already identified both the coreutils behavior and the container as the source of the bit. This PR is essentially its suggested fix. Eight reports of this now, two filed today.

There are two other open PRs for this bug: #11714 (2026-09-13) and #12019. Please close whichever of the three is least useful — I'd rather this land once than land twice. What this one adds over the others is noted below.

The bug

prepare_caller_mounts hardens the two bind sources and then asserts the result is exactly 700:

chmod 0700 -- "/proc/$BASHPID/fd/$storage_fd" "/proc/$BASHPID/fd/$shared_fd" || { ... }
...
if [[ $storage_mode != 700 || $shared_mode != 700 ]]; then

chmod leaves a directory's setuid/setgid bits alone unless a numeric mode clears them with five or more octal digits, so on a setgid source the chmod is a no-op, the assert sees 2700 != 700, and the action returns 1 before Docker is ever invoked.

The bit is not incidental — the container sets it on every run. dockurr/windows's /run/samba.sh runs chmod 2777 on the /shared bind source so Samba can write to it, and that source is the host's ~/Windows. So one successful VM run is enough, and every launch after it fails. Because assert_mounts_safe gates every privileged action, this takes remove and install down with launch (as #11741 reports).

The change

Use 00700 at the three directory-hardening sites:

  • prepare_caller_mounts (:583) — the one that causes the failure.
  • prepare_user_mount_sources (:1018) — same normalization at install time, so the sources don't start out dirty.
  • write_credentials (:1061) — ~/.config/windows holds the plaintext RDP password; a stray setgid bit there should not survive the hardening step either.

The third site is the one neither #11714 nor #12019 covers.

One call, not two. #9630, #11714 and #12019 all pair a numeric chmod with a symbolic u-s,g-s. A single five-digit 00700 is one chmod(2) per path rather than two, so there is no window in which the source is mode-normalized but still setgid — which matters here, because this runs as root immediately before the directory is bind-mounted into a container.

The audit #9630 asks for. Going through the other "numeric chmod then compare" sites:

  • mounted_leaf_matches (:518) applies the same strict $mode == 700 test to the bind target. It shares an inode with the source, so this fix covers it — and that's also why loosening the comparison at :590 instead would be wrong: the rejection would just move to mounts_ready.
  • prepare_boundary_component (:267) uses chmod "$mode" but verifies through assert_boundary_dir, which only masks 022. Setgid there is tolerated, so it is not a failure path. I left it alone rather than widen the diff; happy to make it consistent if you'd prefer.

Regression test

Extends test/shell.d/windows-vm-mount-boundary-test.sh with the drift the container actually leaves — 2777 on the shared source, plus setuid on storage for the symmetric case — and asserts prepare_caller_mounts recovers both the sources and their production anchors to 700, that mounts_ready then accepts the result, and that uid 1001 still cannot read through the hardened anchor.

# without the fix
not ok - root failed to recover from special bits left on the pinned sources

# with it
ok - prepare_caller_mounts clears setuid/setgid the running VM leaves on its pinned sources

Credit where it's due: #11714 had the idea of covering this in the boundary suite first, and if you merge that one instead, its test is the part worth keeping.

Testing

test/shell.d/windows-vm-mount-boundary-test.sh, windows-vm-test.sh and windows-vm-compose-test.sh all pass; the boundary suite fails at the new assertion when bin/omarchy-windows-vm is reverted to the pre-fix version.

Also verified against a real VM on Omarchy 4.0.3-1: reproduced the failure (bash -x confirms shared_mode=2700 → return 1), applied the patch, and confirmed bring-up from a 2777 ~/Windows across repeated stop/start cycles, including runs where Samba re-applied 2777 in between.

Environment: Omarchy 4.0.3-1, coreutils 9.11, Docker 29.7.2 / Compose 5.5.1, btrfs /home, user not in the docker group (so the pkexec path).

On the error message

The >&2 message #9630 and #11940 ask for is included, naming both directories and their actual modes. It only helps terminal callers — #12153 makes the point I can't fix in this hunk: windows-vm.desktop is written with Terminal=false, so from the app grid this still surfaces as nothing but the generic critical notification. Genuinely addressing #9630's second ask means routing the reason into omarchy-notification-send in launch_windows, which is a bigger change than this bug fix warrants. Happy to follow up separately, or drop the message hunk if you'd rather keep this minimal.

🤖 Generated with Claude Code

jonwash and others added 2 commits September 15, 2026 14:47
…t run

`chmod` leaves a directory's setuid/setgid bits alone unless a numeric
mode clears them with five or more octal digits. `prepare_caller_mounts`
hardened the two bind sources with a four-digit `0700` and then asserted
the result was exactly `700`, so any source carrying the setgid bit
stayed `2700` and failed the assert on every subsequent launch.

This is not an edge case. The container sets the bit itself: dockurr/
windows runs `chmod 2777` on the `/shared` bind source so Samba can write
to it, and that source is the host's `~/Windows`. One successful VM run
therefore leaves the directory setgid and every later `launch` fails --
before Docker is invoked, with no diagnostic on any stream.

Use `00700` at the three directory-hardening sites, and name the
directory and its mode on the mismatch branch so the one bring-up failure
a user can act on is no longer invisible.

Fixes omacom#11940

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Reproduce the exact mode the container leaves on the pinned sources --
2777 on shared, plus setuid on storage for the symmetric case -- and
assert prepare_caller_mounts recovers both the sources and their
production anchors to 700, that the final pre-Docker guard accepts the
result, and that another local account still cannot read through the
hardened anchor.

Fails on the pre-fix helper with "root failed to recover from special
bits left on the pinned sources"; passes with it.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@chessing234

Copy link
Copy Markdown
Contributor

the setgid clear on windows-vm mounts is already in #12264 (folded from #9414). please close this as a duplicate of that.

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