Repository navigation
π fix(unix): refuse another account's lock file - #968
Merged
gaborbernat merged 3 commits intoNov 17, 2026
Merged
Conversation
Under a sticky parent such as /tmp the owner of a lock file can unlink it while another account holds its flock. The next contender then creates and locks a new inode at the path, so two processes hold the exclusive lock. Refuse, with PermissionError, a lock file owned by neither this account nor the directory's owner, as the soft locks already do for their directories. The shared helper becomes foreign_owner, since it now judges files too.
gaborbernat
enabled auto-merge (squash)
November 17, 2026 18:02
gaborbernat
added a commit
to tox-dev/github-workflows
that referenced
this pull request
Nov 17, 2026
Adding or removing a label on a merged pull request turned its π Changelog check red, even when the pull request carried a fragment ([run on tox-dev/filelock#968](https://github.com/tox-dev/filelock/actions/runs/44169907520), labeled `security` after it merged). Once this is released and callers bump the pin, those post-merge label changes pass instead of leaving a failed check on the pull request. The news check counts fragments between the pull request head and its merge base with the base branch. After a merge the head is already on the base branch, so that count is zero. The step that already skips labels set at opening now also skips any label change on a pull request that is not open, which covers merged and closed-unmerged ones alike. A closed pull request gets the full check again from its `reopened` run, so callers must keep `reopened` in their trigger types, as the docs now say.
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
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.
On Unix,
UnixFileLock._finalize_locked_fdrecorded a hold on whatever regular file sat at the lock path, checking only that the file still had a link. Under a sticky directory such as/tmp, a file another account created stays that account's to remove. If it removed the file during a hold, the next process created a new file at the path and locked that, so two processes held the same exclusive lock. π The lock now raisesPermissionErrorfor such a file. This addresses draft advisory GHSA-386w-3w6q-9c53.The lock trusted a file another account could remove
_open_lock_filefalls back to opening an existing file when its exclusive create fails, including theEACCESLinux returns for another account's file in a sticky directory (fs.protected_regular), a path #317 added. The sticky bit stops other accounts from removing a file but not its owner (unlink(2)), andflockstays with the unlinked inode, so a laterO_CREAT | O_EXCLat the same path yields a second, unrelated lock._finalize_locked_fdnow compares the owner of the opened file with the caller's account and the parent directory's owner while it holds theflock, and raises before the hold is recorded; its caller then closes the descriptor, which drops theflock. The rule is the oneStrictSoftFileLockandSoftReadWriteLockapply to their coordination directories (#839), so the helper they share becomesforeign_ownerand judges files as well as directories.sequenceDiagram participant O as Other account participant P as lock path in /tmp participant A as Process A participant B as Process B O->>P: create the file first A->>+P: open existing file, flock rect rgb(255, 214, 214) P-->>A: before: hold recorded O->>P: unlink its own file B->>P: create a new file, flock P-->>B: hold recorded while A still holds end rect rgb(216, 243, 220) P-->>-A: now: PermissionError, no hold endBehavior changes
acquire()raisesPermissionError(EACCES) naming the owning uid, without waiting for the timeout, and takes no hold. This narrows [BugFix] fix permission denied error when lock file is placed in/tmpΒ #317: accounts that share one lock file in/tmpneed the directory's owner, usuallyroot, to create it, or a directory of their own.statof the parent directory per acquisition.flock-less fallback: unchanged.Reported by oss-security-shopify: GHSA-386w-3w6q-9c53.