Skip to content

Commit 68a8310

Browse files
[AUTO-CHERRYPICK] vitess: Fix CVE-2024-45339 - branch 3.0-dev (#12196)
Co-authored-by: KavyaSree2610 <[email protected]>
1 parent e806263 commit 68a8310

File tree

2 files changed

+125
-1
lines changed

2 files changed

+125
-1
lines changed

SPECS/vitess/CVE-2024-45339.patch

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
From afd4339ec8682b92eb6bcc870d138106ffd5f58d Mon Sep 17 00:00:00 2001
2+
From: kavyasree <[email protected]>
3+
Date: Fri, 31 Jan 2025 21:16:51 +0530
4+
Subject: [PATCH] Patch CVE-2024-45339
5+
6+
Reference: https://github.com/golang/glog/pull/74
7+
8+
---
9+
vendor/github.com/golang/glog/glog_file.go | 60 ++++++++++++++++------
10+
1 file changed, 44 insertions(+), 16 deletions(-)
11+
12+
diff --git a/vendor/github.com/golang/glog/glog_file.go b/vendor/github.com/golang/glog/glog_file.go
13+
index e7d125c..6d239fa 100644
14+
--- a/vendor/github.com/golang/glog/glog_file.go
15+
+++ b/vendor/github.com/golang/glog/glog_file.go
16+
@@ -118,32 +118,53 @@ var onceLogDirs sync.Once
17+
// contains tag ("INFO", "FATAL", etc.) and t. If the file is created
18+
// successfully, create also attempts to update the symlink for that tag, ignoring
19+
// errors.
20+
-func create(tag string, t time.Time) (f *os.File, filename string, err error) {
21+
+func create(tag string, t time.Time, dir string) (f *os.File, filename string, err error) {
22+
+ if dir != "" {
23+
+ f, name, err := createInDir(dir, tag, t)
24+
+ if err == nil {
25+
+ return f, name, err
26+
+ }
27+
+ return nil, "", fmt.Errorf("log: cannot create log: %v", err)
28+
+ }
29+
+
30+
onceLogDirs.Do(createLogDirs)
31+
if len(logDirs) == 0 {
32+
return nil, "", errors.New("log: no log dirs")
33+
}
34+
- name, link := logName(tag, t)
35+
var lastErr error
36+
for _, dir := range logDirs {
37+
- fname := filepath.Join(dir, name)
38+
- f, err := os.Create(fname)
39+
+ f, name, err := createInDir(dir, tag, t)
40+
if err == nil {
41+
- symlink := filepath.Join(dir, link)
42+
- os.Remove(symlink) // ignore err
43+
- os.Symlink(name, symlink) // ignore err
44+
- if *logLink != "" {
45+
- lsymlink := filepath.Join(*logLink, link)
46+
- os.Remove(lsymlink) // ignore err
47+
- os.Symlink(fname, lsymlink) // ignore err
48+
- }
49+
- return f, fname, nil
50+
+ return f, name, err
51+
}
52+
lastErr = err
53+
}
54+
return nil, "", fmt.Errorf("log: cannot create log: %v", lastErr)
55+
}
56+
57+
+func createInDir(dir, tag string, t time.Time) (f *os.File, name string, err error) {
58+
+ name, link := logName(tag, t)
59+
+ fname := filepath.Join(dir, name)
60+
+ // O_EXCL is important here, as it prevents a vulnerability. The general idea is that logs often
61+
+ // live in an insecure directory (like /tmp), so an unprivileged attacker could create fname in
62+
+ // advance as a symlink to a file the logging process can access, but the attacker cannot. O_EXCL
63+
+ // fails the open if it already exists, thus prevent our this code from opening the existing file
64+
+ // the attacker points us to.
65+
+ f, err = os.OpenFile(fname, os.O_RDWR|os.O_CREATE|os.O_EXCL, 0666)
66+
+ if err == nil {
67+
+ symlink := filepath.Join(dir, link)
68+
+ os.Remove(symlink) // ignore err
69+
+ os.Symlink(name, symlink) // ignore err
70+
+ if *logLink != "" {
71+
+ lsymlink := filepath.Join(*logLink, link)
72+
+ os.Remove(lsymlink) // ignore err
73+
+ os.Symlink(fname, lsymlink) // ignore err
74+
+ }
75+
+ return f, fname, nil
76+
+ }
77+
+ return nil, "", err
78+
+}
79+
+
80+
// flushSyncWriter is the interface satisfied by logging destinations.
81+
type flushSyncWriter interface {
82+
Flush() error
83+
@@ -247,6 +268,7 @@ type syncBuffer struct {
84+
names []string
85+
sev logsink.Severity
86+
nbytes uint64 // The number of bytes written to this file
87+
+ madeAt time.Time
88+
}
89+
90+
func (sb *syncBuffer) Sync() error {
91+
@@ -254,9 +276,14 @@ func (sb *syncBuffer) Sync() error {
92+
}
93+
94+
func (sb *syncBuffer) Write(p []byte) (n int, err error) {
95+
+ // Rotate the file if it is too large, but ensure we only do so,
96+
+ // if rotate doesn't create a conflicting filename.
97+
if sb.nbytes+uint64(len(p)) >= MaxSize {
98+
- if err := sb.rotateFile(time.Now()); err != nil {
99+
- return 0, err
100+
+ now := timeNow()
101+
+ if now.After(sb.madeAt.Add(1*time.Second)) || now.Second() != sb.madeAt.Second() {
102+
+ if err := sb.rotateFile(now); err != nil {
103+
+ return 0, err
104+
+ }
105+
}
106+
}
107+
n, err = sb.Writer.Write(p)
108+
@@ -274,7 +301,8 @@ const footer = "\nCONTINUED IN NEXT FILE\n"
109+
func (sb *syncBuffer) rotateFile(now time.Time) error {
110+
var err error
111+
pn := "<none>"
112+
- file, name, err := create(sb.sev.String(), now)
113+
+ file, name, err := create(sb.sev.String(), now, "")
114+
+ sb.madeAt = now
115+
116+
if sb.file != nil {
117+
// The current log file becomes the previous log at the end of
118+
--
119+
2.34.1
120+

SPECS/vitess/vitess.spec

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
Name: vitess
55
Version: 19.0.4
6-
Release: 3%{?dist}
6+
Release: 4%{?dist}
77
Summary: Database clustering system for horizontal scaling of MySQL
88
# Upstream license specification: MIT and Apache-2.0
99
License: MIT and ASL 2.0
@@ -27,6 +27,7 @@ Source0: %{name}-%{version}.tar.gz
2727
#
2828
Source1: %{name}-%{version}-vendor.tar.gz
2929
Patch0: CVE-2017-14623.patch
30+
Patch1: CVE-2024-45339.patch
3031
BuildRequires: golang < 1.23
3132

3233
%description
@@ -104,6 +105,9 @@ go check -t go/cmd \
104105
%{_bindir}/*
105106

106107
%changelog
108+
* Fri Jan 31 2025 Kavya Sree Kaitepalli <[email protected]> -19.0.4-4
109+
- Patch for CVE-2024-45339
110+
107111
* Tue Oct 15 2024 Muhammad Falak <[email protected]> - 19.0.4-3
108112
- Pin golang version to <= 1.22
109113

0 commit comments

Comments
 (0)