Skip to content

[POSIX] Use flock instead of fcntl#973

Merged
mhutchinson merged 2 commits into
transparency-dev:mainfrom
mhutchinson:bug/posix-locking
Jun 2, 2026
Merged

[POSIX] Use flock instead of fcntl#973
mhutchinson merged 2 commits into
transparency-dev:mainfrom
mhutchinson:bug/posix-locking

Conversation

@mhutchinson
Copy link
Copy Markdown
Contributor

BSD flock locks are associated with the open file description rather than the PID, which prevents different file descriptors in the same process from concurrently acquiring the lock. This avoids a silent-release vulnerability where closing any file descriptor to the lock file in the process immediately drops the lock for all other descriptors.

This doesn't fix any immediate known issues. However, it does make things less brittle. Should we change which files are written from different goroutines in the future, this will protect against multiple workers ignoring each other's locks.

It also avoids a risk that a library user could create 2 instances of a POSIX storage backed by the same directory. Previously these would have ignored each other's locks, but now they will respect them.

@mhutchinson mhutchinson requested a review from a team as a code owner June 2, 2026 10:06
@mhutchinson mhutchinson requested a review from phbnf June 2, 2026 10:06
@mhutchinson mhutchinson requested a review from AlCutter June 2, 2026 10:06
Comment thread storage/posix/files.go
BSD flock locks are associated with the open file description rather than the PID, which prevents different file descriptors in the same process from concurrently acquiring the lock. This avoids a silent-release vulnerability where closing any file descriptor to the lock file in the process immediately drops the lock for all other descriptors.

This doesn't fix any immediate known issues. However, it does make things less brittle. Should we change which files are written from different goroutines in the future, this will protect against multiple workers ignoring each other's locks.

It also avoids a risk that a library user could create 2 instances of a POSIX storage backed by the same directory. Previously these would have ignored each other's locks, but now they will respect them.
@mhutchinson mhutchinson merged commit 917c768 into transparency-dev:main Jun 2, 2026
19 checks passed
@mhutchinson mhutchinson deleted the bug/posix-locking branch June 2, 2026 11:08
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.

2 participants