GHSA-2g95-wg33-c5x2: Medium severity pip/filelock vulnerability

Published Oct 23, 2026
·
Updated

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 leaseduration. Affected versions: filelock >= 4.1.0 and <= 4.2.0 (finding ANT-2026-RKC48J5B).

Severity

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.

Scope and preconditions

- The other user can create files in the lock's directory; a root-owned 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. - The directory is on a filesystem that reuses a freed inode number at once: ext4, and overlayfs on it (thousands of create/unlink cycles returned one number). tmpfs does not reuse one, so the pair cannot repeat there; btrfs does not either. - File timestamps come from a coarse clock whose future values the other user can compute (CLOCKREALTIMECOARSE, 4 ms steps on Linux 6.1; 20,000 file creations all carried that clock's value). - At least two processes of the lock user are waiting on the lock while the other user's file is there. The other user does not choose which processes overlap or when; each attempt blocks the lock for 2.2 s (for a lease, leaseduration). - No symbolic link, hard link or FIFO takes part, so the 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.

Affected code

At the scanned commit b831496, the watch is SoftFileLock.markerunchangedfor, with its caller in trybreakstalelock. The MarkerSoftFileLock and SoftFileLease paths hand an unparsable marker to the same code. The re-check in breaklockfile compares the values the contender just read.

Introduced

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.

Mechanism

SoftFileLock.acquire creates the marker with OCREAT | OEXCL (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. trybreakstalelock reads the marker, finds no holder, and calls breaklockfile(lockfile, mtime, ino) only if markerunchangedfor(mtime, ino) reaches MALFORMEDLOCKAGETHRESHOLD (2.0 s). That function keeps self.markerseen = ((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.

1. While the lock is free, the other user creates an empty file at the lock path (inode I) and sets its mtime to T, a tick of the coarse clock about 2.2 s in the future. 2. Every waiting process of the lock user polls each 50 ms, reads an empty file and records markerseen = ((T, I), first seen). After 2 s each poll calls breaklockfile, 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 markerseen. 3. When the coarse clock reaches T, the other user unlinks its file. Inode I is free. 4. Process F of the lock user polls during tick T. Its OEXCL create succeeds, and its marker is inode I with mtime T. 5. Process S polls before F has written its record. It reads an empty file with pair (T, I), markerunchangedfor returns the 2.2 s that S spent watching the other user's file, and S calls breaklockfile(lockfile, T, I). 6. breaklockfile 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. 7. F writes its record into the unlinked inode and returns from 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 (unlinkopenmarker) 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.markerunchangedfor(mtime, ino) >= self.leaseduration: breaklockfile(...). markerseen 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 leaseduration, until F's first heartbeat (the periodic refresh a lease holder runs). With the lock user's processes using SoftFileLease(path, leaseduration=2) and holding for 1 s, the same other user produced an overlap in 17 of 30 attempts. The superseded holder's oncompromise (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.

Reproduction

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

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

LOCKDIR = "/tmp/locks" LOCKPATH = "/tmp/locks/app.lock" HOLDSLOG = "/tmp/holds.log"

def startvictims(): # a root-owned sticky directory like /tmp, and ten processes of user victim taking turns on one lock in it shutil.rmtree(LOCKDIR, ignoreerrors=True) os.mkdir(LOCKDIR) os.chmod(LOCKDIR, 0o1777) victim = [sys.executable, "/tmp/repro.d/victim.py", LOCKPATH] with open(HOLDSLOG, "w") as holdslog: return [ subprocess.Popen(victim, stdout=holdslog, user="victim", group="victim", extragroups=[]) for in range(10) ]

def holdsenteredafter(moment): holds = [] for line in open(HOLDSLOG): 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 attackuntiloverlap(phase, dateoffsets, maxattempts): victims = startvictims() attacker = [sys.executable, "/tmp/repro.d/attacker.py", LOCKPATH, str(dateoffsets)] for attempt in range(1, maxattempts + 1): run = subprocess.run(attacker, stdout=subprocess.PIPE, text=True, check=True, user="attacker", group="attacker", extragroups=[]) print(f"{phase} attempt {attempt}: {run.stdout.strip()}", flush=True) unlinkedat = float(run.stdout.split("unlinkedat=")[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 breaklockfile (see the # report), so those are left out. time.monotonic() is one clock for every process on the machine. holds = holdsenteredafter(unlinkedat + 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 = attackuntiloverlap("CONTROL", dateoffsets=3600, maxattempts=20) attack: the same file dated at that tick, i.e. with the mtime a victim's marker created in that tick gets observed = attackuntiloverlap("OBSERVED", dateoffsets=0, maxattempts=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

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

lockpath, dateoffsets = sys.argv[1], int(sys.argv[2])

CLOCKREALTIMECOARSE = 5 # <linux/time.h>; the kernel stamps new files from it, and it moves once per timer tick tickns = round(time.clockgetres(CLOCKREALTIMECOARSE) 1e9)

take the lock path the moment it is free, like any contender while True: try: fd = os.open(lockpath, os.OCREAT | os.OEXCL | os.OWRONLY, 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. parks = random.uniform(2.2, 2.25) releasetick = time.clockgettimens(CLOCKREALTIMECOARSE) + round(parks 1e9 / tickns) tickns mtimens = releasetick + dateoffsets 109 os.utime(fd, ns=(mtimens, mtimens)) inode = os.fstat(fd).stino os.close(fd)

time.sleep(parks - 0.05) while time.clockgettimens(CLOCKREALTIMECOARSE) < releasetick: pass os.unlink(lockpath) # a marker created before the next tick gets mtime == releasetick and, on ext4, this inode unlinkedat = 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} mtimens={mtimens} unlinkedintick={releasetick} unlinkedat={unlinkedat}")

repro.d/victim.py

python #!/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()} islocked={lock.islocked}", flush=True) time.sleep(0.05)

Attack sequence

mermaid 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 breaklockfile, 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: OEXCL 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: breaklockfile(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

Evidence

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 CLOCKREALTIMECOARSE 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 islocked=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.

Impact

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 leaseduration 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.

Workarounds

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 pollinterval so fewer waiters bunch inside one clock tick; this lowers the hit rate but does not close the window.

Patched version

4.2.1.

Fix: https://github.com/tox-dev/filelock/pull/843

Credits

Reported by Anthropic's OSS Scanner (automated analysis), 15 October 2026; reviewed by the maintainers.

- 2026-10-15 23:08 UTC: report received (finding ANT-2026-RKC48J5B, scanned commit b831496b0273) - 2026-10-16 00:46 UTC: draft advisory created - 2026-10-16 01:42 UTC: fix PR #843 opened

Affected Software

1 affected componentFixes available
pip/filelock>=4.1.0<=4.2.0
4.2.1

Remediation

Recommended actions to resolve this vulnerability, in priority order.

  1. Upgrade

    Upgrade pip/filelock to a version that resolves this vulnerability.

    Fixed in 4.2.1
  2. Upgrade

    Upgrade filelock to a version that resolves this vulnerability.

    Fixed in 4.2.1
  3. Configuration

    Where native FileLock works, prefer FileLock over SoftFileLock.

    filelock lock implementation = FileLock
  4. Configuration

    Raise poll_interval to reduce the number of waiters bunching inside one clock tick; this lowers the hit rate but does not close the race window.

    filelock poll_interval
  5. Compensating control

    Keep soft locks in a directory where other users cannot create files, such as a 0700 directory owned by the lock user, or place the lock directory on tmpfs, which does not reuse inode numbers immediately.

Event History

Oct 23, 2026
Advisory Published
via GitHub·10:00 PM
Data Sourced
via GitHub·10:00 PM
DescriptionSeverityWeaknessAffected Software

Frequently Asked Questions

1

Who is realistically exposed to this race condition?

The risk applies where another local user can create files in the directory that contains the lock path, including a sticky /tmp directory. Exploitation also depends on a filesystem that immediately reuses freed inode numbers, such as ext4 or overlayfs on ext4.

2

What does an attacker need to do to trigger the issue?

A local attacker must place an empty file at the lock path, give it an mtime in a future coarse-clock tick, allow lock waiters to observe it for more than two seconds, and remove it during that tick. The subsequent legitimate lock marker must receive the same inode number and mtime so a waiting process treats prior observation time as applying to the new marker.

3

What is the practical impact if exploitation succeeds?

A waiting process can remove a lock marker while another process still holds the lock. This allows two processes using the lock to enter the critical section concurrently.

4

How can I identify deployments with the relevant exposure conditions?

Review uses of SoftFileLock, MarkerSoftFileLock, and SoftFileLease whose lock paths are in directories writable by other local users. Give particular attention to shared temporary directories and hosts using ext4 or overlayfs backed by ext4.

Contact

SecAlerts Pty Ltd.
132 Wickham Terrace
Fortitude Valley,
QLD 4006, Australia
info@secalerts.co
By using SecAlerts services, you agree to our services end-user license agreement. This website is safeguarded by reCAPTCHA and governed by the Google Privacy Policy and Terms of Service. All names, logos, and brands of products are owned by their respective owners, and any usage of these names, logos, and brands for identification purposes only does not imply endorsement. If you possess any content that requires removal, please get in touch with us.
© 2026 SecAlerts Pty Ltd.
ABN: 70 645 966 203, ACN: 645 966 203