omarchy icon indicating copy to clipboard operation
omarchy copied to clipboard

omarchy windows vm launch fails ("Failed to start Windows VM!"): numeric chmod 0700 cannot clear the setgid bit on ~/Windows

Open zakkoo opened this issue 3 months ago • 4 comments

Summary

omarchy windows vm launch (and the "Windows" desktop launcher) fails with "❌ Failed to start Windows VM!" even when the Windows container is running and healthy. The failure is actually in the mount-safety check, not in starting the VM, so the message is misleading.

Root cause: in bin/omarchy-windows-vm, prepare_caller_mounts() normalizes the bind-mount source directories with a numeric chmod 0700, then asserts each is exactly mode 700. GNU chmod with a numeric mode does not clear the setgid bit on a directory (only a symbolic g-s does). After a VM session the shared folder ~/Windows carries the setgid bit (mode 2700), so stat -c %a returns 2700, the [[ $shared_mode != 700 ]] guard trips, prepare_caller_mounts returns 1, assert_mounts_safe fails, and __priv_up_wait returns 1 — surfaced by launch_windows as "Failed to start Windows VM!".

Steps to reproduce

  1. omarchy windows vm install, complete the Windows install, log in, use the VM, then shut Windows down.
  2. Run omarchy windows vm launch (or click the "Windows" app) again.
  3. → "❌ Failed to start Windows VM!", even though the container starts fine and RDP is reachable.

After a session, ~/Windows is mode 2700 (setgid). The bit is applied during the VM run — the dockur/windows container provisioning the /shared Samba share, which is bind-mounted from ~/Windows.

Root-cause detail

prepare_caller_mounts() in bin/omarchy-windows-vm:

chmod 0700 -- "/proc/$BASHPID/fd/$storage_fd" "/proc/$BASHPID/fd/$shared_fd" || {
  exec {storage_fd}<&-
  exec {shared_fd}<&-
  return 1
}
storage_mode=$(stat -Lc '%a' "/proc/$BASHPID/fd/$storage_fd" 2>/dev/null) || storage_mode=""
shared_mode=$(stat -Lc '%a' "/proc/$BASHPID/fd/$shared_fd" 2>/dev/null) || shared_mode=""
if [[ $storage_mode != 700 || $shared_mode != 700 ]]; then
  exec {storage_fd}<&-
  exec {shared_fd}<&-
  return 1
fi

The chmod 0700 is meant to normalize the mode, but on a directory GNU coreutils preserves the setuid/setgid bits for numeric modes, so a 2700 source stays 2700 and the equality check fails.

Minimal, self-contained repro (GNU coreutils 9.11):

$ d=$(mktemp -d); chmod 2700 "$d"; stat -c %a "$d"   # 2700
$ chmod 0700 "$d"; stat -c %a "$d"                    # 2700   <-- setgid NOT cleared
$ chmod g-s "$d"; stat -c %a "$d"                     # 700    <-- symbolic clears it

Trace of the failing privileged action (__priv up_wait, run under bash -x):

+ chmod 0700 -- /proc/.../fd/11 /proc/.../fd/12
+ storage_mode=700
+ shared_mode=2700
+ [[ 2700 != 700 ]]
+ return 1

Suggested fix

Explicitly clear the special bits with a symbolic mode alongside the numeric chmod, e.g.:

chmod 0700 -- "$a" "$b" && chmod ug-s -- "$a" "$b" || { …; return 1; }

Actually clearing the bit is preferable to loosening the check, so the bind source is genuinely 700. The same "numeric chmod then compare == 700" pattern appears in the other anchor/source validation paths too, so it is worth auditing all of them (mounted_leaf_matches, prepare_boundary_component, etc.).

Separately: consider making the user-facing message distinguish a mount-safety rejection from a genuine start failure — "Failed to start Windows VM!" is confusing when the VM is actually running.

Workaround

chmod g-s ~/Windows   # before launching

System

  • Omarchy: 4.0.2-1
  • Kernel: 7.1.9-arch1-2 (Arch Linux)
  • CPU: Intel Core i7-11850H
  • GPU: Intel UHD Graphics (TigerLake-H) + NVIDIA RTX A2000 Mobile
  • RAM: 62 GB
  • Docker: 29.7.2 · Compose: 5.5.0
  • coreutils: 9.11
  • Image: dockurr/windows@sha256:0cff9eb0e7aee9953e55bc682852ca4fdca233145a58ae1ec94f0b0c01a2ed30

zakkoo avatar Sep 01 '26 15:09 zakkoo

Confirming this on Omarchy 4.0.2-1 (Arch, kernel 7.1.9). I hit it independently and traced it to exactly the code and the coreutils behaviour described here, so nothing to add on the root cause.

Two things I ran into that I don't see in this issue or in the related ones (#10256, #10149, #10399), and that widen the blast radius a little:

1. remove fails through the same check, not just launch.

__priv_remove also begins with assert_mounts_safe, so once ~/Windows carries the setgid bit the documented teardown path is broken too — with the same silent return 1 and, via remove_windows, no output at all:

$ pkexec /usr/bin/omarchy-windows-vm __priv remove
$ echo $?
1
$ chmod g-s ~/Windows        # only change
$ pkexec /usr/bin/omarchy-windows-vm __priv remove
Untagged: dockurr/windows:latest
Deleted: sha256:0cff9eb0e7aee9953e55bc682852ca4fdca233145a58ae1ec94f0b0c01a2ed30
$ echo $?
0

So a user who hits the launch bug and decides to remove the VM instead finds that removal fails too, also without an error message.

2. Two more directory chmod 0700 sites with the same defect.

Besides line 583, the same numeric-mode-on-a-directory pattern appears at:

  • line 1018, prepare_user_mount_sources() — chmod 0700 -- "$storage" "$shared". This one is part of the same failure chain: it is the user-side hardening whose result line 590 later asserts, so it cannot clear the bit it is there to clear either.
  • line 1061, write_credentials() — chmod 0700 "$dir".

Line 267 (chmod "$mode" -- "$path" in prepare_boundary_component()) shares the flaw but is harmless today, since assert_boundary_dir() only tests ! ((8#$mode & 022)) rather than exact equality.

Trace, for what it's worth — pkexec /usr/bin/bash -x /usr/bin/omarchy-windows-vm __priv up_wait ends precisely at the assertion:

+ chmod 0700 -- /proc/13259/fd/11 /proc/13259/fd/12
+ storage_mode=700
+ shared_mode=2700
+ [[ 700 != 700 ]]
+ [[ 2700 != 700 ]]
+ return 1
+ return 1
+ return 1

Seconding the request in #10256 that this branch print something to stderr. As it stands there is no way to distinguish it from a declined polkit authorization without tracing the privileged half.

0bsidian-bit avatar Sep 08 '26 18:09 0bsidian-bit

Confirming on Omarchy 4.0.3-1 (upgraded from pre-Quattro, which had left ~/Windows at mode 2700 from the old installer).

Symptoms: every omarchy windows vm launch/status/stop/remove re-ran the legacy-compose migration, the pkexec'd __priv write_compose exited non-zero, and no /var/lib/omarchy/windows/docker-compose.yml was ever written → "Windows VM not configured."

Root cause verified locally: chmod 0700 on the setgid directory exits 0 but leaves mode 2700 (GNU coreutils: numeric modes can't clear set-ID bits on directories), so the re-stat check shared_mode != 700 aborts the migration. Both the user-side (line 1018) and root-side (line 583) chmods are affected.

Workaround confirmed working: chmod g-s ~/Windows, then omarchy windows vm status completed the migration and the VM boots again with all data intact.

jedemenge-it avatar Sep 15 '26 14:09 jedemenge-it

Automated duplication check: this issue looks similar to #9334, which covers the same Windows VM setgid permission check. I keep that one open and close this one to keep the discussion in one place.

If you feel this is the wrong decision, please open the issue again with a note on the difference.

bjarneo avatar Sep 20 '26 18:09 bjarneo

Update: #12323 has merged into quattro. The reported numeric-chmod/setgid rejection is fixed in both mount-source hardening paths on quattro. Launch, install and removal re-harden the sources without weakening the exact mode-700 check.

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

omarchybot avatar Oct 04 '26 12:10 omarchybot