Skip to content

🐛 fix(fork): preserve holds across PID namespaces - #1075

Merged
gaborbernat merged 2 commits into
tox-dev:mainfrom
gaborbernat:fix/mx-pid-namespace
Nov 20, 2026
Merged

gaborbernat merged 2 commits into
tox-dev:mainfrom
gaborbernat:fix/mx-pid-namespace

Conversation

@gaborbernat

@gaborbernat gaborbernat commented Nov 20, 2026 •

Copy link
Copy Markdown
Member

A child in a new Linux PID namespace can have the same numeric PID as its parent. Releasing an inherited lock could then release the parent's hold. Filelock now invalidates inherited locks in the child even when the PIDs match. Finalizing an inherited SQLite lock connection in the child leaves the parent's private database link in place. Issue #1021

A child callback registered before filelock's fork hook may run first. If it accesses a lock, the thread that called fork() checks whether its PID namespace changed. If either namespace identity is unreadable and the numeric PIDs match, an earlier callback can still see the parent's hold. After those earlier callbacks finish, filelock’s own child hook invalidates the inherited locks even without procfs. A lock created after the early check remains usable in the child.

Fixes #1021.

@gaborbernat
gaborbernat marked this pull request as draft November 20, 2026 15:32
@gaborbernat gaborbernat changed the title 🐛 fix(fork): protect locks across PID namespaces 🐛 fix(fork): preserve holds across PID namespaces Nov 20, 2026
@gaborbernat
gaborbernat changed the base branch from main to fix/ynl-counter-signal-agent November 20, 2026 15:43
@gaborbernat
gaborbernat marked this pull request as ready for review November 20, 2026 18:15
@gaborbernat
gaborbernat marked this pull request as draft November 20, 2026 19:33
@gaborbernat
gaborbernat marked this pull request as ready for review November 20, 2026 21:36
@gaborbernat
gaborbernat marked this pull request as draft November 20, 2026 22:00
@gaborbernat
gaborbernat deleted the branch tox-dev:fix/ynl-counter-signal-agent November 20, 2026 22:01
@gaborbernat gaborbernat reopened this Nov 20, 2026
@gaborbernat
gaborbernat changed the base branch from fix/ynl-counter-signal-agent to main November 20, 2026 22:03
A child in a new PID namespace can have its parent’s numeric PID.
Invalidate inherited locks in the child hook and check the namespace in
earlier callbacks. Only a known namespace change on the forking thread
can invalidate locks before the hook runs.

Fixes tox-dev#1021
Mark a connection as inherited before dropping the child lock's reference.
Its finalizer could otherwise close SQLite and remove the parent's
private database link when the two processes have the same PID.
@gaborbernat
gaborbernat marked this pull request as ready for review November 20, 2026 22:48
@gaborbernat
gaborbernat merged commit a8a2b5a into tox-dev:main Nov 20, 2026
49 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

A forked PID 1 child can release its parent's lock

1 participant