Skip to content

Commit 5a82cf5

Browse files
[AUTO-CHERRYPICK] Fix multiple CVE in Skopeo - branch 3.0-dev (#12134)
Co-authored-by: Rohit Rawat <[email protected]>
1 parent f426b7a commit 5a82cf5

File tree

3 files changed

+250
-1
lines changed

3 files changed

+250
-1
lines changed

SPECS/skopeo/CVE-2023-45288.patch

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
From 224f3ac556af38fe8a2f719cdfe5752acfc276b6 Mon Sep 17 00:00:00 2001
2+
From: Rohit Rawat <[email protected]>
3+
Date: Sun, 10 Nov 2024 19:06:25 +0000
4+
Subject: [PATCH] http2: close connections when receiving too many headers
5+
6+
Patch from https://go-review.googlesource.com/c/net/+/576057
7+
---
8+
vendor/golang.org/x/net/http2/frame.go | 31 ++++++++++++++++++++++++++
9+
1 file changed, 31 insertions(+)
10+
11+
diff --git a/vendor/golang.org/x/net/http2/frame.go b/vendor/golang.org/x/net/http2/frame.go
12+
index c1f6b90..175c154 100644
13+
--- a/vendor/golang.org/x/net/http2/frame.go
14+
+++ b/vendor/golang.org/x/net/http2/frame.go
15+
@@ -1565,6 +1565,7 @@ func (fr *Framer) readMetaFrame(hf *HeadersFrame) (*MetaHeadersFrame, error) {
16+
if size > remainSize {
17+
hdec.SetEmitEnabled(false)
18+
mh.Truncated = true
19+
+ remainSize = 0
20+
return
21+
}
22+
remainSize -= size
23+
@@ -1577,6 +1578,36 @@ func (fr *Framer) readMetaFrame(hf *HeadersFrame) (*MetaHeadersFrame, error) {
24+
var hc headersOrContinuation = hf
25+
for {
26+
frag := hc.HeaderBlockFragment()
27+
+
28+
+ // Avoid parsing large amounts of headers that we will then discard.
29+
+ // If the sender exceeds the max header list size by too much,
30+
+ // skip parsing the fragment and close the connection.
31+
+ //
32+
+ // "Too much" is either any CONTINUATION frame after we've already
33+
+ // exceeded the max header list size (in which case remainSize is 0),
34+
+ // or a frame whose encoded size is more than twice the remaining
35+
+ // header list bytes we're willing to accept.
36+
+ if int64(len(frag)) > int64(2*remainSize) {
37+
+ if VerboseLogs {
38+
+ log.Printf("http2: header list too large")
39+
+ }
40+
+ // It would be nice to send a RST_STREAM before sending the GOAWAY,
41+
+ // but the struture of the server's frame writer makes this difficult.
42+
+ return nil, ConnectionError(ErrCodeProtocol)
43+
+ }
44+
+
45+
+ // Also close the connection after any CONTINUATION frame following an
46+
+ // invalid header, since we stop tracking the size of the headers after
47+
+ // an invalid one.
48+
+ if invalid != nil {
49+
+ if VerboseLogs {
50+
+ log.Printf("http2: invalid header: %v", invalid)
51+
+ }
52+
+ // It would be nice to send a RST_STREAM before sending the GOAWAY,
53+
+ // but the struture of the server's frame writer makes this difficult.
54+
+ return nil, ConnectionError(ErrCodeProtocol)
55+
+ }
56+
+
57+
if _, err := hdec.Write(frag); err != nil {
58+
return nil, ConnectionError(ErrCodeCompression)
59+
}
60+
--
61+
2.39.4
62+

SPECS/skopeo/CVE-2024-9676.patch

Lines changed: 182 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,182 @@
1+
From d461620d47450c72d9f0da215606949272df3398 Mon Sep 17 00:00:00 2001
2+
From: Rohit Rawat <[email protected]>
3+
Date: Sun, 10 Nov 2024 18:36:17 +0000
4+
Subject: [PATCH] Backport CVE-2024-9676 fix
5+
6+
Patch from https://github.com/containers/storage/pull/2146 by Matt Heon <[email protected]>
7+
---
8+
.../github.com/containers/storage/.cirrus.yml | 2 +-
9+
.../github.com/containers/storage/userns.go | 92 +++++++++++++------
10+
.../containers/storage/userns_unsupported.go | 14 +++
11+
3 files changed, 80 insertions(+), 28 deletions(-)
12+
create mode 100644 vendor/github.com/containers/storage/userns_unsupported.go
13+
14+
diff --git a/vendor/github.com/containers/storage/.cirrus.yml b/vendor/github.com/containers/storage/.cirrus.yml
15+
index c41dd5d..9e61509 100644
16+
--- a/vendor/github.com/containers/storage/.cirrus.yml
17+
+++ b/vendor/github.com/containers/storage/.cirrus.yml
18+
@@ -119,7 +119,7 @@ lint_task:
19+
env:
20+
CIRRUS_WORKING_DIR: "/go/src/github.com/containers/storage"
21+
container:
22+
- image: golang
23+
+ image: golang:1.19
24+
modules_cache:
25+
fingerprint_script: cat go.sum
26+
folder: $GOPATH/pkg/mod
27+
diff --git a/vendor/github.com/containers/storage/userns.go b/vendor/github.com/containers/storage/userns.go
28+
index 32ae830..2c855da 100644
29+
--- a/vendor/github.com/containers/storage/userns.go
30+
+++ b/vendor/github.com/containers/storage/userns.go
31+
@@ -1,18 +1,21 @@
32+
+//go:build linux
33+
+
34+
package storage
35+
36+
import (
37+
"fmt"
38+
"os"
39+
"os/user"
40+
- "path/filepath"
41+
"strconv"
42+
43+
drivers "github.com/containers/storage/drivers"
44+
"github.com/containers/storage/pkg/idtools"
45+
"github.com/containers/storage/pkg/unshare"
46+
"github.com/containers/storage/types"
47+
+ securejoin "github.com/cyphar/filepath-securejoin"
48+
libcontainerUser "github.com/opencontainers/runc/libcontainer/user"
49+
"github.com/sirupsen/logrus"
50+
+ "golang.org/x/sys/unix"
51+
)
52+
53+
// getAdditionalSubIDs looks up the additional IDs configured for
54+
@@ -85,40 +88,59 @@ const nobodyUser = 65534
55+
// parseMountedFiles returns the maximum UID and GID found in the /etc/passwd and
56+
// /etc/group files.
57+
func parseMountedFiles(containerMount, passwdFile, groupFile string) uint32 {
58+
+ var (
59+
+ passwd *os.File
60+
+ group *os.File
61+
+ size int
62+
+ err error
63+
+ )
64+
if passwdFile == "" {
65+
- passwdFile = filepath.Join(containerMount, "etc/passwd")
66+
- }
67+
- if groupFile == "" {
68+
- groupFile = filepath.Join(groupFile, "etc/group")
69+
+ passwd, err = secureOpen(containerMount, "/etc/passwd")
70+
+ } else {
71+
+ // User-specified override from a volume. Will not be in
72+
+ // container root.
73+
+ passwd, err = os.Open(passwdFile)
74+
}
75+
-
76+
- size := 0
77+
-
78+
- users, err := libcontainerUser.ParsePasswdFile(passwdFile)
79+
if err == nil {
80+
- for _, u := range users {
81+
- // Skip the "nobody" user otherwise we end up with 65536
82+
- // ids with most images
83+
- if u.Name == "nobody" {
84+
- continue
85+
- }
86+
- if u.Uid > size && u.Uid != nobodyUser {
87+
- size = u.Uid
88+
- }
89+
- if u.Gid > size && u.Gid != nobodyUser {
90+
- size = u.Gid
91+
+ defer passwd.Close()
92+
+
93+
+ users, err := libcontainerUser.ParsePasswd(passwd)
94+
+ if err == nil {
95+
+ for _, u := range users {
96+
+ // Skip the "nobody" user otherwise we end up with 65536
97+
+ // ids with most images
98+
+ if u.Name == "nobody" || u.Name == "nogroup" {
99+
+ continue
100+
+ }
101+
+ if u.Uid > size && u.Uid != nobodyUser {
102+
+ size = u.Uid + 1
103+
+ }
104+
+ if u.Gid > size && u.Gid != nobodyUser {
105+
+ size = u.Gid + 1
106+
+ }
107+
}
108+
}
109+
}
110+
111+
- groups, err := libcontainerUser.ParseGroupFile(groupFile)
112+
+ if groupFile == "" {
113+
+ group, err = secureOpen(containerMount, "/etc/group")
114+
+ } else {
115+
+ // User-specified override from a volume. Will not be in
116+
+ // container root.
117+
+ group, err = os.Open(groupFile)
118+
+ }
119+
if err == nil {
120+
- for _, g := range groups {
121+
- if g.Name == "nobody" {
122+
- continue
123+
- }
124+
- if g.Gid > size && g.Gid != nobodyUser {
125+
- size = g.Gid
126+
+ defer group.Close()
127+
+
128+
+ groups, err := libcontainerUser.ParseGroup(group)
129+
+ if err == nil {
130+
+ for _, g := range groups {
131+
+ if g.Name == "nobody" || g.Name == "nogroup" {
132+
+ continue
133+
+ }
134+
+ if g.Gid > size && g.Gid != nobodyUser {
135+
+ size = g.Gid + 1
136+
+ }
137+
}
138+
}
139+
}
140+
@@ -309,3 +331,19 @@ func getAutoUserNSIDMappings(
141+
gidMap := append(availableGIDs.zip(requestedContainerGIDs), additionalGIDMappings...)
142+
return uidMap, gidMap, nil
143+
}
144+
+
145+
+// Securely open (read-only) a file in a container mount.
146+
+func secureOpen(containerMount, file string) (*os.File, error) {
147+
+ filePath, err := securejoin.SecureJoin(containerMount, file)
148+
+ if err != nil {
149+
+ return nil, err
150+
+ }
151+
+
152+
+ flags := unix.O_PATH | unix.O_CLOEXEC | unix.O_RDONLY
153+
+ fileHandle, err := os.OpenFile(filePath, flags, 0)
154+
+ if err != nil {
155+
+ return nil, err
156+
+ }
157+
+
158+
+ return fileHandle, nil
159+
+}
160+
diff --git a/vendor/github.com/containers/storage/userns_unsupported.go b/vendor/github.com/containers/storage/userns_unsupported.go
161+
new file mode 100644
162+
index 0000000..e37c18f
163+
--- /dev/null
164+
+++ b/vendor/github.com/containers/storage/userns_unsupported.go
165+
@@ -0,0 +1,14 @@
166+
+//go:build !linux
167+
+
168+
+package storage
169+
+
170+
+import (
171+
+ "errors"
172+
+
173+
+ "github.com/containers/storage/pkg/idtools"
174+
+ "github.com/containers/storage/types"
175+
+)
176+
+
177+
+func (s *store) getAutoUserNS(_ *types.AutoUserNsOptions, _ *Image, _ rwLayerStore, _ []roLayerStore) ([]idtools.IDMap, []idtools.IDMap, error) {
178+
+ return nil, nil, errors.New("user namespaces are not supported on this platform")
179+
+}
180+
--
181+
2.39.4
182+

SPECS/skopeo/skopeo.spec

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Summary: Inspect container images and repositories on registries
22
Name: skopeo
33
Version: 1.14.4
4-
Release: 2%{?dist}
4+
Release: 3%{?dist}
55
License: Apache-2.0
66
Vendor: Microsoft Corporation
77
Distribution: Azure Linux
@@ -10,6 +10,8 @@ URL: https://github.com/containers/skopeo
1010
Source0: https://github.com/containers/skopeo/archive/refs/tags/v%{version}.tar.gz#/%{name}-%{version}.tar.gz
1111
Patch0: CVE-2022-2879.patch
1212
Patch1: CVE-2024-6104.patch
13+
Patch2: CVE-2023-45288.patch
14+
Patch3: CVE-2024-9676.patch
1315

1416
%global debug_package %{nil}
1517
%define our_gopath %{_topdir}/.gopath
@@ -49,6 +51,9 @@ make test-unit-local
4951
%{_mandir}/man1/%%{name}*
5052

5153
%changelog
54+
* Mon Nov 11 2024 Rohit Rawat <[email protected]> - 1.14.4-3
55+
- Fix CVE-2023-45288 and CVE-2024-9676
56+
5257
* Fri Aug 02 2024 Sindhu Karri <[email protected]> - 1.14.4-2
5358
- Fix CVE-2024-6104 in github.com/hashicorp/go-retryablehttp with a patch
5459

0 commit comments

Comments
 (0)