Skip to content

Conversation

@gaborbernat
Copy link
Member

@gaborbernat gaborbernat commented Dec 15, 2025

A race condition existed between checking if the lock file exists and opening it with O_TRUNC, allowing local attackers to create a symlink pointing to victim files. When the lock was acquired, os.open() would follow the symlink and truncate the target file, causing data loss or corruption.

The vulnerability affected both Unix and Windows platforms and cascaded through dependent libraries:

  • virtualenv: Could overwrite user configs with virtualenv metadata, leaking file contents
  • PyTorch: Could truncate CPU ISA cache causing crashes, or corrupt compiled model checkpoints preventing
    model loading (DoS for ML pipelines)

Unix/Linux/macOS fix:

  • Add O_NOFOLLOW flag to os.open() call in UnixFileLock._acquire()
  • System returns ELOOP error if lock path is a symlink, preventing the attack

Windows fix:

  • Use GetFileAttributesW API via ctypes to detect reparse points (symlinks/junctions)
  • Refuse to open lock file if FILE_ATTRIBUTE_REPARSE_POINT flag is set
  • Raises OSError before attempting to open, closing the race window

This addresses CWE-362 (Race Condition), CWE-367 (TOCTOU), and CWE-59 (Link Following).

Reported-by: @tsigouris007

@gaborbernat gaborbernat changed the title Fix TOCTOU symlink vulnerability in lock file creation CVE-2025-68146: Fix TOCTOU symlink vulnerability in lock file creation Dec 15, 2025
A race condition existed between checking if the lock file exists and opening it with O_TRUNC, allowing
local attackers to create a symlink pointing to victim files. When the lock was acquired, os.open() would
follow the symlink and truncate the target file, causing data loss or corruption.

The vulnerability affected both Unix and Windows platforms and cascaded through dependent libraries:
- virtualenv: Could overwrite user configs with virtualenv metadata, leaking file contents
- PyTorch: Could truncate CPU ISA cache causing crashes, or corrupt compiled model checkpoints preventing
  model loading (DoS for ML pipelines)

Unix/Linux/macOS fix:
- Add O_NOFOLLOW flag to os.open() call in UnixFileLock._acquire()
- System returns ELOOP error if lock path is a symlink, preventing the attack

Windows fix:
- Use GetFileAttributesW API via ctypes to detect reparse points (symlinks/junctions)
- Refuse to open lock file if FILE_ATTRIBUTE_REPARSE_POINT flag is set
- Raises OSError before attempting to open, closing the race window

This addresses CWE-362 (Race Condition), CWE-367 (TOCTOU), and CWE-59 (Link Following).

Reported-by: @tsigouris007
Signed-off-by: Bernát Gábor <bgabor8@bloomberg.net>
@gaborbernat gaborbernat merged commit 4724d7f into tox-dev:main Dec 15, 2025
30 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant