Repository navigation
🐛 fix(rw): protect private database links - #1096
Merged
gaborbernat merged 8 commits intoNov 21, 2026
Merged
Conversation
Cleanup in another PID namespace can mistake a live owner for dead and unlink its private alias before SQLite opens it. A missing alias now fails instead of creating a second database. When procfs cannot verify namespace identity, cleanup leaves links in place, so stale links may need manual removal. Fixes tox-dev#1005
A busy shared directory can exhaust the cleanup budget before a process finds a dead holder’s link. A later connection can retry the sweep.
A watch on a shared-directory entry can outlive a permissions change. Create the final link name inside a fresh private child, and reject inherited permissions that would expose that name.
gaborbernat
marked this pull request as draft
November 20, 2026 15:32
gaborbernat
marked this pull request as ready for review
November 20, 2026 17:40
gaborbernat
marked this pull request as draft
November 20, 2026 19:32
Filesystems with inherited ACLs can grant group access to newly created directories. Set mode 0700 on the nested directory and check it again before creating the private link.
Starting over on each connection kept large directories from ever reaching their last entry. Pause between scan slices and retain up to 16 directory iterators so later connections can continue. Drop inherited iterators in a fork child and start a fresh scan if the parent directory changes.
gaborbernat
marked this pull request as ready for review
November 20, 2026 22:03
gaborbernat
marked this pull request as draft
November 20, 2026 23:57
The child must leave an inherited SQLite connection open and close its copy of a paused cleanup iterator. Keep both tests and their platform requirements.
gaborbernat
marked this pull request as ready for review
November 21, 2026 00:13
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.
Processes sharing a
ReadWriteLockorAsyncReadWriteLockdatabase need to open the same file. On POSIX, filelock now opens the private hard link with SQLite'smode=rw. If the link disappears before SQLite opens it, acquisition fails. Upgrade every process sharing the database before resuming lock operations. Earlier releases can create a separate database at a missing link. Fixes #1005.The final link sits inside a new directory that only the locking account can access. If inherited permissions let other accounts in, filelock sets mode 0700 and checks the directory again before creating the link. This keeps the final link name hidden from anyone watching the enclosing directory. Private link advisory
Cleanup checks a 50 ms deadline between directory entries. When a scan runs out of time, that process skips cleanup for the database for one minute. Its next eligible connection resumes the scan. Each process keeps up to 16 paused scans. An evicted scan starts over. Linux processes that cannot verify a holder's PID namespace leave its links in place. Stop all database users before removing stale directories. Cleanup advisory
flowchart TD A["Open by private hard link"] --> B["Create a private directory"] B --> G["Tighten inherited permissions if needed"] G --> C{"Only owner has access?"} C -->|Yes| D["Open existing link"] C -->|No| E["Refuse acquisition"] D -->|Link exists| F["Use shared database"] D -->|Link missing| E classDef work fill:#cfe4ff,stroke:#1f6feb,color:#0b1f3a classDef stop fill:#ffe3a3,stroke:#d29200,color:#3a2c00 class A,B,C,D,F,G work class E stop