Skip to content

Fail if log file already exists - #74

Merged
stapelberg merged 3 commits into
golang:masterfrom
chressie:fail-already-exist
Jan 13, 2025
Merged

Fail if log file already exists#74
stapelberg merged 3 commits into
golang:masterfrom
chressie:fail-already-exist

Conversation

@chressie

Copy link
Copy Markdown
Contributor

No description provided.

… 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)
@chressie chressie assigned chressie and stapelberg and unassigned chressie Jan 13, 2025
@openshift-merge-robot

Copy link
Copy Markdown

Fix included in accepted release 4.18.0-0.nightly-2025-07-22-072508

@openshift-merge-robot

Copy link
Copy Markdown

Fix included in accepted release 4.17.0-0.nightly-2025-07-22-124947

@openshift-merge-robot

Copy link
Copy Markdown

Fix included in accepted release 4.17.0-0.nightly-2025-07-24-221000

@openshift-merge-robot

Copy link
Copy Markdown

Fix included in accepted release 4.15.0-0.nightly-2025-07-25-174721

@openshift-merge-robot

Copy link
Copy Markdown

Fix included in accepted release 4.13.0-0.nightly-2025-07-27-161939

@openshift-merge-robot

Copy link
Copy Markdown

Fix included in accepted release 4.19.0-0.nightly-2025-07-28-070511

@openshift-merge-robot

Copy link
Copy Markdown

Fix included in accepted release 4.17.0-0.nightly-2025-07-30-151445

@openshift-merge-robot

Copy link
Copy Markdown

Fix included in accepted release 4.14.0-0.nightly-2025-07-31-094118

@openshift-merge-robot

Copy link
Copy Markdown

Fix included in accepted release 4.16.0-0.nightly-2025-07-31-193942

@openshift-merge-robot

Copy link
Copy Markdown

Fix included in accepted release 4.18.0-0.nightly-2025-08-01-014810

@openshift-merge-robot

Copy link
Copy Markdown

Fix included in accepted release 4.15.0-0.nightly-2025-08-01-220917

@golang golang locked as spam and limited conversation to collaborators Aug 4, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants