diff --git a/bin/omarchy-windows-vm b/bin/omarchy-windows-vm index f672ed7eee1..15c4b253ef3 100755 --- a/bin/omarchy-windows-vm +++ b/bin/omarchy-windows-vm @@ -515,7 +515,12 @@ mounted_leaf_matches() { actual=$(stat -Lc '%d:%i' "$stable" 2>/dev/null) || return 1 owner=$(stat -Lc '%u' "$stable" 2>/dev/null) || return 1 mode=$(stat -Lc '%a' "$stable" 2>/dev/null) || return 1 - [[ $actual == "$identity" && $owner == "$CALLER_UID" && $mode == 700 ]] + # dockur re-applies mode 2777 to the shared source on every start (Samba + # guest share), and btrfs does not clear the resulting setgid bit with a + # plain octal chmod (2777/2700 persist). Require only that the caller owns + # the source and retains full owner rwx, tolerating the setgid/guest bits + # the container intentionally applies while keeping identity checks strict. + [[ $actual == "$identity" && $owner == "$CALLER_UID" && $(( (8#$mode & 8#0700) == 8#0700 )) == 1 ]] } bind_mount_leaf() { @@ -580,6 +585,9 @@ 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. + # btrfs retains the setgid bit set by dockur's 2777 chmod on the shared + # source even after the octal chmod below, so accept any owner-rwx mode + # (2777/2700) here rather than demanding the exact private 0700. chmod 0700 -- "/proc/$BASHPID/fd/$storage_fd" "/proc/$BASHPID/fd/$shared_fd" || { exec {storage_fd}<&- exec {shared_fd}<&- @@ -587,7 +595,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 + if [[ $(( (8#$storage_mode & 8#0700) == 8#0700 )) != 1 || $(( (8#$shared_mode & 8#0700) == 8#0700 )) != 1 ]]; then 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 13623d81645..b99010d7964 100644 --- a/test/shell.d/windows-vm-mount-boundary-test.sh +++ b/test/shell.d/windows-vm-mount-boundary-test.sh @@ -143,6 +143,19 @@ chown root:root "$USERS_DIR" mounts_ready || fail "restored production boundaries were rejected" pass "root rejects wrong-owned and group-writable production mount boundaries without mutation" +# dockur sets an empty /shared bind to 2777 for Samba guest access on every +# start; btrfs keeps the setgid bit even after an octal chmod. The final guard +# must tolerate the tolerant owner-rwx shared mode instead of failing the VM. +# Reinstating exact 0700 must likewise stay accepted, proving the check was +# loosened only wide enough to cover the container-applied mode. +chmod 2777 /home/shared-target +mounts_ready || fail "final guard rejected a dockur-style 2777 shared source" +restored_mode=$(command stat -Lc '%a' /home/shared-target) +[[ $restored_mode == 2777 ]] || fail "shared source unexpectedly changed while testing 2777 tolerance" +chmod 0700 /home/shared-target +mounts_ready || fail "final guard rejected a hardened 0700 shared source" +pass "dockur 2777 shared mode is tolerated while exact 0700 stays accepted" + expected_space=$(command df -P -- /home/storage-target | awk 'NR==2 {print int($4/1024/1024)}') actual_space=$(available_storage_gb) [[ $actual_space == "$expected_space" ]] || fail "disk-space helper did not measure the storage target filesystem"