Repository navigation
fix: create the rotation lock file 0644, and never through a symlink - #370
Merged
Merged
Conversation
lock_file() created it with S_IRWXU|S_IRWXG|S_IRWXO and followed whatever
the name pointed at. Nothing is ever written to that file -- it exists to
be fcntl locked -- so the execute bits and the world write bit were asking
for permissions the library does not use.
It matters most for the default when there is no configuration file to
lock against, /tmp/zlog.lock, which every such process shares: whoever
creates the name first decides what it refers to, and a symlink planted
there aimed the lock at a file of the attacker's choosing. Nothing is
written through it, so this is a rotation denial of service rather than
data loss, but there is no reason to leave it open. The fallback added
recently for a read-only configuration file sends more processes to that
path, which is what brought it up.
0644 and O_NOFOLLOW, the latter behind an ifdef for platforms without it.
This is not a regression for rotation between users: with the usual umask
of 022 the old mode produced 0755, so a second user could not take the
lock either, and such a setup needs the file created and chowned by hand
as the users guide says.
test_lockfile_perms checks the mode after a rotation, and that a symlink
in place of the lock file stops the rotation instead of being followed. It
fails without the change ("lock file is 0777, expected 0644"). 39/39 tests
pass in Debug, 37/37 in Release.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
The users guide said zlog opens the lock file at zlog_init() with read-write permission. It does not: the open happens the first time a rotation is due, which is why zlog_init() succeeds against a read-only configuration file and the trouble only shows up later, as a rotation that never happens (HardySimpson#88, HardySimpson#69). Bring the section up to what the code does: - the open is lazy, and the file is created 0644, with a symbolic link in its place refused rather than followed - a configuration file the process may only read cannot lock itself, so zlog falls back to /tmp/zlog.lock and warns; same when there is no configuration file at all - for rotation between users, say what actually has to be done -- create the lock file beforehand and grant write access -- rather than "make sure each program has permission", which 0644 does not give them Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
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.
lock_file() created it with S_IRWXU|S_IRWXG|S_IRWXO and followed whatever the name pointed at. Nothing is ever written to that file -- it exists to be fcntl locked -- so the execute bits and the world write bit were asking for permissions the library does not use.
It matters most for the default when there is no configuration file to lock against, /tmp/zlog.lock, which every such process shares: whoever creates the name first decides what it refers to, and a symlink planted there aimed the lock at a file of the attacker's choosing. Nothing is written through it, so this is a rotation denial of service rather than data loss, but there is no reason to leave it open. The fallback added recently for a read-only configuration file sends more processes to that path, which is what brought it up.
0644 and O_NOFOLLOW, the latter behind an ifdef for platforms without it. This is not a regression for rotation between users: with the usual umask of 022 the old mode produced 0755, so a second user could not take the lock either, and such a setup needs the file created and chowned by hand as the users guide says.
test_lockfile_perms checks the mode after a rotation, and that a symlink in place of the lock file stops the rotation instead of being followed. It fails without the change ("lock file is 0777, expected 0644"). 39/39 tests pass in Debug, 37/37 in Release.