Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vitess: Fix CVE-2024-45339 [HIGH] #12173

Open
wants to merge 4 commits into
base: fasttrack/2.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
120 changes: 120 additions & 0 deletions SPECS/vitess/CVE-2024-45339.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
From afd4339ec8682b92eb6bcc870d138106ffd5f58d Mon Sep 17 00:00:00 2001
From: kavyasree <[email protected]>
Date: Fri, 31 Jan 2025 21:16:51 +0530
Subject: [PATCH] Patch CVE-2024-45339

Reference: https://github.com/golang/glog/pull/74

---
vendor/github.com/golang/glog/glog_file.go | 60 ++++++++++++++++------
1 file changed, 44 insertions(+), 16 deletions(-)

diff --git a/vendor/github.com/golang/glog/glog_file.go b/vendor/github.com/golang/glog/glog_file.go
index e7d125c..6d239fa 100644
--- a/vendor/github.com/golang/glog/glog_file.go
+++ b/vendor/github.com/golang/glog/glog_file.go
@@ -118,32 +118,53 @@ var onceLogDirs sync.Once
// contains tag ("INFO", "FATAL", etc.) and t. If the file is created
// successfully, create also attempts to update the symlink for that tag, ignoring
// errors.
-func create(tag string, t time.Time) (f *os.File, filename string, err error) {
+func create(tag string, t time.Time, dir string) (f *os.File, filename string, err error) {
+ if dir != "" {
+ f, name, err := createInDir(dir, tag, t)
+ if err == nil {
+ return f, name, err
+ }
+ return nil, "", fmt.Errorf("log: cannot create log: %v", err)
+ }
+
onceLogDirs.Do(createLogDirs)
if len(logDirs) == 0 {
return nil, "", errors.New("log: no log dirs")
}
- name, link := logName(tag, t)
var lastErr error
for _, dir := range logDirs {
- fname := filepath.Join(dir, name)
- f, err := os.Create(fname)
+ f, name, err := createInDir(dir, tag, t)
if err == nil {
- symlink := filepath.Join(dir, link)
- os.Remove(symlink) // ignore err
- os.Symlink(name, symlink) // ignore err
- if *logLink != "" {
- lsymlink := filepath.Join(*logLink, link)
- os.Remove(lsymlink) // ignore err
- os.Symlink(fname, lsymlink) // ignore err
- }
- return f, fname, nil
+ return f, name, err
}
lastErr = err
}
return nil, "", fmt.Errorf("log: cannot create log: %v", lastErr)
}

+func createInDir(dir, tag string, t time.Time) (f *os.File, name string, err error) {
+ name, link := logName(tag, t)
+ fname := filepath.Join(dir, name)
+ // O_EXCL is important here, as it prevents a vulnerability. The general idea is that logs often
+ // live in an insecure directory (like /tmp), so an unprivileged attacker could create fname in
+ // advance as a symlink to a file the logging process can access, but the attacker cannot. O_EXCL
+ // fails the open if it already exists, thus prevent our this code from opening the existing file
+ // the attacker points us to.
+ f, err = os.OpenFile(fname, os.O_RDWR|os.O_CREATE|os.O_EXCL, 0666)
+ if err == nil {
+ symlink := filepath.Join(dir, link)
+ os.Remove(symlink) // ignore err
+ os.Symlink(name, symlink) // ignore err
+ if *logLink != "" {
+ lsymlink := filepath.Join(*logLink, link)
+ os.Remove(lsymlink) // ignore err
+ os.Symlink(fname, lsymlink) // ignore err
+ }
+ return f, fname, nil
+ }
+ return nil, "", err
+}
+
// flushSyncWriter is the interface satisfied by logging destinations.
type flushSyncWriter interface {
Flush() error
@@ -247,6 +268,7 @@ type syncBuffer struct {
names []string
sev logsink.Severity
nbytes uint64 // The number of bytes written to this file
+ madeAt time.Time
}

func (sb *syncBuffer) Sync() error {
@@ -254,9 +276,14 @@ func (sb *syncBuffer) Sync() error {
}

func (sb *syncBuffer) Write(p []byte) (n int, err error) {
+ // Rotate the file if it is too large, but ensure we only do so,
+ // if rotate doesn't create a conflicting filename.
if sb.nbytes+uint64(len(p)) >= MaxSize {
- if err := sb.rotateFile(time.Now()); err != nil {
- return 0, err
+ now := timeNow()
+ if now.After(sb.madeAt.Add(1*time.Second)) || now.Second() != sb.madeAt.Second() {
+ if err := sb.rotateFile(now); err != nil {
+ return 0, err
+ }
}
}
n, err = sb.Writer.Write(p)
@@ -274,7 +301,8 @@ const footer = "\nCONTINUED IN NEXT FILE\n"
func (sb *syncBuffer) rotateFile(now time.Time) error {
var err error
pn := "<none>"
- file, name, err := create(sb.sev.String(), now)
+ file, name, err := create(sb.sev.String(), now, "")
+ sb.madeAt = now

if sb.file != nil {
// The current log file becomes the previous log at the end of
--
2.34.1

6 changes: 5 additions & 1 deletion SPECS/vitess/vitess.spec
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

Name: vitess
Version: 17.0.7
Release: 3%{?dist}
Release: 4%{?dist}
Summary: Database clustering system for horizontal scaling of MySQL
# Upstream license specification: MIT and Apache-2.0
License: MIT and ASL 2.0
Expand All @@ -27,6 +27,7 @@ Source0: %{name}-%{version}.tar.gz
#
Source1: %{name}-%{version}-vendor.tar.gz
Patch0: CVE-2024-45338.patch
Patch1: CVE-2024-45339.patch
BuildRequires: golang

%description
Expand Down Expand Up @@ -104,6 +105,9 @@ go check -t go/cmd \
%{_bindir}/*

%changelog
* Fri Jan 31 2025 Kavya Sree Kaitepalli <[email protected]> - 17.0.7-4
- Add patch for CVE-2024-45339

* Thu Jan 02 2025 Sumedh Sharma <[email protected]> - 17.0.7-3
- Add patch for CVE-2024-45338.

Expand Down
Loading