Skip to content

Commit 1a65dff

Browse files
KavyaSree2610kavyasree
and
kavyasree
authored
sriov-network-device-plugin: Fix CVE-2024-45339 (#12175)
Co-authored-by: kavyasree <[email protected]>
1 parent ba0b6ec commit 1a65dff

File tree

2 files changed

+124
-1
lines changed

2 files changed

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

SPECS/sriov-network-device-plugin/sriov-network-device-plugin.spec

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Summary: Plugin for discovering and advertising networking resources
22
Name: sriov-network-device-plugin
33
Version: 3.6.2
4-
Release: 7%{?dist}
4+
Release: 8%{?dist}
55
License: MIT
66
Vendor: Microsoft Corporation
77
Distribution: Mariner
@@ -10,6 +10,7 @@ Source0: https://github.com/k8snetworkplumbingwg/%{name}/archive/refs/tag
1010
Patch0: CVE-2023-45288.patch
1111
Patch1: CVE-2024-24786.patch
1212
Patch2: CVE-2024-45338.patch
13+
Patch3: CVE-2024-45339.patch
1314
BuildRequires: golang
1415
Requires: gawk
1516
Requires: hwdata
@@ -37,6 +38,9 @@ install -D -m0755 images/ddptool-1.0.1.12.tar.gz %{buildroot}%{_datadir}/%{name}
3738
%{_datadir}/%{name}/ddptool-1.0.1.12.tar.gz
3839

3940
%changelog
41+
* Fri Jan 31 2025 Kavya Sree Kaitepalli <[email protected]> - 3.6.2-8
42+
- Add patch for CVE-2024-45339
43+
4044
* Thu Jan 02 2025 Sumedh Sharma <[email protected]> - 3.6.2-7
4145
- Add patch for CVE-2024-45338.
4246

0 commit comments

Comments
 (0)