Dec 5, 2026·11 min read·1 visit
A local attacker with write access to a shared lock directory can exploit inode number recycling in filelock < 4.3.0 to cause the SoftReadWriteLock heartbeat mechanism to corrupt the beginning of unrelated files created by the lock holder. Upgrading to filelock 4.3.0 resolves the issue via in-band header token verification.
CVE-2026-144386 is a Time-of-Check to Time-of-Use (TOCTOU) race condition and inode reuse vulnerability in the Python filelock library prior to version 4.3.0. In multi-user environments sharing a directory on filesystems that recycle inode numbers (such as ext4), the SoftReadWriteLock heartbeat mechanism can be manipulated into overwriting the leading bytes of an unrelated victim-owned file with lock holder metadata.
The Python filelock library provides a platform-independent file locking mechanism for inter-process synchronization. In recent versions, the library introduced SoftReadWriteLock, a multi-reader, single-writer synchronization primitive that coordinates lock state through a directory structure on the local filesystem rather than relying exclusively on kernel-level flock or fcntl calls. Under this architecture, active lock holders register their presence by maintaining individual record files inside a designated holders/ subdirectory.
To detect crashed or unresponsive processes and prevent stale locks from blocking execution indefinitely, SoftReadWriteLock uses a periodic background heartbeat mechanism. Each active participant periodically refreshes its lease by writing an updated nonce and metadata block to its specific holder record file. Because lock directories may reside in shared locations such as /tmp, /var/tmp, or shared build caches, the storage engine implements safety checks to verify that the target path still refers to the original file created by the participant.
CVE-2026-144386 (also tracked as GHSA-x3f4-g3q6-f985) is a Time-of-Check to Time-of-Use (TOCTOU) race condition (CWE-367) coupled with an inode identity reuse flaw in the SoftReadWriteLock storage layer (src/filelock/_soft_rw/_storage.py). Prior to version 4.3.0, the heartbeat overwrite operation relied solely on POSIX device and inode identifiers (st_dev, st_ino) along with hard link counts (st_nlink == 1) to authenticate the target file before writing.
On filesystems that aggressively recycle freed inode numbers—most notably Linux ext4—relying solely on (st_dev, st_ino) across distinct file lifecycle events is insufficient to guarantee file identity. A local attacker with write access to the shared lock directory can unlink the victim's active holder record, wait for the victim process to allocate a new file that inherits the freed inode number, and rename that unrelated file back into the holder record path. When the victim's next heartbeat triggers, the metadata checks pass and the library overwrites the beginning of the victim's unrelated file with lock record data.
The root cause of CVE-2026-144386 lies in the false assumption that a POSIX (st_dev, st_ino) tuple uniquely and persistently identifies a specific logical file across time, even when the directory containing the file is writable by untrusted local users. While (st_dev, st_ino) is unique at any single instant on a POSIX-compliant filesystem, inode numbers are finite resources managed by the filesystem allocator and are immediately eligible for reallocation once all directory hard links and open file descriptors referencing the inode are closed.
In filelock, when a SoftReadWriteLock participant acquires a lock, it creates a holder record file at holders/<token> and caches the file's (st_dev, st_ino) tuple in self._holder_identity. Importantly, the participant does not keep an open file descriptor to this record between heartbeats. Instead, every time _refresh_nonce() executes, OsFiles.overwrite() opens the path holders/<token> fresh from the filesystem using os.O_WRONLY | _O_NOFOLLOW.
Because the file descriptor is closed between creation and subsequent heartbeat refreshes, the reference count on the underlying inode drops to zero as soon as the directory entry holders/<token> is unlinked. Once the inode's link count (st_nlink) and open file descriptor count both reach zero, the filesystem marks the inode as free. On Linux ext4, the block group inode allocator typically selects the lowest available free inode number in the target directory's block group, meaning the very next file created in or near that directory frequently receives the exact same st_ino value.
When OsFiles.overwrite() opens holders/<token> during a heartbeat, it calls os.fstat(fd) and verifies three conditions: stat.S_ISREG(opened.st_mode), (opened.st_dev, opened.st_ino) == identity, and opened.st_nlink == 1. If an attacker unlinked the original holder file, allowed the victim to create a new regular file that inherited the recycled st_ino, and then moved or renamed that new file to holders/<token>, all three fstat predicates evaluate to true. The software checks out-of-band filesystem metadata that has been aliased to a new object, resulting in an unintended write to the wrong file.
The vulnerable logic is located in src/filelock/_soft_rw/_storage.py within the OsFiles.overwrite() method, and its caller _refresh_nonce() in src/filelock/_soft_rw/_protocol.py. Prior to version 4.3.0, overwrite() opened the target file in write-only mode (os.O_WRONLY) and relied entirely on os.fstat(fd) to validate the file before calling write_all(fd, data).
# Vulnerable implementation in src/filelock/_soft_rw/_storage.py (prior to 4.3.0)
def overwrite(self, path: str, data: bytes, identity: tuple[int, int]) -> bool:
try:
# Opens path fresh on each heartbeat; original inode could have been freed
fd = self._open(path, os.O_WRONLY | _O_NOFOLLOW | getattr(os, "O_NONBLOCK", 0) | _O_BINARY)
except OSError as error:
if error.errno != ENXIO:
raise
return False
if fd is None:
return False
try:
opened = os.fstat(fd)
# FLAW: (st_dev, st_ino) can match a newly created file if the original was unlinked
if not stat.S_ISREG(opened.st_mode) or (opened.st_dev, opened.st_ino) != identity or opened.st_nlink != 1:
return False
write_all(fd, data)
finally:
os.close(fd)In commit 184931a64dd221e68f41586bcab91a2f9e59b419 (Pull Request #982), the maintainers remediated the vulnerability by introducing in-band content verification. Because each lock participant generates a unique cryptographic or random token upon initialization, any legitimate holder record file created by that participant must begin with a deterministic ASCII header containing the protocol identifier and the participant's token (<PROTOCOL>\ntoken=<token>\n).
# Patched implementation in src/filelock/_soft_rw/_protocol.py
def _holder_header(token: str) -> bytes:
return f"{_PROTOCOL}\ntoken={token}\n".encode("ascii")
def _refresh_nonce(self) -> bool:
if (identity := self._holder_identity) is None:
return False
return self._files.overwrite(
self._holder_path(self.token), self._record(), identity, _holder_header(self.token)
)The updated OsFiles.overwrite() method in src/filelock/_soft_rw/_storage.py changes the file descriptor access mode from os.O_WRONLY to os.O_RDWR. After performing the initial fstat checks on (st_dev, st_ino) and st_nlink, it reads the leading bytes of the opened file and compares them against the expected header byte sequence. If the file does not start with the exact protocol and token header, overwrite() aborts and returns False, causing the lock participant to treat its lock lease as lost without modifying the file.
# Patched implementation in src/filelock/_soft_rw/_storage.py (version 4.3.0)
def overwrite(self, path: str, data: bytes, identity: tuple[int, int], header: bytes) -> bool:
try:
# Changed from O_WRONLY to O_RDWR to permit in-band header reading
fd = self._open(path, os.O_RDWR | _O_NOFOLLOW | getattr(os, "O_NONBLOCK", 0) | _O_BINARY)
except OSError as error:
if error.errno != ENXIO:
raise
return False
if fd is None:
return False
try:
opened = os.fstat(fd)
if not stat.S_ISREG(opened.st_mode) or (opened.st_dev, opened.st_ino) != identity or opened.st_nlink != 1:
return False
# In-band verification: ensure the file content starts with this holder's unique token header
remaining = header
while remaining:
if not (chunk := os.read(fd, len(remaining))) or not remaining.startswith(chunk):
return False
remaining = remaining[len(chunk) :]
# Rewind file offset to 0 before writing the updated heartbeat record
os.lseek(fd, 0, os.SEEK_SET)
write_all(fd, data)
finally:
os.close(fd)Regarding fix completeness, verifying the in-band header effectively prevents overwriting unrelated victim files that do not start with the exact <PROTOCOL>\ntoken=<token>\n prefix. Because the file descriptor fd remains open during the os.read(), os.lseek(), and write_all() calls, an attacker cannot swap the underlying inode after the header check passes. Even if an attacker renamed the file in the directory tree during this window, all operations occur on the already-opened fd referencing the verified inode, and the check opened.st_nlink == 1 prevents hard-link aliasing prior to the open call.
Exploiting CVE-2026-144386 requires local access to the target host and write permissions within the directory housing the SoftReadWriteLock state (specifically the holders/ subdirectory) as well as a directory on the same filesystem where the victim process creates other files. Additionally, the underlying filesystem must reuse released inode numbers predictably, which is standard behavior on Linux ext4 filesystems.
The attack proceeds through the following sequence of operations:
SoftReadWriteLock, which creates holders/<token> on device D with inode number X and closes the file descriptor. The victim caches (D, X) in memory. The local attacker monitors the holders/ directory via inotify or polling to identify <token> and its inode X.holders/<token>. Because no process holds an open file descriptor to holders/<token>, the kernel reclaims inode X and returns it to the filesystem's free inode pool.D. Due to ext4 allocation heuristics, the kernel assigns the recently freed inode X to this new victim-owned file.st_nlink == 1) onto the path holders/<token>. Because the victim process created the file in Step 3, the victim user has write permissions to it._refresh_nonce(). OsFiles.overwrite() opens holders/<token>, confirms via os.fstat() that the file is a regular file with (st_dev, st_ino) == (D, X) and st_nlink == 1, and writes the ASCII lock record at offset 0.When Step 5 completes, the leading bytes of the victim's file are overwritten with the structured lock record payload (<PROTOCOL>\ntoken=<token>\npid=<pid>\nhost=<host>\nlease=<lease>\nnonce=<nonce>), corrupting whatever data previously occupied the start of the file.
The security impact of CVE-2026-144386 is confined to localized data integrity loss, reflected by its CVSS v3.1 base score of 2.5 (CVSS:3.1/AV:L/AC:H/PR:L/UI:N/S:U/C:N/I:L/A:N). The vulnerability does not grant confidentiality disclosure (C:N), as the heartbeat mechanism only writes data and never exposes file contents to the attacker. Furthermore, the attacker cannot control the exact bytes written to the file beyond triggering the write of the victim's own lock metadata record.
The attack complexity is rated High (AC:H) because successful exploitation depends on winning a race window between periodic heartbeat intervals and ensuring that the victim process allocates a new file in the exact filesystem block group required to inherit the freed inode number. Additionally, the attacker must already possess filesystem permissions sufficient to unlink files in the lock directory and rename the victim's newly created file into the holders/ directory.
> [!NOTE]
> If a directory has the POSIX sticky bit (chmod +t, such as /tmp) enabled and holders/ is owned exclusively by the victim with restrictive permissions (0700), an unprivileged attacker cannot unlink holders/<token>. The vulnerability is only reachable when the holders/ directory itself is writable by multiple accounts or lacks sticky bit enforcement.
In affected multi-user deployments—such as shared CI/CD runners, multi-tenant build servers, or HPC clusters utilizing shared scratch directories—an attacker can leverage this flaw to corrupt data files, build artifacts, or state caches generated by another user's process. As of current threat intelligence tracking, the EPSS score is 0.00162 (5.60th percentile), and the vulnerability is not listed in the CISA Known Exploited Vulnerabilities (KEV) catalog.
The primary remediation for CVE-2026-144386 is upgrading the filelock package to version 4.3.0 or later. Version 4.3.0 incorporates commit 184931a64dd221e68f41586bcab91a2f9e59b419, which enforces in-band verification of the holder header prior to executing any heartbeat overwrite.
# Upgrade filelock using pip
pip install --upgrade "filelock>=4.3.0"
# Verify the installed version
python3 -c "import filelock; print(filelock.__version__)"For environments where an immediate package upgrade is not feasible, administrators and developers should apply filesystem-level mitigations to eliminate the shared-directory attack surface:
SoftReadWriteLock to place their lock directories inside private, user-owned directories (e.g., /run/user/$UID/ or ~/.cache/app_locks/) with mode 0700 rather than world-writable shared directories like /tmp.chmod 2770) containing only trusted service accounts, and verify that the Linux kernel parameter fs.protected_hardlinks=1 is active (default on modern distributions) to prevent unprivileged users from creating hard links to files they do not own.requirements.txt, Pipfile.lock, poetry.lock, and uv.lock files across Python projects to ensure transitive dependencies (such as tox or virtualenv) are resolved against filelock >= 4.3.0.CVSS:3.1/AV:L/AC:H/PR:L/UI:N/S:U/C:N/I:L/A:N| Product | Affected Versions | Fixed Version |
|---|---|---|
filelock tox-dev | < 4.3.0 | 4.3.0 |
| Attribute | Detail |
|---|---|
| CVE / GHSA ID | CVE-2026-144386 / GHSA-x3f4-g3q6-f985 |
| Vulnerability Class | CWE-367: Time-of-check Time-of-use (TOCTOU) Race Condition |
| Affected Component | filelock SoftReadWriteLock (OsFiles.overwrite) |
| CVSS v3.1 Score | 2.5 Low (CVSS:3.1/AV:L/AC:H/PR:L/UI:N/S:U/C:N/I:L/A:N) |
| EPSS Score | 0.16% (5.60th Percentile) |
| Attack Vector | Local Shared Directory Inode Reuse |
| Primary Impact | Arbitrary File Corruption (Leading Bytes Overwrite) |
| Patched Version | filelock >= 4.3.0 |
The software checks the state of a resource before using that resource, but the state of the resource can change between the check and the use in a way that invalidates the results of the check.
CVE-2026-144353 is an arbitrary file deletion vulnerability affecting the filelock library for Python in versions prior to 4.3.0. The defect resides in the SQLite connection setup logic within the ReadWriteLock implementation. When a directory housing an SQLite lock database transitions from shared (world- or group-writable) permissions to private permissions, pre-existing SQLite side files such as rollback journals are not automatically purged. Because the vulnerable code evaluates only the current directory permissions at the time of connection, it bypasses its protective hard-link isolation mechanism and opens the database directly by name. A local attacker who plants a crafted hot rollback journal containing a master-journal pointer before the permission change can induce SQLite to unlink arbitrary files that the locking process has permissions to read and delete.
CVE-2026-144381 (GHSA-gqj6-5294-r46r) is a local permission assignment and directory validation vulnerability in the Python filelock library prior to version 4.3.0. In Unix-like environments where a shared parent directory is writable by multiple users and lacks the sticky bit, an unprivileged local user can rename an unrelated directory owned by a victim account to match the filelock coordination path (<path>.filelock). When the victim process subsequently invokes StrictSoftFileLock, the library verifies ownership of the directory via os.geteuid() and executes os.fchmod() to restrict its permissions without first validating that the directory contents conform to the lock protocol. This modifies the permission bits of the victim's directory and injects a claims subdirectory, resulting in unauthorized permission modifications and local denial of service.
CVE-2026-144382 (GHSA-7mx6-8qvh-pvc4) is an unverified ownership vulnerability (CWE-283) in the tox-dev/filelock Python library prior to version 4.3.0. On Linux systems utilizing user namespaces or idmapped mounts, unmapped user identifiers are reported by the kernel as the overflow UID (typically 65534). When lock coordination directories or files reside within a shared sticky directory such as /tmp, filelock's ownership verification fails to distinguish between unrelated host accounts that resolve to the same overflow UID. This allows a local attacker to plant a lock protocol tree that is trusted by victim processes, breaking mutual exclusion guarantees in SoftReadWriteLock, StrictSoftFileLock, and UnixFileLock.
CVE-2026-144341 (GHSA-x9cq-qqfm-8972) is a local denial-of-service vulnerability affecting the Python filelock library prior to version 4.3.0 on Microsoft Windows systems. A local user account with read access to a SQLite lock database file can place a Windows Opportunistic Lock (oplock) on the database, forcing the low-level file open routine into an uninterruptible synchronous polling loop. Because AsyncReadWriteLock executes SQLite database operations inside a background worker thread via asyncio executor dispatch, task cancellations and process shutdown routines cannot interrupt the oplock wait loop, delaying coroutine termination up to the full lock acquisition timeout.
CVE-2026-144334 is a local denial-of-service vulnerability affecting the Python filelock package prior to version 4.3.0 on Microsoft Windows systems. The host_name() function unconditionally probes the POSIX path /proc/self/ns/pid to retrieve the Linux PID namespace inode. On Windows, a path beginning with a single leading slash resolves relative to the root of the current working drive (e.g., C:\proc\self\ns\pid). Because default Windows NTFS permissions allow unprivileged local users to create directories at the drive root, a local attacker can plant this file structure to inject an arbitrary NTFS file index into the host identity string recorded by SoftFileLock and MarkerSoftFileLock. If the lock-holding process terminates abnormally and the planted path is subsequently altered, removed, or evaluated from a different working drive, contending processes observe a hostname mismatch and fail closed, permanently blocking stale lock recovery.
CVE-2026-144338 is a local denial-of-service vulnerability affecting the Python filelock library prior to version 4.3.0. On POSIX systems, when ReadWriteLock or AsyncReadWriteLock operates within a shared parent directory, an unprivileged local user can flood the directory with entries matching the .filelock-* prefix. Because connection initialization executes an unbounded synchronous directory sweep before evaluating user-supplied lock timeouts, this flooding stalls calling threads and starves the asyncio event loop.