Skip to content

Commit e21478f

Browse files
[AUTO-CHERRYPICK] Fix multiple CVEs in moby-buildx package - branch main (#10381)
Co-authored-by: Bala <kumaran.4353@gmail.com>
1 parent a17f93f commit e21478f

5 files changed

Lines changed: 496 additions & 1 deletion

File tree

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
From 42d1c02750b3631402da3973e5f36b76c8c934f4 Mon Sep 17 00:00:00 2001
2+
From: Samuel Karp <skarp@amazon.com>
3+
Date: Wed, 21 Jul 2021 17:59:42 -0700
4+
Subject: [PATCH] registry: ensure default auth config has address
5+
6+
Signed-off-by: Samuel Karp <skarp@amazon.com>
7+
---
8+
.../github.com/docker/cli/cli/command/registry.go | 15 +++++++--------
9+
1 file changed, 7 insertions(+), 8 deletions(-)
10+
11+
diff --git a/vendor/github.com/docker/cli/cli/command/registry.go b/vendor/github.com/docker/cli/cli/command/registry.go
12+
index e6311c8..68e3dd3 100644
13+
--- a/vendor/github.com/docker/cli/cli/command/registry.go
14+
+++ b/vendor/github.com/docker/cli/cli/command/registry.go
15+
@@ -63,17 +63,14 @@ func RegistryAuthenticationPrivilegedFunc(cli Cli, index *registrytypes.IndexInf
16+
indexServer := registry.GetAuthConfigKey(index)
17+
isDefaultRegistry := indexServer == ElectAuthServer(context.Background(), cli)
18+
authConfig, err := GetDefaultAuthConfig(cli, true, indexServer, isDefaultRegistry)
19+
- if authConfig == nil {
20+
- authConfig = &types.AuthConfig{}
21+
- }
22+
if err != nil {
23+
fmt.Fprintf(cli.Err(), "Unable to retrieve stored credentials for %s, error: %s.\n", indexServer, err)
24+
}
25+
- err = ConfigureAuth(cli, "", "", authConfig, isDefaultRegistry)
26+
+ err = ConfigureAuth(cli, "", "", &authConfig, isDefaultRegistry)
27+
if err != nil {
28+
return "", err
29+
}
30+
- return EncodeAuthToBase64(*authConfig)
31+
+ return EncodeAuthToBase64(authConfig)
32+
}
33+
}
34+
35+
@@ -92,7 +89,7 @@ func ResolveAuthConfig(ctx context.Context, cli Cli, index *registrytypes.IndexI
36+
37+
// GetDefaultAuthConfig gets the default auth config given a serverAddress
38+
// If credentials for given serverAddress exists in the credential store, the configuration will be populated with values in it
39+
-func GetDefaultAuthConfig(cli Cli, checkCredStore bool, serverAddress string, isDefaultRegistry bool) (*types.AuthConfig, error) {
40+
+func GetDefaultAuthConfig(cli Cli, checkCredStore bool, serverAddress string, isDefaultRegistry bool) (types.AuthConfig, error) {
41+
if !isDefaultRegistry {
42+
serverAddress = registry.ConvertToHostname(serverAddress)
43+
}
44+
@@ -101,13 +98,15 @@ func GetDefaultAuthConfig(cli Cli, checkCredStore bool, serverAddress string, is
45+
if checkCredStore {
46+
authconfig, err = cli.ConfigFile().GetAuthConfig(serverAddress)
47+
if err != nil {
48+
- return nil, err
49+
+ return types.AuthConfig{
50+
+ ServerAddress: serverAddress,
51+
+ }, err
52+
}
53+
}
54+
authconfig.ServerAddress = serverAddress
55+
authconfig.IdentityToken = ""
56+
res := types.AuthConfig(authconfig)
57+
- return &res, nil
58+
+ return res, nil
59+
}
60+
61+
// ConfigureAuth handles prompting of user's username and password if needed
62+
--
63+
2.33.8
64+
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
From 1e63c2f08a10a150fa02c50ece89b340ae64efe4 Mon Sep 17 00:00:00 2001
2+
From: Damien Neil <dneil@google.com>
3+
Date: Tue, 6 Dec 2022 11:57:53 -0800
4+
Subject: [PATCH] http2: limit canonical header cache by bytes, not entries
5+
6+
The canonical header cache is a per-connection cache mapping header
7+
keys to their canonicalized form. (For example, "foo-bar" => "Foo-Bar").
8+
We limit the number of entries in the cache to prevent an attacker
9+
from consuming unbounded amounts of memory by sending many unique
10+
keys, but a small number of very large keys can still consume an
11+
unreasonable amount of memory.
12+
13+
Track the amount of memory consumed by the cache and limit it based
14+
on memory rather than number of entries.
15+
16+
Thanks to Josselin Costanzi for reporting this issue.
17+
18+
For golang/go#56350
19+
20+
Change-Id: I41db4c9823ed5bf371a9881accddff1268489b16
21+
Reviewed-on: https://go-review.googlesource.com/c/net/+/455635
22+
Reviewed-by: Jenny Rakoczy <jenny@golang.org>
23+
Run-TryBot: Damien Neil <dneil@google.com>
24+
TryBot-Result: Gopher Robot <gobot@golang.org>
25+
---
26+
vendor/golang.org/x/net/http2/server.go | 18 +++++++++++-------
27+
1 file changed, 11 insertions(+), 7 deletions(-)
28+
29+
diff --git a/vendor/golang.org/x/net/http2/server.go b/vendor/golang.org/x/net/http2/server.go
30+
index 52afaa6..f26f665 100644
31+
--- a/vendor/golang.org/x/net/http2/server.go
32+
+++ b/vendor/golang.org/x/net/http2/server.go
33+
@@ -525,6 +525,7 @@ type serverConn struct {
34+
headerTableSize uint32
35+
peerMaxHeaderListSize uint32 // zero means unknown (default)
36+
canonHeader map[string]string // http2-lower-case -> Go-Canonical-Case
37+
+ canonHeaderKeysSize int // canonHeader keys size in bytes
38+
writingFrame bool // started writing a frame (on serve goroutine or separate)
39+
writingFrameAsync bool // started a frame on its own goroutine but haven't heard back on wroteFrameCh
40+
needsFrameFlush bool // last frame write wasn't a flush
41+
@@ -701,6 +702,13 @@ func (sc *serverConn) condlogf(err error, format string, args ...interface{}) {
42+
}
43+
}
44+
45+
+// maxCachedCanonicalHeadersKeysSize is an arbitrarily-chosen limit on the size
46+
+// of the entries in the canonHeader cache.
47+
+// This should be larger than the size of unique, uncommon header keys likely to
48+
+// be sent by the peer, while not so high as to permit unreasonable memory usage
49+
+// if the peer sends an unbounded number of unique header keys.
50+
+const maxCachedCanonicalHeadersKeysSize = 2048
51+
+
52+
func (sc *serverConn) canonicalHeader(v string) string {
53+
sc.serveG.check()
54+
buildCommonHeaderMapsOnce()
55+
@@ -716,14 +724,10 @@ func (sc *serverConn) canonicalHeader(v string) string {
56+
sc.canonHeader = make(map[string]string)
57+
}
58+
cv = http.CanonicalHeaderKey(v)
59+
- // maxCachedCanonicalHeaders is an arbitrarily-chosen limit on the number of
60+
- // entries in the canonHeader cache. This should be larger than the number
61+
- // of unique, uncommon header keys likely to be sent by the peer, while not
62+
- // so high as to permit unreaasonable memory usage if the peer sends an unbounded
63+
- // number of unique header keys.
64+
- const maxCachedCanonicalHeaders = 32
65+
- if len(sc.canonHeader) < maxCachedCanonicalHeaders {
66+
+ size := 100 + len(v)*2 // 100 bytes of map overhead + key + value
67+
+ if sc.canonHeaderKeysSize+size <= maxCachedCanonicalHeadersKeysSize {
68+
sc.canonHeader[v] = cv
69+
+ sc.canonHeaderKeysSize += size
70+
}
71+
return cv
72+
}
73+
--
74+
2.33.8
75+
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
Parent: ebc8168a (all: fix some typos)
2+
Author: Damien Neil <dneil@google.com>
3+
AuthorDate: 2024-01-10 13:41:39 -0800
4+
Commit: Gopher Robot <gobot@golang.org>
5+
CommitDate: 2024-04-03 16:01:29 +0000
6+
7+
http2: close connections when receiving too many headers
8+
9+
Maintaining HPACK state requires that we parse and process
10+
all HEADERS and CONTINUATION frames on a connection.
11+
When a request's headers exceed MaxHeaderBytes, we don't
12+
allocate memory to store the excess headers but we do
13+
parse them. This permits an attacker to cause an HTTP/2
14+
endpoint to read arbitrary amounts of data, all associated
15+
with a request which is going to be rejected.
16+
17+
Set a limit on the amount of excess header frames we
18+
will process before closing a connection.
19+
20+
Thanks to Bartek Nowotarski for reporting this issue.
21+
22+
Fixes CVE-2023-45288
23+
Fixes golang/go#65051
24+
25+
Change-Id: I15df097268df13bb5a9e9d3a5c04a8a141d850f6
26+
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go-private/+/2130527
27+
Reviewed-by: Roland Shoemaker <bracewell@google.com>
28+
Reviewed-by: Tatiana Bradley <tatianabradley@google.com>
29+
Reviewed-on: https://go-review.googlesource.com/c/net/+/576155
30+
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
31+
Auto-Submit: Dmitri Shuralyov <dmitshur@golang.org>
32+
Reviewed-by: Than McIntosh <thanm@google.com>
33+
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
34+
35+
---
36+
vendor/golang.org/x/net/http2/frame.go | 31 ++++++++++++++++++++++++++
37+
1 file changed, 31 insertions(+)
38+
39+
diff --git a/vendor/golang.org/x/net/http2/frame.go b/vendor/golang.org/x/net/http2/frame.go
40+
index 514c126..37f3e0e 100644
41+
--- a/vendor/golang.org/x/net/http2/frame.go
42+
+++ b/vendor/golang.org/x/net/http2/frame.go
43+
@@ -1521,6 +1521,7 @@ func (fr *Framer) readMetaFrame(hf *HeadersFrame) (*MetaHeadersFrame, error) {
44+
if size > remainSize {
45+
hdec.SetEmitEnabled(false)
46+
mh.Truncated = true
47+
+ remainSize = 0
48+
return
49+
}
50+
remainSize -= size
51+
@@ -1533,6 +1534,36 @@ func (fr *Framer) readMetaFrame(hf *HeadersFrame) (*MetaHeadersFrame, error) {
52+
var hc headersOrContinuation = hf
53+
for {
54+
frag := hc.HeaderBlockFragment()
55+
+
56+
+ // Avoid parsing large amounts of headers that we will then discard.
57+
+ // If the sender exceeds the max header list size by too much,
58+
+ // skip parsing the fragment and close the connection.
59+
+ //
60+
+ // "Too much" is either any CONTINUATION frame after we've already
61+
+ // exceeded the max header list size (in which case remainSize is 0),
62+
+ // or a frame whose encoded size is more than twice the remaining
63+
+ // header list bytes we're willing to accept.
64+
+ if int64(len(frag)) > int64(2*remainSize) {
65+
+ if VerboseLogs {
66+
+ log.Printf("http2: header list too large")
67+
+ }
68+
+ // It would be nice to send a RST_STREAM before sending the GOAWAY,
69+
+ // but the struture of the server's frame writer makes this difficult.
70+
+ return nil, ConnectionError(ErrCodeProtocol)
71+
+ }
72+
+
73+
+ // Also close the connection after any CONTINUATION frame following an
74+
+ // invalid header, since we stop tracking the size of the headers after
75+
+ // an invalid one.
76+
+ if invalid != nil {
77+
+ if VerboseLogs {
78+
+ log.Printf("http2: invalid header: %v", invalid)
79+
+ }
80+
+ // It would be nice to send a RST_STREAM before sending the GOAWAY,
81+
+ // but the struture of the server's frame writer makes this difficult.
82+
+ return nil, ConnectionError(ErrCodeProtocol)
83+
+ }
84+
+
85+
if _, err := hdec.Write(frag); err != nil {
86+
return nil, ConnectionError(ErrCodeCompression)
87+
}
88+
--
89+
2.33.8
90+

0 commit comments

Comments
 (0)