Skip to content

Commit cbc750f

Browse files
Kanishk-Bansalsameluch
authored andcommitted
Patch CVE-2024-28180, CVE-2023-45288 for moby-containerd-cc [High] (#12169)
Co-authored-by: Sam Meluch <[email protected]>
1 parent 468a249 commit cbc750f

File tree

3 files changed

+177
-1
lines changed

3 files changed

+177
-1
lines changed
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
Author: Damien Neil <[email protected]>
2+
AuthorDate: 2024-01-10 13:41:39 -0800
3+
Commit: Gopher Robot <[email protected]>
4+
CommitDate: 2024-04-03 17:06:00 +0000
5+
6+
[internal-branch.go1.21-vendor] http2: close connections when receiving too many headers
7+
8+
Maintaining HPACK state requires that we parse and process
9+
all HEADERS and CONTINUATION frames on a connection.
10+
When a request's headers exceed MaxHeaderBytes, we don't
11+
allocate memory to store the excess headers but we do
12+
parse them. This permits an attacker to cause an HTTP/2
13+
endpoint to read arbitrary amounts of data, all associated
14+
with a request which is going to be rejected.
15+
16+
Set a limit on the amount of excess header frames we
17+
will process before closing a connection.
18+
19+
Thanks to Bartek Nowotarski for reporting this issue.
20+
21+
Fixes CVE-2023-45288
22+
For golang/go#65051
23+
24+
Change-Id: I15df097268df13bb5a9e9d3a5c04a8a141d850f6
25+
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go-private/+/2130527
26+
Reviewed-by: Roland Shoemaker <[email protected]>
27+
Reviewed-by: Tatiana Bradley <[email protected]>
28+
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go-private/+/2197243
29+
Run-TryBot: Damien Neil <[email protected]>
30+
Reviewed-by: Dmitri Shuralyov <[email protected]>
31+
Reviewed-on: https://go-review.googlesource.com/c/net/+/576057
32+
LUCI-TryBot-Result: Go LUCI <[email protected]>
33+
Auto-Submit: Dmitri Shuralyov <[email protected]>
34+
35+
diff --git a/vendor/golang.org/x/net/http2/frame.go b/vendor/golang.org/x/net/http2/frame.go
36+
index c1f6b90..175c154 100644
37+
--- a/vendor/golang.org/x/net/http2/frame.go
38+
+++ b/vendor/golang.org/x/net/http2/frame.go
39+
@@ -1565,6 +1565,7 @@
40+
if size > remainSize {
41+
hdec.SetEmitEnabled(false)
42+
mh.Truncated = true
43+
+ remainSize = 0
44+
return
45+
}
46+
remainSize -= size
47+
@@ -1577,6 +1578,36 @@
48+
var hc headersOrContinuation = hf
49+
for {
50+
frag := hc.HeaderBlockFragment()
51+
+
52+
+ // Avoid parsing large amounts of headers that we will then discard.
53+
+ // If the sender exceeds the max header list size by too much,
54+
+ // skip parsing the fragment and close the connection.
55+
+ //
56+
+ // "Too much" is either any CONTINUATION frame after we've already
57+
+ // exceeded the max header list size (in which case remainSize is 0),
58+
+ // or a frame whose encoded size is more than twice the remaining
59+
+ // header list bytes we're willing to accept.
60+
+ if int64(len(frag)) > int64(2*remainSize) {
61+
+ if VerboseLogs {
62+
+ log.Printf("http2: header list too large")
63+
+ }
64+
+ // It would be nice to send a RST_STREAM before sending the GOAWAY,
65+
+ // but the struture of the server's frame writer makes this difficult.
66+
+ return nil, ConnectionError(ErrCodeProtocol)
67+
+ }
68+
+
69+
+ // Also close the connection after any CONTINUATION frame following an
70+
+ // invalid header, since we stop tracking the size of the headers after
71+
+ // an invalid one.
72+
+ if invalid != nil {
73+
+ if VerboseLogs {
74+
+ log.Printf("http2: invalid header: %v", invalid)
75+
+ }
76+
+ // It would be nice to send a RST_STREAM before sending the GOAWAY,
77+
+ // but the struture of the server's frame writer makes this difficult.
78+
+ return nil, ConnectionError(ErrCodeProtocol)
79+
+ }
80+
+
81+
if _, err := hdec.Write(frag); err != nil {
82+
return nil, ConnectionError(ErrCodeCompression)
83+
}
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
From 4a3082f33a489334e1d3075843905ca5b8dd6e4a Mon Sep 17 00:00:00 2001
2+
From: Kanishk Bansal <[email protected]>
3+
Date: Fri, 31 Jan 2025 12:58:34 +0000
4+
Subject: [PATCH] Address CVE-2024-28180 for packer
5+
6+
---
7+
vendor/gopkg.in/square/go-jose.v2/crypter.go | 6 ++++++
8+
vendor/gopkg.in/square/go-jose.v2/encoding.go | 20 +++++++++++++++----
9+
2 files changed, 22 insertions(+), 4 deletions(-)
10+
11+
diff --git a/vendor/gopkg.in/square/go-jose.v2/crypter.go b/vendor/gopkg.in/square/go-jose.v2/crypter.go
12+
index d24cabf..a628386 100644
13+
--- a/vendor/gopkg.in/square/go-jose.v2/crypter.go
14+
+++ b/vendor/gopkg.in/square/go-jose.v2/crypter.go
15+
@@ -405,6 +405,9 @@ func (ctx *genericEncrypter) Options() EncrypterOptions {
16+
// Decrypt and validate the object and return the plaintext. Note that this
17+
// function does not support multi-recipient, if you desire multi-recipient
18+
// decryption use DecryptMulti instead.
19+
+//
20+
+// Automatically decompresses plaintext, but returns an error if the decompressed
21+
+// data would be >250kB or >10x the size of the compressed data, whichever is larger.
22+
func (obj JSONWebEncryption) Decrypt(decryptionKey interface{}) ([]byte, error) {
23+
headers := obj.mergedHeaders(nil)
24+
25+
@@ -469,6 +472,9 @@ func (obj JSONWebEncryption) Decrypt(decryptionKey interface{}) ([]byte, error)
26+
// with support for multiple recipients. It returns the index of the recipient
27+
// for which the decryption was successful, the merged headers for that recipient,
28+
// and the plaintext.
29+
+//
30+
+// Automatically decompresses plaintext, but returns an error if the decompressed
31+
+// data would be >250kB or >3x the size of the compressed data, whichever is larger.
32+
func (obj JSONWebEncryption) DecryptMulti(decryptionKey interface{}) (int, Header, []byte, error) {
33+
globalHeaders := obj.mergedHeaders(nil)
34+
35+
diff --git a/vendor/gopkg.in/square/go-jose.v2/encoding.go b/vendor/gopkg.in/square/go-jose.v2/encoding.go
36+
index 70f7385..2b92116 100644
37+
--- a/vendor/gopkg.in/square/go-jose.v2/encoding.go
38+
+++ b/vendor/gopkg.in/square/go-jose.v2/encoding.go
39+
@@ -21,6 +21,7 @@ import (
40+
"compress/flate"
41+
"encoding/base64"
42+
"encoding/binary"
43+
+ "fmt"
44+
"io"
45+
"math/big"
46+
"strings"
47+
@@ -85,7 +86,7 @@ func decompress(algorithm CompressionAlgorithm, input []byte) ([]byte, error) {
48+
}
49+
}
50+
51+
-// Compress with DEFLATE
52+
+// deflate compresses the input.
53+
func deflate(input []byte) ([]byte, error) {
54+
output := new(bytes.Buffer)
55+
56+
@@ -97,15 +98,26 @@ func deflate(input []byte) ([]byte, error) {
57+
return output.Bytes(), err
58+
}
59+
60+
-// Decompress with DEFLATE
61+
+// inflate decompresses the input.
62+
+//
63+
+// Errors if the decompressed data would be >250kB or >10x the size of the
64+
+// compressed data, whichever is larger.
65+
func inflate(input []byte) ([]byte, error) {
66+
output := new(bytes.Buffer)
67+
reader := flate.NewReader(bytes.NewBuffer(input))
68+
69+
- _, err := io.Copy(output, reader)
70+
- if err != nil {
71+
+ maxCompressedSize := 10 * int64(len(input))
72+
+ if maxCompressedSize < 250000 {
73+
+ maxCompressedSize = 250000
74+
+ }
75+
+ limit := maxCompressedSize + 1
76+
+ n, err := io.CopyN(output, reader, limit)
77+
+ if err != nil && err != io.EOF {
78+
return nil, err
79+
}
80+
+ if n == limit {
81+
+ return nil, fmt.Errorf("uncompressed data would be too large (>%d bytes)", maxCompressedSize)
82+
+ }
83+
84+
err = reader.Close()
85+
return output.Bytes(), err
86+
--
87+
2.43.0
88+

SPECS/moby-containerd-cc/moby-containerd-cc.spec

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
Summary: Industry-standard container runtime for confidential containers
77
Name: moby-%{upstream_name}
88
Version: 1.7.7
9-
Release: 5%{?dist}
9+
Release: 6%{?dist}
1010
License: ASL 2.0
1111
Group: Tools/Container
1212
URL: https://www.containerd.io
@@ -20,6 +20,8 @@ Patch0: CVE-2023-47108.patch
2020
Patch1: CVE-2023-44487.patch
2121
Patch2: fix_cc_tests_for_golang1.21.patch
2222
Patch3: CVE-2024-24786.patch
23+
Patch4: CVE-2024-28180.patch
24+
Patch5: CVE-2023-45288.patch
2325

2426
%{?systemd_requires}
2527

@@ -77,6 +79,9 @@ fi
7779
%config(noreplace) %{_sysconfdir}/containerd/config.toml
7880

7981
%changelog
82+
* Fri Jan 31 2025 Kanishk Bansal <[email protected]> - 1.7.7-6
83+
- Address CVE-2024-28180, CVE-2023-45288
84+
8085
* Mon Nov 25 2024 Bala <[email protected]> - 1.7.7-5
8186
- Fix CVE-2024-24786 by patching
8287

0 commit comments

Comments
 (0)