Skip to content

Strip stray special mode bits when hardening Windows VM directories - #13154

Closed
MehrshadFb wants to merge 1 commit into
omacom:quattrofrom
MehrshadFb:windows-vm-strip-special-bits
Closed

MehrshadFb wants to merge 1 commit into
omacom:quattrofrom
MehrshadFb:windows-vm-strip-special-bits

Conversation

@MehrshadFb

@MehrshadFb MehrshadFb commented Sep 24, 2026 •

Copy link
Copy Markdown

If ~/Windows picks up a setgid bit (mode 2700), launching the Windows VM dies with a generic "Failed to start Windows VM" and nothing in the logs. The culprit is GNU chmod: on directories it preserves setuid/setgid across a four-digit numeric mode, so root's chmod 0700 leaves the directory at 2700, and the strict 700 check that follows returns 1 without saying a word.

So use the five-digit chmod 00700, which actually clears the special bits, and have both the chmod failure and the mode mismatch say what went wrong on stderr, like every other validation in this script already does.

Comes with a boundary test that puts stray setgid/setuid bits on the pinned sources and expects hardening to land on exactly 0700. It fails on the old script and passes on this one.

Fixes #13146

Fixes #13558

GNU chmod keeps a directory's setuid and setgid bits across a four-digit
numeric mode, so a ~/Windows left at 2700 survived the privileged
`chmod 0700` in prepare_caller_mounts and then failed the strict 700
check with no message. `omarchy-windows-vm launch` surfaced that only as
a generic "Failed to start Windows VM" notification.

Use the five-digit form, which clears every special bit, and report both
the chmod failure and the mode mismatch on stderr like the surrounding
validations do. Add a boundary test that sets stray setgid/setuid bits
on the pinned sources and expects hardening to land on exactly 0700.

Fixes omacom#13146
@MehrshadFb
MehrshadFb force-pushed the windows-vm-strip-special-bits branch from c8242f5 to 2e9beca Compare September 24, 2026 14:41
@llstrk

llstrk commented Sep 24, 2026

Copy link
Copy Markdown

Automated AI review

Community review: Independent automated community review, unaffiliated with the Omarchy team, intended to help prepare PRs for their review.

No issues found in the reviewed scope. Verified: chmod 00700 fixes the silent failure described in #13146, and the new stderr messages follow the script's existing omarchy-windows-vm: style without changing return codes or descriptor cleanup.

Verified: why 0700 kept the bits and 00700 clears them

The retained bit comes from GNU chmod, not the kernel, and it applies to any caller, not only root. For a directory, a numeric mode with fewer than five digits leaves existing setuid/setgid bits in place (gnulib lib/modechange.c, documented in the coreutils manual under "Directory Setuid and Setgid"). The kernel then applies exactly the mode chmod requests. Isolated runs with coreutils 9.11 on directories, by path and through /proc/$BASHPID/fd/N:

start mode   chmod 0700   chmod 00700
2700         2700         700
4700         4700         700
6700         6700         700
2750, 2755   2700         700
1700         700          700   (sticky was already cleared by 0700)

The real prepare_caller_mounts body from each revision, run against directories starting at 4700/2700 with only the runtime-tree and bind-mount helpers stubbed:

base: chmod 0700  -> 4700 / 2700 -> exact-700 check -> return 1, no message
head: chmod 00700 -> 700 / 700   -> exact-700 check -> continues to the bind step

The symbolic alternative suggested in the issue would not have been enough: u=rwx,go= also keeps both bits on directories, and a preceding g-s clears setgid but not setuid. 00700 covers both.

Verified: fresh installs are covered too. The mode can arise without touching ~/Windows. If the home directory has setgid, the kernel copies that bit to new subdirectories, so install -d -m 0700 creates both directories at 2700, and the user-side chmod 0700 in prepare_user_mount_sources keeps it. On the base revision the privileged write_compose step then fails at the same silent check during install. The head revision normalizes the mode at that step as well.

Optional: Neither new message names a directory, and chmod's own error names only /proc/<pid>/fd/N. Including $LEGACY_STORAGE / $LEGACY_SHARED next to each reported mode (for example omarchy-windows-vm: $LEGACY_SHARED must be mode 0700 (got 2700)) would tell the user which directory to fix.


Review information

Test scope: Source review of the changed function and its callers in bin/omarchy-windows-vm, the new test, GNU coreutils 9.11 chmod/install mode handling and Linux 7.2 chmod and setgid-inheritance code. Isolated runs covered directory chmod semantics, setgid inheritance under install -d, and the real prepare_caller_mounts body on base and head with mount and runtime helpers stubbed. The PR's boundary test was not run, because the isolated runtime lacks the subordinate-ID user namespace it requires; its fail-on-base, pass-on-head behavior is supported by source reading and the function-level runs above. Docker, pkexec and the desktop launch path were not exercised.

AI process: Opus 5.5 Medium coordination and synthesis, independent Opus 5.5 Xhigh and GPT 6 Sol Xhigh technical assessments, Opus 5.5 Medium editorial check.

Opt out: To stop receiving these reviews, reply to this comment saying so.

@omarchybot

Copy link
Copy Markdown
Collaborator

Reviewed at 2e9beca and verified on a disposable Omarchy worker. Nothing to fix.

Reproduced. windows-vm-mount-boundary-test.sh fails against quattro's bin/omarchy-windows-vm ("root rejected pinned sources carrying stray special mode bits"), passes on this head, and fails again with only chmod 00700 put back to 0700. That last run prints the new message, storage and shared directories must be mode 0700 (got 4700 and 2700), so the diagnostic does its job too. The same test, plus windows-vm-test.sh, windows-vm-compose-test.sh and windows-key-test.sh, passes with this branch merged into current quattro.

Suite. ./test/cli has one failure, vscode generated theme references current theme file. Plain quattro at 821ae58 fails it the same way and this PR doesn't touch that code, so it is not caused here, but the suite is not green yet.

Paths checked. Root launch, the privileged write_compose on a fresh install, removal, and a docker-group launch (when mounts_ready sees 2700, it falls back to the privileged path) all reach the exact-700 checks only after this chmod. The user-side chmod 0700 in prepare_user_mount_sources has no exact-mode check after it, so leaving it unchanged is fine.

Second opinion. Codex Medium reviewed this PR against #13750 and #13800 and found no defects in it. It agreed with my reading of the paths above, and its independence is not guaranteed. #13750 and #13800 fix the same bug in other ways; choosing between them is the maintainer's call. This PR now also links #13558, which is the same failure, triggered by the dockurr container setting setgid on an empty /shared.

Next: this waits on the maintainer and on the unrelated quattro test failure. Nothing is needed from you.

@omarchybot

Copy link
Copy Markdown
Collaborator

Closing this alternative after #12323 merged into quattro. The merged fix explicitly clears setuid/setgid in both mount-source hardening paths, keeps the exact mode-700 boundary, adds a diagnostic, and covers this launch/install failure. This alternative is no longer needed for that bug.

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 omarchybot closed this Oct 4, 2026
@omarchybot omarchybot removed the verified Omarchy Triage has verified that this issue is ready for final review label Oct 4, 2026
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

3 participants