Skip to content

Commit 3272f2f

Browse files
nicogbgCBL-Mariner-Botanphel31jslobodzian
authored
[2.0] prometheus address CVE-2023-39325 CVE-2023-45288 (#10954)
Co-authored-by: CBL-Mariner Servicing Account <[email protected]> Co-authored-by: Andrew Phelps <[email protected]> Co-authored-by: jslobodzian <[email protected]>
1 parent 1de07b4 commit 3272f2f

File tree

3 files changed

+246
-2
lines changed

3 files changed

+246
-2
lines changed
Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
From 84b30b3380727ea94e05c438ab695ea24e38fb0c Mon Sep 17 00:00:00 2001
2+
From: Damien Neil <[email protected]>
3+
Date: Fri, 6 Oct 2023 09:51:19 -0700
4+
Subject: [PATCH] http2: limit maximum handler goroutines to
5+
MaxConcurrentStreams
6+
7+
When the peer opens a new stream while we have MaxConcurrentStreams
8+
handler goroutines running, defer starting a handler until one
9+
of the existing handlers exits.
10+
11+
Fixes golang/go#63417
12+
Fixes CVE-2023-39325
13+
14+
Change-Id: If0531e177b125700f3e24c5ebd24b1023098fa6d
15+
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go-private/+/2045854
16+
TryBot-Result: Security TryBots <[email protected]>
17+
Reviewed-by: Ian Cottrell <[email protected]>
18+
Reviewed-by: Tatiana Bradley <[email protected]>
19+
Run-TryBot: Damien Neil <[email protected]>
20+
Reviewed-on: https://go-review.googlesource.com/c/net/+/534215
21+
Reviewed-by: Michael Pratt <[email protected]>
22+
Reviewed-by: Dmitri Shuralyov <[email protected]>
23+
LUCI-TryBot-Result: Go LUCI <[email protected]>
24+
Auto-Submit: Dmitri Shuralyov <[email protected]>
25+
Reviewed-by: Damien Neil <[email protected]>
26+
27+
Modified to apply to vendored code by: Daniel McIlvaney <[email protected]>
28+
- Adjusted paths
29+
- Removed reference to server_test.go
30+
---
31+
.../vendor/golang.org/x/net/http2/server.go | 66 ++++++++++++++++++-
32+
1 file changed, 64 insertions(+), 2 deletions(-)
33+
34+
diff --git a/vendor/golang.org/x/net/http2/server.go b/vendor/golang.org/x/net/http2/server.go
35+
index 8cb14f3..6000140 100644
36+
--- a/vendor/golang.org/x/net/http2/server.go
37+
+++ b/vendor/golang.org/x/net/http2/server.go
38+
@@ -581,9 +581,11 @@ type serverConn struct {
39+
advMaxStreams uint32 // our SETTINGS_MAX_CONCURRENT_STREAMS advertised the client
40+
curClientStreams uint32 // number of open streams initiated by the client
41+
curPushedStreams uint32 // number of open streams initiated by server push
42+
+ curHandlers uint32 // number of running handler goroutines
43+
maxClientStreamID uint32 // max ever seen from client (odd), or 0 if there have been no client requests
44+
maxPushPromiseID uint32 // ID of the last push promise (even), or 0 if there have been no pushes
45+
streams map[uint32]*stream
46+
+ unstartedHandlers []unstartedHandler
47+
initialStreamSendWindowSize int32
48+
maxFrameSize int32
49+
peerMaxHeaderListSize uint32 // zero means unknown (default)
50+
@@ -981,6 +983,8 @@ func (sc *serverConn) serve() {
51+
return
52+
case gracefulShutdownMsg:
53+
sc.startGracefulShutdownInternal()
54+
+ case handlerDoneMsg:
55+
+ sc.handlerDone()
56+
default:
57+
panic("unknown timer")
58+
}
59+
@@ -1028,6 +1032,7 @@ var (
60+
idleTimerMsg = new(serverMessage)
61+
shutdownTimerMsg = new(serverMessage)
62+
gracefulShutdownMsg = new(serverMessage)
63+
+ handlerDoneMsg = new(serverMessage)
64+
)
65+
66+
func (sc *serverConn) onSettingsTimer() { sc.sendServeMsg(settingsTimerMsg) }
67+
@@ -2022,8 +2027,7 @@ func (sc *serverConn) processHeaders(f *MetaHeadersFrame) error {
68+
}
69+
}
70+
71+
- go sc.runHandler(rw, req, handler)
72+
- return nil
73+
+ return sc.scheduleHandler(id, rw, req, handler)
74+
}
75+
76+
func (sc *serverConn) upgradeRequest(req *http.Request) {
77+
@@ -2043,6 +2047,10 @@ func (sc *serverConn) upgradeRequest(req *http.Request) {
78+
sc.conn.SetReadDeadline(time.Time{})
79+
}
80+
81+
+ // This is the first request on the connection,
82+
+ // so start the handler directly rather than going
83+
+ // through scheduleHandler.
84+
+ sc.curHandlers++
85+
go sc.runHandler(rw, req, sc.handler.ServeHTTP)
86+
}
87+
88+
@@ -2283,8 +2291,62 @@ func (sc *serverConn) newResponseWriter(st *stream, req *http.Request) *response
89+
return &responseWriter{rws: rws}
90+
}
91+
92+
+type unstartedHandler struct {
93+
+ streamID uint32
94+
+ rw *responseWriter
95+
+ req *http.Request
96+
+ handler func(http.ResponseWriter, *http.Request)
97+
+}
98+
+
99+
+// scheduleHandler starts a handler goroutine,
100+
+// or schedules one to start as soon as an existing handler finishes.
101+
+func (sc *serverConn) scheduleHandler(streamID uint32, rw *responseWriter, req *http.Request, handler func(http.ResponseWriter, *http.Request)) error {
102+
+ sc.serveG.check()
103+
+ maxHandlers := sc.advMaxStreams
104+
+ if sc.curHandlers < maxHandlers {
105+
+ sc.curHandlers++
106+
+ go sc.runHandler(rw, req, handler)
107+
+ return nil
108+
+ }
109+
+ if len(sc.unstartedHandlers) > int(4*sc.advMaxStreams) {
110+
+ return sc.countError("too_many_early_resets", ConnectionError(ErrCodeEnhanceYourCalm))
111+
+ }
112+
+ sc.unstartedHandlers = append(sc.unstartedHandlers, unstartedHandler{
113+
+ streamID: streamID,
114+
+ rw: rw,
115+
+ req: req,
116+
+ handler: handler,
117+
+ })
118+
+ return nil
119+
+}
120+
+
121+
+func (sc *serverConn) handlerDone() {
122+
+ sc.serveG.check()
123+
+ sc.curHandlers--
124+
+ i := 0
125+
+ maxHandlers := sc.advMaxStreams
126+
+ for ; i < len(sc.unstartedHandlers); i++ {
127+
+ u := sc.unstartedHandlers[i]
128+
+ if sc.streams[u.streamID] == nil {
129+
+ // This stream was reset before its goroutine had a chance to start.
130+
+ continue
131+
+ }
132+
+ if sc.curHandlers >= maxHandlers {
133+
+ break
134+
+ }
135+
+ sc.curHandlers++
136+
+ go sc.runHandler(u.rw, u.req, u.handler)
137+
+ sc.unstartedHandlers[i] = unstartedHandler{} // don't retain references
138+
+ }
139+
+ sc.unstartedHandlers = sc.unstartedHandlers[i:]
140+
+ if len(sc.unstartedHandlers) == 0 {
141+
+ sc.unstartedHandlers = nil
142+
+ }
143+
+}
144+
+
145+
// Run on its own goroutine.
146+
func (sc *serverConn) runHandler(rw *responseWriter, req *http.Request, handler func(http.ResponseWriter, *http.Request)) {
147+
+ defer sc.sendServeMsg(handlerDoneMsg)
148+
didPanic := true
149+
defer func() {
150+
rw.rws.stream.cancelCtx()
151+
--
152+
2.33.8
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
From 87bba52321835fa92f7c91be1b8eef89a93d2506 Mon Sep 17 00:00:00 2001
2+
From: Damien Neil <[email protected]>
3+
Date: Wed, 10 Jan 2024 13:41:39 -0800
4+
Subject: [PATCH] http2: close connections when receiving too many headers
5+
6+
Maintaining HPACK state requires that we parse and process
7+
all HEADERS and CONTINUATION frames on a connection.
8+
When a request's headers exceed MaxHeaderBytes, we don't
9+
allocate memory to store the excess headers but we do
10+
parse them. This permits an attacker to cause an HTTP/2
11+
endpoint to read arbitrary amounts of data, all associated
12+
with a request which is going to be rejected.
13+
14+
Set a limit on the amount of excess header frames we
15+
will process before closing a connection.
16+
17+
Thanks to Bartek Nowotarski for reporting this issue.
18+
19+
Fixes CVE-2023-45288
20+
Fixes golang/go#65051
21+
22+
Change-Id: I15df097268df13bb5a9e9d3a5c04a8a141d850f6
23+
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go-private/+/2130527
24+
Reviewed-by: Roland Shoemaker <[email protected]>
25+
Reviewed-by: Tatiana Bradley <[email protected]>
26+
Reviewed-on: https://go-review.googlesource.com/c/net/+/576155
27+
Reviewed-by: Dmitri Shuralyov <[email protected]>
28+
Auto-Submit: Dmitri Shuralyov <[email protected]>
29+
Reviewed-by: Than McIntosh <[email protected]>
30+
LUCI-TryBot-Result: Go LUCI <[email protected]>
31+
---
32+
vendor/golang.org/x/net/http2/frame.go | 31 ++++++++++++++++++++++++++
33+
1 file changed, 31 insertions(+)
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 @@ func (fr *Framer) readMetaFrame(hf *HeadersFrame) (*MetaHeadersFrame, error) {
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 @@ func (fr *Framer) readMetaFrame(hf *HeadersFrame) (*MetaHeadersFrame, error) {
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+
}
84+
--
85+
2.44.0
86+

SPECS/prometheus/prometheus.spec

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
Summary: Prometheus monitoring system and time series database
55
Name: prometheus
66
Version: 2.37.9
7-
Release: 1%{?dist}
7+
Release: 2%{?dist}
88
License: Apache-2.0
99
Vendor: Microsoft Corporation
1010
Distribution: Mariner
@@ -20,6 +20,8 @@ Source6: promu-%{promu_version}.tar.gz
2020
Patch0: 02-Default_settings.patch
2121
Patch1: CVE-2024-6104.patch
2222
Patch2: CVE-2024-24786.patch
23+
Patch3: CVE-2023-39325.patch
24+
Patch4: CVE-2023-45288.patch
2325
BuildRequires: golang
2426
BuildRequires: nodejs
2527
BuildRequires: systemd-rpm-macros
@@ -133,7 +135,11 @@ fi
133135
%doc README.md RELEASE.md documentation
134136

135137
%changelog
136-
* Tue Oct 08 2024 Bhagyashri Pathak <[email protected]> - 2.37.0-16
138+
* Wed Nov 06 2024 Nicolas Guibourge <[email protected]> - 2.37.9-2
139+
- Patch for CVE-2023-39325 CVE-2023-45288
140+
- Fix previous changelog version number
141+
142+
* Tue Oct 08 2024 Bhagyashri Pathak <[email protected]> - 2.37.9-1
137143
- Bump version to patch CVE-2022-41717
138144
- Patch for CVE-2024-24786
139145

0 commit comments

Comments
 (0)