omarchy icon indicating copy to clipboard operation
omarchy copied to clipboard

Windows VM: launch fails silently when the container leaves ~/Windows setgid (chmod 0700 cannot clear it)

Open rogerfsh opened this issue 3 months ago • 5 comments

Summary

omarchy-windows-vm launch fails with ❌ Failed to start Windows VM! and no other output, on a VM that is healthy and reachable over RDP. omarchy-windows-vm status simultaneously reports RUNNING.

The cause is a mode check in prepare_caller_mounts that the script itself cannot satisfy, and the dockurr/windows container re-creates the triggering condition on every start — so each successful start breaks the next launch.

Environment

  • Omarchy 4.0.2-1
  • Kernel 7.1.9-arch1-2, GNU coreutils 9.11, Docker Compose 5.5.0
  • Intel Core Ultra 9 275HX, Intel Arrow Lake-S + NVIDIA RTX 5070 Mobile

Root cause

bin/omarchy-windows-vm:583-593, inside 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
  ...
  return 1
fi

The container sets /shared — bind-mounted from ~/Windows — to 2777 on every start. GNU chmod preserves setuid/setgid on directories when given an octal mode, so the script's own normalisation cannot clear it:

start:        2777
after 0700:   2700   <- the script's chmod, mode "retained as 2700"
after g-s:    700

stat -Lc '%a' therefore returns 2700, the comparison against the literal 700 fails, and the function returns 1. The callers at :859 and :888 propagate the bare return 1, and launch_windows prints only ❌ Failed to start Windows VM!.

Why this is unusually hard to diagnose

  • The failure is silent. Every other refusal in assert_mounts_safe prints a reason to stderr; this branch prints nothing.
  • status still says RUNNING, because __priv_status does not go through the mount checks.
  • It is self-perpetuating. Clearing the bit by hand fixes exactly one launch; the next container start restores 2777. Observed here: cleared 23:30, VM started 23:44, broken again by 23:47.
  • Through the desktop launcher the stderr is discarded (gtk-launch), so even the branches that do print a reason surface nothing to the user.
  • chmod 0700 ~/Windows — the obvious manual fix — reports mode retained as 2700 and changes nothing, which sends you looking in the wrong place.

Steps to reproduce

chmod 2777 ~/Windows        # what the container does on every start
omarchy-windows-vm launch   # ❌ Failed to start Windows VM!   (no other output)
omarchy-windows-vm status   # Windows VM Status: RUNNING

Workaround

chmod 0700 ~/Windows && chmod g-s ~/Windows   # both calls are required

Suggested fix

  1. Normalise the mode in a way that actually clears the high bits — chmod u=rwx,go=,g-s, or chmod 0700 followed by chmod g-s — or compare against the permission bits only rather than the literal string 700.
  2. Give this branch a message, matching the other refusals in assert_mounts_safe, e.g. omarchy-windows-vm: refusing VM mount source with unexpected mode $shared_mode. The silent return 1 is what turns a one-line fix into a long debugging session.

rogerfsh avatar Sep 03 '26 07:09 rogerfsh

Reviewed here and independently by Codex at xhigh reasoning; both landed on the mechanism you named, and Codex's contribution was checking the call graph rather than only the arithmetic.

Your diagnosis is right down to the line. chmod 0700 at bin/omarchy-windows-vm:583 leaves S_ISGID standing on a directory, the exact-700 comparison at :590 then rejects a source the same function was just asked to secure, and prepare_caller_mounts returns 1 with nothing on stderr. Probed on a clean 4.0.0 worker, coreutils 9.11:

start=2777  chmod 0700  -> 2700
start=2700  chmod 0700  -> 2700
start=6700  chmod 0700  -> 6700
start=1700  chmod 0700  ->  700

Numeric chmod preserves setuid and setgid on a directory but does clear the sticky bit, which is exactly why 2777 lands on 2700 and never on 700.

This is the defect already tracked as #9374, and PR #9605 is open for it. It replaces that chmod with 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 — and gives the mode branch the message you asked for. The same probe against the fixed form:

start=2777 / 2700 / 6700 / 1700 / 755  chmod u=rwx,go=,a-s  ->  700

That closes the self-perpetuating half as well: whatever mode the container leaves behind, the next preflight normalises it instead of refusing. windows-vm-test.sh, windows-vm-compose-test.sh and windows-vm-mount-boundary-test.sh are green on that branch (3 / 24 / 9 passing), and its new 2700/6700 regression case fails against the current quattro script, so the test is actually load-bearing.

One part of your report #9605 does not close. The mode branch now prints a reason and priv() hands pkexec's stderr straight back, so a terminal caller will see it — but the app-menu entry is written with Terminal=false (:1170), and launch_windows still ends at the generic ❌ Failed to start Windows VM! and an equally generic notification (:1411-1415). A desktop launch will still surface no reason, for this failure or any other. That is a separate, unfixed gap and the maintainer's call to make.

The repository cannot settle one detail either way: whether dockurr/windows sets /shared to 2777 on every start, as you observed, or only once while it is still empty, as the reporter of #9874 traced from /run/samba.sh. It does not change the fix, since the preflight now normalises the mode on every privileged action.

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

omarchybot avatar Sep 03 '26 12:09 omarchybot

Hit this on the same version (omarchy 4.0.2-1), from the remove side, which the report above doesn't cover — adding it since it's the same silent branch but with a different, misleading user-facing symptom.

After a reboot, omarchy-windows-vm remove fails with nothing but:

Removing Windows VM...
❌ Windows VM removal stopped before user-side cleanup; inspect the VM data before retrying.

launch was equally dead (no output past the generic failure). Fresh install from the omarchy menu; nobody touched ~/Windows by hand, so the setgid bit was there from the container's first start — consistent with the /shared → 2777 behavior, though I can't add data on every-start vs once, since I removed the VM once the workaround let me.

Trace (pkexec bash -x /usr/bin/omarchy-windows-vm __priv remove) shows the same mechanism, and one detail that makes the removal symptom worse than the launch one:

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

prepare_caller_mounts fails inside assert_mounts_safe before dc down ever runs, so nothing is cleaned up and the container, compose and storage all survive — retrying removal just fails identically forever. The message tells the user to "inspect the VM data", which points anywhere but at a permission bit, and since the failure is silent there is no way to self-diagnose without tracing the privileged half.

Workaround confirmed: chmod g-s ~/Windows (and chmod 0700 ~/Windows alone indeed does nothing — GNU chmod retains the mode). #9605's u=rwx,go=,a-s normalization in prepare_caller_mounts fixes the removal path as well, since it goes through the same preflight.

avara-zen avatar Sep 08 '26 20:09 avara-zen

A data point for the open question from the review above — whether the container sets /shared to 2777 on every start or only once while it is still empty.

Timeline from my machine (container lifecycle from docker events, mode checks from stat -c %a):

  1. Container running for hours; ~/Windows at 2777.
  2. chmod 00700 ~/Windows while the container was still running → 700.
  3. RDP closed → docker compose down removes the container. Mode still 700.
  4. 51 s later: second launch — succeeded, session lasted 48 s. Mode was still 700 after it (a 48-second session is too short for the bit to come back).
  5. 39 s later: third launch — succeeded, session lasted ~4.7 min.
  6. After the third session ended: ~/Windows is back to 2777.
  7. With 2777 now in place, a privileged start (__priv up) fails exactly as reported: exit 1, no output.

The three successful launches all ran with mode 700 — inferred from the fact that they succeeded, since a start with 2777 present fails deterministically (verified directly in step 7).

What this settles:

  • The bit was re-applied to the same directory across multiple container restarts, so it is definitively not a once-per-directory event.
  • The directory happened to be empty at every start here, so this can't separate "every start" from "only while empty" — but "every start, at least while empty" is confirmed.
  • New detail: the bit is applied at container start (samba init), not continuously during runtime — a mid-session chmod 00700 survived until the container restarted. Practically, that means the workaround window is predictable: clearing the bit while the VM is stopped, or even mid-session, holds until the next start, and a start that happens to re-arm it does so within the first minutes of the session.

avara-zen avatar Sep 09 '26 06:09 avara-zen

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