From 8a8a3b94147e45fdf9540f34d3e8a8876f42e1b4 Mon Sep 17 00:00:00 2001 From: "Mark E. DeYoung" <1854350+mark-e-deyoung@users.noreply.github.com> Date: Mon, 23 Nov 2026 13:44:51 +0100 Subject: [PATCH] security(rdte): replay synthetic same-UID replacement of a locked file inode --- formal/LOCK_FILE_INODE_CUSTODY.md | 45 +++++++++++++++++ scripts/ci/test.sh | 1 + tests/test_lock_inode_custody_negative.py | 59 +++++++++++++++++++++++ 3 files changed, 105 insertions(+) create mode 100644 formal/LOCK_FILE_INODE_CUSTODY.md create mode 100644 tests/test_lock_inode_custody_negative.py diff --git a/formal/LOCK_FILE_INODE_CUSTODY.md b/formal/LOCK_FILE_INODE_CUSTODY.md new file mode 100644 index 00000000..d9d022bf --- /dev/null +++ b/formal/LOCK_FILE_INODE_CUSTODY.md @@ -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. diff --git a/scripts/ci/test.sh b/scripts/ci/test.sh index 8ac392fa..c5927631 100755 --- a/scripts/ci/test.sh +++ b/scripts/ci/test.sh @@ -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 \ diff --git a/tests/test_lock_inode_custody_negative.py b/tests/test_lock_inode_custody_negative.py new file mode 100644 index 00000000..9b331087 --- /dev/null +++ b/tests/test_lock_inode_custody_negative.py @@ -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()