Fail if log file already exists - #74
Merged
Merged
Conversation
… second If you do, then you truncate the existing file. So logging too much too quickly would lose log data. cl/709080575 (google-internal)
This prevents an attack like the one described [here](https://owasp.org/www-community/vulnerabilities/Insecure_Temporary_File#:~:text=On%20Unix%20based,with%20elevated%20permissions.). An unprivileged attacker could use symlinks to trick a privileged logging process to follow a symlink from the log dir and write logs over an arbitrary file. The components of the log names are program, host, username, tag, date, time and PID. These are all predictable. It's not at all unusual for the logdir to be writable by unprivileged users, and one of the fallback directories (/tmp) traditionally has broad write privs with the sticky bit set on Unix systems. As a concrete example, let's say I've got a glog-enabled binary running as a root cronjob. I can gauge when that cron job will run and then use a bash script to spray the log dir with glog-looking symlinks to `/etc/shadow` with predicted times and PIDs. When the cronjob runs, the `os.Create` call will follow the symlink, truncate `/etc/shadow` and then fill it with logs. This change defeats that by setting `O_EXCL`, which will cause the open call to fail if the file already exists. Fixes CVE-2024-45339 cl/712795111 (google-internal)
stapelberg
approved these changes
Jan 13, 2025
|
Fix included in accepted release 4.18.0-0.nightly-2025-07-22-072508 |
|
Fix included in accepted release 4.17.0-0.nightly-2025-07-22-124947 |
|
Fix included in accepted release 4.17.0-0.nightly-2025-07-24-221000 |
|
Fix included in accepted release 4.15.0-0.nightly-2025-07-25-174721 |
|
Fix included in accepted release 4.13.0-0.nightly-2025-07-27-161939 |
|
Fix included in accepted release 4.19.0-0.nightly-2025-07-28-070511 |
|
Fix included in accepted release 4.17.0-0.nightly-2025-07-30-151445 |
|
Fix included in accepted release 4.14.0-0.nightly-2025-07-31-094118 |
|
Fix included in accepted release 4.16.0-0.nightly-2025-07-31-193942 |
|
Fix included in accepted release 4.18.0-0.nightly-2025-08-01-014810 |
|
Fix included in accepted release 4.15.0-0.nightly-2025-08-01-220917 |
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
No description provided.