diff --git a/bin/omarchy-windows-vm b/bin/omarchy-windows-vm index 6c8204da905a..2b4d182d3c3a 100755 --- a/bin/omarchy-windows-vm +++ b/bin/omarchy-windows-vm @@ -580,7 +580,11 @@ prepare_caller_mounts() { # Privacy is an explicit preflight step for both already-pinned sources, not # a side effect halfway through the two-mount transaction. Old umask-022 # installs are hardened together before either Docker-facing anchor changes. - chmod 0700 -- "/proc/$BASHPID/fd/$storage_fd" "/proc/$BASHPID/fd/$shared_fd" || { + # GNU chmod keeps a directory's setuid/setgid bits across a four-digit numeric + # mode, so a stray 2700 on ~/Windows would survive 0700 and fail the check + # below; the five-digit form clears every special bit as well. + chmod 00700 -- "/proc/$BASHPID/fd/$storage_fd" "/proc/$BASHPID/fd/$shared_fd" || { + echo "omarchy-windows-vm: could not make the storage and shared directories private" >&2 exec {storage_fd}<&- exec {shared_fd}<&- return 1 @@ -588,6 +592,7 @@ prepare_caller_mounts() { 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 + echo "omarchy-windows-vm: storage and shared directories must be mode 0700 (got ${storage_mode:-unknown} and ${shared_mode:-unknown})" >&2 exec {storage_fd}<&- exec {shared_fd}<&- return 1 diff --git a/test/shell.d/windows-vm-mount-boundary-test.sh b/test/shell.d/windows-vm-mount-boundary-test.sh index 197590444919..a76f4a7febe3 100644 --- a/test/shell.d/windows-vm-mount-boundary-test.sh +++ b/test/shell.d/windows-vm-mount-boundary-test.sh @@ -123,6 +123,16 @@ if setpriv --reuid=1001 --regid=1001 --clear-groups cat "$EXPECTED_SHARED/shared fi pass "cross-filesystem symlink sources bind by identity and migrated 0700 leaves deny another account" +# A caller can leave setgid or other special bits on ~/Windows (mode 2700). +# Numeric chmod as root keeps those bits on directories, so hardening must +# still land on exactly 0700 instead of failing the launch without a message. +chmod 2700 /home/shared-target +chmod 4700 /home/storage-target +with_vm_lock prepare_caller_mounts || fail "root rejected pinned sources carrying stray special mode bits" +[[ $(command stat -Lc '%a' /home/storage-target) == 700 && + $(command stat -Lc '%a' /home/shared-target) == 700 ]] || fail "hardening left special mode bits on the pinned sources" +pass "root strips stray setuid/setgid bits while hardening the pinned sources" + # Existing production boundary components are never repaired in place when # their ownership or write permissions are unsafe. Both the preparation path # and the final pre-Docker guard must fail closed without disturbing the binds.