omarchy icon indicating copy to clipboard operation
omarchy copied to clipboard

omarchy-windows-vm: setgid on ~/Windows silently blocks every privileged VM action

Open ACooperDev opened this issue 3 months ago • 7 comments

What happened

Every privileged omarchy windows vm operation (remove, launch, stop) fails when either VM source directory — ~/.windows or ~/Windows — has the setgid bit set. The failure is silent: the privileged helper returns 1 without printing a reason, so the user only sees the generic wrapper message.

$ omarchy windows vm remove
Removing Windows VM...
❌ Windows VM removal stopped before user-side cleanup; inspect the VM data before retrying.

~/Windows was mode 2700 (drwx--S---). No other diagnostic is printed, so there is nothing pointing at the mode as the cause.

Root cause

omarchy-windows-vm, prepare_caller_mounts():

chmod 0700 -- "/proc/$BASHPID/fd/$storage_fd" "/proc/$BASHPID/fd/$shared_fd" || {
  ...
}
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

GNU chmod does not clear setuid/setgid on a directory for a numeric mode of four digits or fewer — 0700 leaves the setgid bit untouched. stat -Lc '%a' then reports 2700, the != 700 comparison fails, and the function returns 1.

The hardening step can therefore never satisfy its own postcondition, and the mode check is unreachable-by-success for any setgid source directory.

This blocks every privileged path, since they all funnel through assert_mounts_safe → prepare_caller_mounts:

  • __priv_remove() — assert_mounts_safe || return 1
  • __priv_up() — assert_mounts_safe && dc up -d
  • __priv_up_wait() — assert_mounts_safe || return 1

Nothing is destroyed (the check runs before dc down and the find -delete), but the VM becomes permanently un-launchable and un-removable through the CLI.

Minimal reproduction

Independent of the VM — this is just the predicate:

d=$(mktemp -d); chmod 2700 "$d"
exec {fd}<"$d/."
chmod 0700 -- "/proc/$BASHPID/fd/$fd"
stat -Lc '%a' "/proc/$BASHPID/fd/$fd"   # prints 2700, expected 700
exec {fd}<&-

Observed on coreutils 9.11-2:

chmod form resulting mode
0700 2700 ❌
u=rwx,go= 2700 ❌
00700 700 ✅
g-s 700 ✅

Note that the symbolic form u=rwx,go= does not clear it either — GNU chmod preserves setuid/setgid on directories unless they are named explicitly.

End-to-end:

  1. chmod g+s ~/Windows (or have a pre-existing setgid ~/Windows before install — install_windows only creates the directory when it is absent: [[ -e $shared || -L $shared ]] || install -d -m 0700 -- "$shared", so an existing setgid directory is adopted as-is)
  2. omarchy windows vm install
  3. omarchy windows vm remove → fails with the generic message above
  4. omarchy windows vm launch → fails the same way

Expected

Either the hardening actually clears the special bits, or the failure explains itself. Both would be better.

Suggested fix

-  chmod 0700 -- "/proc/$BASHPID/fd/$storage_fd" "/proc/$BASHPID/fd/$shared_fd" || {
+  # Numeric modes of four digits or fewer leave setuid/setgid on a directory
+  # alone; the fifth digit is what clears them, and the mode check below
+  # requires exactly 700.
+  chmod 00700 -- "/proc/$BASHPID/fd/$storage_fd" "/proc/$BASHPID/fd/$shared_fd" || {

and give the mode check a diagnostic so it is not silent:

   if [[ $storage_mode != 700 || $shared_mode != 700 ]]; then
+    echo "omarchy-windows-vm: VM source directories must be mode 700 (storage=$storage_mode shared=$shared_mode)" >&2
     exec {storage_fd}<&-
     exec {shared_fd}<&-
     return 1
   fi

The same silent-return 1 pattern appears elsewhere in prepare_caller_mounts and in __priv_remove (the EXPECTED_STORAGE/EXPECTED_SHARED equality checks), which is why the wrapper's generic message is all the user ever gets. Worth a pass, though the setgid case is the one that actually bites.

Workaround

chmod g-s ~/Windows ~/.windows

System details

  • Omarchy 4.0.2-1
  • Kernel 7.1.9-arch1-2
  • coreutils 9.11-2
  • Docker 29.7.2
  • Hyprland 0.56.2
  • CPU: Intel Core i9-10885H
  • GPU: Intel CometLake-H GT2 [UHD Graphics] / NVIDIA TU104GLM [Quadro RTX 5000 Mobile / Max-Q]
  • Sudoless Docker: not enabled (privileged actions go through pkexec)

ACooperDev avatar Sep 01 '26 23:09 ACooperDev

Confirmed on a second machine, with three additions to the analysis:

1. Fresh installs are blocked too, not just launch/remove of an existing VM. Omarchy 4.0.0 (omarchy-dev 4.0.0.r1979.gb686ed8-1, kernel 7.1.11-arch1-1, coreutils 9.11-2, pkexec path). ~/Windows was mode 2700 from initial setup — a Windows VM had never been successfully installed, so this wasn't a dockurr container leftover. Consequences beyond the launch/remove breakage described above:

  • install dies at the same spot; the user only sees ❌ Failed to write the Windows VM configuration.
  • Because a legacy-format compose existed, status, launch, and remove all first attempt the legacy migration, which dies in this same silent mode check — status just hangs on the pkexec prompt, and remove refuses with Could not safely migrate the VM before removal. So a never-installed VM is simultaneously un-installable, un-launchable, and un-removable.

2. bash -x trace of the privileged writer, showing the fully silent exit 2 (nothing reaches the terminal except the wrapper's generic message):

+ chmod 0700 -- /proc/22137/fd/11 /proc/22137/fd/12
++ stat -Lc %a /proc/22317/fd/11
+ storage_mode=700
++ stat -Lc %a /proc/22319/fd/12
+ shared_mode=2700
+ [[ 2700 != 700 ]]
+ return 1
+ exit 2

3. Validates the chmod 00700 fix on a newer stack (coreutils 9.11, kernel 7.1.11): both the five-digit mode and direct chmod(2) clear the bit —

$ d=$(mktemp -d); chmod 2755 $d; python3 -c "import os; os.chmod('$d',0o755)"; stat -c %a $d
755
$ chmod 2755 $d && chmod 00700 $d && stat -c %a $d
700

Worth noting the kernel is not involved (direct chmod(2) works fine) — it is purely coreutils' directory setgid-preservation semantics, matching the root cause above.

Workaround confirmed end-to-end: the directory was empty, so rmdir ~/Windows && mkdir -m 0700 ~/Windows resolved it completely — install then finished successfully, image download and first boot included. chmod g-s ~/Windows ~/.windows also works if the directories aren't empty.

DanielJBurbridge avatar Sep 03 '26 11:09 DanielJBurbridge

Reviewed here and independently by Codex at xhigh reasoning; both confirmed the mechanism, and Codex's contribution was tracing which commands actually reach the check rather than re-deriving the chmod behaviour.

Your analysis is correct, and your table matches what a clean 4.0.0 worker on coreutils 9.11 produces. Two additions from re-running it: chmod 0700 also fails to clear setuid (6700 stays 6700), and it does clear the sticky bit (1700 drops to 700) — the preservation is specific to the set-ID bits, which is why 2700 is the mode everyone lands on.

@DanielJBurbridge's install observation checks out in source: __priv_write_compose runs prepare_caller_mounts || exit 2, so a setgid ~/Windows makes install die at ❌ Failed to write the Windows VM configuration. exactly as described, and the legacy-compose migration goes through the same writer. One qualification for anyone reading later: on a machine with no compose at all, launch stops earlier at "Windows VM not configured" and remove skips priv remove entirely, so the un-installable/un-launchable/un-removable trio needs the legacy compose that was present in that case. A plain stop on a modern compose is also unaffected — it is only dc down.

This duplicates #9374, and PR #9605 is open for it. It takes the symbolic route rather than 00700 — chmod u=rwx,go=,a-s — at all three sites that make these directories private: prepare_caller_mounts, prepare_user_mount_sources and write_credentials. That clears setuid, setgid and sticky together, and on a directory carrying a POSIX access ACL it also zeroes the mask, so stat -Lc '%a' reads 700 there too; 00700 would leave the ACL mask standing in the group bits and the check would still refuse. It also adds the diagnostic you asked for, naming both modes. The three windows-vm suites pass on that branch (3 / 24 / 9), and its new 2700/6700 regression case fails against the current quattro script.

The rest of your last paragraph stands and #9605 does not address it: the other return 1 sites in prepare_caller_mounts and the EXPECTED_STORAGE/EXPECTED_SHARED equality checks in __priv_remove are still silent, and the app-menu entry is Terminal=false, so a desktop launch sees only the generic notification whatever the reason. That is reported to the maintainer as a separate gap.

Waiting on the maintainer to review #9605. Nothing further needed from you.

omarchybot avatar Sep 03 '26 12:09 omarchybot

Just confirming: same problem here — dockur keeps re-setting the setgid bit on ~/Windows, so every privileged omarchy-windows-vm action fails — and an explicit chmod g-s ~/.windows ~/Windows before each launch solves it on both my machines running omarchy 4.0.2-1.

jon-nielsen avatar Sep 04 '26 08:09 jon-nielsen

Still present on omarchy 4.0.3-1 (kernel 7.2.3-arch1-3), hit via omarchy windows vm remove, same generic message and no reason printed.

Traced pkexec bash -x /usr/bin/omarchy-windows-vm __priv remove; the tail is the same postcondition failure described above:

+ chmod 0700 -- /proc/198867/fd/11 /proc/198867/fd/12
++ stat -Lc %a /proc/199097/fd/11
+ storage_mode=700
++ stat -Lc %a /proc/199101/fd/12
+ shared_mode=2700
+ [[ 700 != 700 ]]
+ [[ 2700 != 700 ]]
+ return 1

~/Windows was drwx--S--- (2700), created by the VM install itself, never touched by hand. chmod g-s ~/Windows and re-running remove completed the removal.

McNutty avatar Sep 13 '26 07:09 McNutty

Independent confirmation on the current release, with the exact postcondition trace and a workaround that survives the dockur re-chmod.

Environment: omarchy 4.0.4-1 (package updated 2026-09-16), coreutils 9.11-2, kernel 7.2.4-arch1-2, docker 29.7.2, /home on btrfs subvol=/@home, /usr/bin/omarchy-windows-vm sha256 25664986469a….

Repro: chmod 2777 ~/Windows → omarchy-windows-vm launch → ❌ Failed to start Windows VM!, nothing else printed. The failed attempt leaves ~/Windows parked at 2700.

Trace (sudo env PKEXEC_UID=1000 bash -x /usr/bin/omarchy-windows-vm __priv up_wait):

+ chmod 0700 -- /proc/<pid>/fd/11 /proc/<pid>/fd/12
++ stat -Lc %a /proc/<pid>/fd/11          # storage
+ storage_mode=700
++ stat -Lc %a /proc/<pid>/fd/12          # shared
+ shared_mode=2700
+ [[ 2700 != 700 ]]
+ return 1

Why it never recovers on its own: mounted_leaf_matches stats the bind anchor, and the anchor's mode is the mode of its source directory — so while ~/Windows is 2777/2700, even mounts_ready fails. Every subsequent launch therefore takes the privileged path (polkit prompt included) and dies at the same check.

Workaround that holds — reset the mode with the documented numeric form for clearing special bits, chmod 00700 ~/Windows ~/.windows (man 1 chmod, SETUID AND SETGID BITS: a numeric mode that must clear them needs the extra leading zero, 00755). To make it automatic, put a wrapper ahead of /usr/bin in PATH:

case "${1:-}" in launch|start) chmod 00700 "$HOME/.windows" "$HOME/Windows" ;; esac
exec /usr/bin/omarchy-windows-vm "$@"

Without something like this the failure re-arms on every container start, because dockur's /run/samba.sh sets the share to 2777 whenever the share directory is empty (on the running container: chmod 2777 "$dir" in the share setup, plus force directory mode = 02777 in /etc/samba/smb.conf). After the wrapper was added, launch/stop/launch cycles here work again — the normal flow still needs a root pkexec only for the first launch after a reboot, to re-pin the anchors.

Still present upstream: branch quattro (9c5482c5) still has chmod 0700 in prepare_caller_mounts / prepare_user_mount_sources and [[ $mode == 700 ]] in mounted_leaf_matches, so #9783 looks like the fix to land. Posted here rather than as a separate issue given the number of open duplicates on this exact failure: #9746 #10114 #10399 #10856 #10983 #11262 #11490 #11575 #11940 #12134.

karem505 avatar Sep 17 '26 16:09 karem505

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