Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions formal/LOCK_FILE_INODE_CUSTODY.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Writer/Controller lock-file custody: expected unsafe negative, R040

## Verified counterexample, not a vulnerability patch

The existing writer-admission and candidate deployment-gate use Linux
`flock` on pathnames under external artifacts' `sessions` directory.
The state initializer currently gives UID1000 ownership of this directory,
which may also be accessible to a Wine application executing as UID1000.
A writer with permission to modify the *parent directory* can remove an
existing root-owned or same-UID file directory entry. A new lock file can
then be created at the same pathname. Both processes may acquire LOCK_EX
because their open file descriptions refer to different inodes.

`tests/test_lock_inode_custody_negative.py` is a bounded **expected unsafe
witness**: an original process acquires an exclusive lock; a separate
same-UID subprocess unlinks the temp filename, creates another file and
acquires another exclusive lock; the parent verifies distinct inodes and
that the old FD is still attached to the unlinked original. It runs only
inside a newly created synthetic TemporaryDirectory. No WineBot mount,
third-party target, hardware, credential or private data is accessed.

**Important:** A PASS means the Linux filesystem exhibits this known
unsafe property. It does NOT mean WineBot is secure. This negative receipt
must be paired with an actual protected control-plane architectural gate
and independent hostile same-UID admission qualification before release.

## Corrective design / release criteria

1. Separate the trusted admission/persistent-owner authority from Wine
execution at the container/user-namespace boundary. Keep its lock
directory and control volume out of the Wine process's writable
namespace. A chmod-only patch cannot protect a file when the parent
can be renamed by the runtime principal.
2. Use a dedicated minimal control service with a protected persistent
volume, generation CAS, auditable ownership transfer and separate
API auth/human STOP priority; client processes cannot originate
unrestricted privileged mutations merely by sharing UID or a socket.
3. Add bad-volume, mount-identity, substitution, forced gate/controller
crash, concurrent rival controller, orphan recovery and guest attempt
to alter lock files to the exact-head public synthetic test matrix.
4. Admit native Windows/WinBot and WinInspect observer semantics
separately. No cross-host NFS distributed locking claim.

This source-only negative-control experiment is explicitly a **release
STOP** for arbitrary/untrusted Wine apps until the architecture changes.
1 change: 1 addition & 0 deletions scripts/ci/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ pytest \
tests/test_invariants.py \
tests/test_persistent_owner.py \
tests/test_writer_admission.py \
tests/test_lock_inode_custody_negative.py \
tests/test_early_writer_admission.py \
tests/test_startup_checkpoint_redaction.py \
tests/test_input_validation.py \
Expand Down
59 changes: 59 additions & 0 deletions tests/test_lock_inode_custody_negative.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
"""Synthetic negative control: user-writable lock paths cannot fence rivals.

A POSIX flock protects an inode, not a filename. This is an expected unsafe
counterexample only, not authorization to test/alter user or host paths.
"""
import fcntl
import os
import subprocess
import sys
import tempfile
import unittest
from pathlib import Path


class LockFileCustodyNegative(unittest.TestCase):
def test_separate_process_replaces_path_and_obtains_second_exclusive_flock(self):
if os.name != "posix":
self.skipTest("Linux/POSIX-only negative control")
with tempfile.TemporaryDirectory(prefix="winebot-synthetic-lock-") as dirname:
path = Path(dirname) / ".winebot-active-writer.lock"
old_fd = os.open(path, os.O_CREAT | os.O_RDWR, 0o600)
try:
fcntl.flock(old_fd, fcntl.LOCK_EX | fcntl.LOCK_NB)
original = os.fstat(old_fd)
# A separate same-UID process changes only its private
# temp-directory entry and opens an independent FD/inode.
child = (
"import fcntl,os,sys\n"
"p=sys.argv[1]\n"
"os.unlink(p)\n"
"fd=os.open(p,os.O_CREAT|os.O_RDWR,0o600)\n"
"try:\n"
" fcntl.flock(fd,fcntl.LOCK_EX|fcntl.LOCK_NB)\n"
" os.write(1,b'SYNTHETIC_SPLIT_FLOCK=CONFIRMED\\n')\n"
"finally:\n"
" os.close(fd)\n"
)
result = subprocess.run(
[sys.executable, "-c", child, str(path)],
capture_output=True, text=True, check=False, timeout=5,
)
self.assertEqual(result.returncode, 0)
self.assertEqual(
result.stdout, "SYNTHETIC_SPLIT_FLOCK=CONFIRMED\n",
)
self.assertEqual(result.stderr, "")
replacement = os.stat(path, follow_symlinks=False)
self.assertNotEqual(
(original.st_dev, original.st_ino),
(replacement.st_dev, replacement.st_ino),
)
# The old lock is still held on a now-unlinked inode.
self.assertEqual(os.fstat(old_fd).st_nlink, 0)
finally:
os.close(old_fd)


if __name__ == "__main__":
unittest.main()