Skip to content

Commit aaac8a4

Browse files
CBL-Mariner-BotdmcilvaneyPawelWMS
authored
[AUTO-CHERRYPICK] Patch CVE-2023-44487 in vendored golang - branch main (#7804)
Co-authored-by: Daniel McIlvaney <damcilva@microsoft.com> Co-authored-by: Pawel Winogrodzki <pawelwi@microsoft.com>
1 parent 589ef81 commit aaac8a4

44 files changed

Lines changed: 3002 additions & 116 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

SPECS/application-gateway-kubernetes-ingress/CVE-2022-21698.patch

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ Differences:
99
- Removed some comments that don't merge
1010
- Line numbers and such
1111

12+
Modified to apply to vendored code by: Daniel McIlvaney <damcilva@microsoft.com>
13+
- Adjusted paths to work for vendored version
14+
1215
Based on:
1316

1417
From 9075cdf61646b5adf54d3ba77a0e4f6c65cb4fd7 Mon Sep 17 00:00:00 2001
@@ -37,16 +40,16 @@ Signed-off-by: Kemal Akkoyun <kakkoyun@gmail.com>
3740

3841
Signed-off-by: Kemal Akkoyun <kakkoyun@gmail.com>
3942
---
40-
prometheus/promhttp/instrument_client.go | 28 ++++++--
41-
prometheus/promhttp/instrument_server.go | 82 ++++++++++++++++++------
42-
prometheus/promhttp/option.go | 31 +++++++++
43+
vendor/github.com/prometheus/client_golang/prometheus/promhttp/instrument_client.go | 28 ++++++--
44+
vendor/github.com/prometheus/client_golang/prometheus/promhttp/instrument_server.go | 82 ++++++++++++++++++------
45+
vendor/github.com/prometheus/client_golang/prometheus/promhttp/option.go | 31 +++++++++
4346
3 files changed, 116 insertions(+), 25 deletions(-)
44-
create mode 100644 prometheus/promhttp/option.go
47+
create mode 100644 vendor/github.com/prometheus/client_golang/prometheus/promhttp/option.go
4548

46-
diff --git a/prometheus/promhttp/instrument_client.go b/prometheus/promhttp/instrument_client.go
49+
diff --git a/vendor/github.com/prometheus/client_golang/prometheus/promhttp/instrument_client.go b/vendor/github.com/prometheus/client_golang/prometheus/promhttp/instrument_client.go
4750
index 83c49b6..861b4d2 100644
48-
--- a/prometheus/promhttp/instrument_client.go
49-
+++ b/prometheus/promhttp/instrument_client.go
51+
--- a/vendor/github.com/prometheus/client_golang/prometheus/promhttp/instrument_client.go
52+
+++ b/vendor/github.com/prometheus/client_golang/prometheus/promhttp/instrument_client.go
5053
@@ -49,7 +49,10 @@ func InstrumentRoundTripperInFlight(gauge prometheus.Gauge, next http.RoundTripp
5154
// http.RoundTripper to observe the request result with the provided CounterVec.
5255
// The CounterVec must have zero, one, or two non-const non-curried labels. For
@@ -114,10 +117,10 @@ index 83c49b6..861b4d2 100644
114117
}
115118
return resp, err
116119
})
117-
diff --git a/prometheus/promhttp/instrument_server.go b/prometheus/promhttp/instrument_server.go
120+
diff --git a/vendor/github.com/prometheus/client_golang/prometheus/promhttp/instrument_server.go b/vendor/github.com/prometheus/client_golang/prometheus/promhttp/instrument_server.go
118121
index 9db2438..91802f8 100644
119-
--- a/prometheus/promhttp/instrument_server.go
120-
+++ b/prometheus/promhttp/instrument_server.go
122+
--- a/vendor/github.com/prometheus/client_golang/prometheus/promhttp/instrument_server.go
123+
+++ b/vendor/github.com/prometheus/client_golang/prometheus/promhttp/instrument_server.go
121124
@@ -58,7 +58,12 @@ func InstrumentHandlerInFlight(g prometheus.Gauge, next http.Handler) http.Handl
122125
//
123126
// Note that this method is only guaranteed to never observe negative durations
@@ -322,11 +325,11 @@ index 9db2438..91802f8 100644
322325
+ return "unknown"
323326
}
324327
}
325-
diff --git a/prometheus/promhttp/option.go b/prometheus/promhttp/option.go
328+
diff --git a/vendor/github.com/prometheus/client_golang/prometheus/promhttp/option.go b/vendor/github.com/prometheus/client_golang/prometheus/promhttp/option.go
326329
new file mode 100644
327330
index 0000000..35e41bd
328331
--- /dev/null
329-
+++ b/prometheus/promhttp/option.go
332+
+++ b/vendor/github.com/prometheus/client_golang/prometheus/promhttp/option.go
330333
@@ -0,0 +1,31 @@
331334
+// Copyright 2022 The Prometheus Authors
332335
+// Licensed under the Apache License, Version 2.0 (the "License");
Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
From 6e577d297aa8b47651c1a5c3ebfbf3f2d769be96 Mon Sep 17 00:00:00 2001
2+
From: Damien Neil <dneil@google.com>
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 <security-trybots@go-security-trybots.iam.gserviceaccount.com>
17+
Reviewed-by: Ian Cottrell <iancottrell@google.com>
18+
Reviewed-by: Tatiana Bradley <tatianabradley@google.com>
19+
Run-TryBot: Damien Neil <dneil@google.com>
20+
Reviewed-on: https://go-review.googlesource.com/c/net/+/534215
21+
Reviewed-by: Michael Pratt <mpratt@google.com>
22+
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
23+
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
24+
Auto-Submit: Dmitri Shuralyov <dmitshur@golang.org>
25+
Reviewed-by: Damien Neil <dneil@google.com>
26+
27+
Modified to apply to vendored code by: Daniel McIlvaney <damcilva@microsoft.com>
28+
- Adjusted paths
29+
- Removed reference to server_test.go
30+
- Removed reference to upgradeRequest() which is not in old versions of the vendored code
31+
- Removed reference to countError() which is not in old versions of the vendored code
32+
---
33+
vendor/golang.org/x/net/http2/server.go | 62 ++++++++++++++++++++++++-
34+
1 file changed, 60 insertions(+), 2 deletions(-)
35+
36+
diff --git a/vendor/golang.org/x/net/http2/server.go b/vendor/golang.org/x/net/http2/server.go
37+
index de31d72..daa01a7 100644
38+
--- a/vendor/golang.org/x/net/http2/server.go
39+
+++ b/vendor/golang.org/x/net/http2/server.go
40+
@@ -521,9 +521,11 @@ type serverConn struct {
41+
advMaxStreams uint32 // our SETTINGS_MAX_CONCURRENT_STREAMS advertised the client
42+
curClientStreams uint32 // number of open streams initiated by the client
43+
curPushedStreams uint32 // number of open streams initiated by server push
44+
+ curHandlers uint32 // number of running handler goroutines
45+
maxClientStreamID uint32 // max ever seen from client (odd), or 0 if there have been no client requests
46+
maxPushPromiseID uint32 // ID of the last push promise (even), or 0 if there have been no pushes
47+
streams map[uint32]*stream
48+
+ unstartedHandlers []unstartedHandler
49+
initialStreamSendWindowSize int32
50+
maxFrameSize int32
51+
headerTableSize uint32
52+
@@ -895,6 +897,8 @@ func (sc *serverConn) serve() {
53+
return
54+
case gracefulShutdownMsg:
55+
sc.startGracefulShutdownInternal()
56+
+ case handlerDoneMsg:
57+
+ sc.handlerDone()
58+
default:
59+
panic("unknown timer")
60+
}
61+
@@ -940,6 +944,7 @@ var (
62+
idleTimerMsg = new(serverMessage)
63+
shutdownTimerMsg = new(serverMessage)
64+
gracefulShutdownMsg = new(serverMessage)
65+
+ handlerDoneMsg = new(serverMessage)
66+
)
67+
68+
func (sc *serverConn) onSettingsTimer() { sc.sendServeMsg(settingsTimerMsg) }
69+
@@ -1880,8 +1885,7 @@ func (sc *serverConn) processHeaders(f *MetaHeadersFrame) error {
70+
sc.conn.SetReadDeadline(time.Time{})
71+
}
72+
73+
- go sc.runHandler(rw, req, handler)
74+
- return nil
75+
+ return sc.scheduleHandler(id, rw, req, handler)
76+
}
77+
78+
func (st *stream) processTrailerHeaders(f *MetaHeadersFrame) error {
79+
@@ -2124,8 +2128,62 @@ func (sc *serverConn) newWriterAndRequestNoBody(st *stream, rp requestParam) (*r
80+
return rw, req, nil
81+
}
82+
83+
+type unstartedHandler struct {
84+
+ streamID uint32
85+
+ rw *responseWriter
86+
+ req *http.Request
87+
+ handler func(http.ResponseWriter, *http.Request)
88+
+}
89+
+
90+
+// scheduleHandler starts a handler goroutine,
91+
+// or schedules one to start as soon as an existing handler finishes.
92+
+func (sc *serverConn) scheduleHandler(streamID uint32, rw *responseWriter, req *http.Request, handler func(http.ResponseWriter, *http.Request)) error {
93+
+ sc.serveG.check()
94+
+ maxHandlers := sc.advMaxStreams
95+
+ if sc.curHandlers < maxHandlers {
96+
+ sc.curHandlers++
97+
+ go sc.runHandler(rw, req, handler)
98+
+ return nil
99+
+ }
100+
+ if len(sc.unstartedHandlers) > int(4*sc.advMaxStreams) {
101+
+ return ConnectionError(ErrCodeEnhanceYourCalm)
102+
+ }
103+
+ sc.unstartedHandlers = append(sc.unstartedHandlers, unstartedHandler{
104+
+ streamID: streamID,
105+
+ rw: rw,
106+
+ req: req,
107+
+ handler: handler,
108+
+ })
109+
+ return nil
110+
+}
111+
+
112+
+func (sc *serverConn) handlerDone() {
113+
+ sc.serveG.check()
114+
+ sc.curHandlers--
115+
+ i := 0
116+
+ maxHandlers := sc.advMaxStreams
117+
+ for ; i < len(sc.unstartedHandlers); i++ {
118+
+ u := sc.unstartedHandlers[i]
119+
+ if sc.streams[u.streamID] == nil {
120+
+ // This stream was reset before its goroutine had a chance to start.
121+
+ continue
122+
+ }
123+
+ if sc.curHandlers >= maxHandlers {
124+
+ break
125+
+ }
126+
+ sc.curHandlers++
127+
+ go sc.runHandler(u.rw, u.req, u.handler)
128+
+ sc.unstartedHandlers[i] = unstartedHandler{} // don't retain references
129+
+ }
130+
+ sc.unstartedHandlers = sc.unstartedHandlers[i:]
131+
+ if len(sc.unstartedHandlers) == 0 {
132+
+ sc.unstartedHandlers = nil
133+
+ }
134+
+}
135+
+
136+
// Run on its own goroutine.
137+
func (sc *serverConn) runHandler(rw *responseWriter, req *http.Request, handler func(http.ResponseWriter, *http.Request)) {
138+
+ defer sc.sendServeMsg(handlerDoneMsg)
139+
didPanic := true
140+
defer func() {
141+
rw.rws.stream.cancelCtx()
142+
--
143+
2.33.8

SPECS/application-gateway-kubernetes-ingress/application-gateway-kubernetes-ingress.spec

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
Summary: Application Gateway Ingress Controller
33
Name: application-gateway-kubernetes-ingress
44
Version: 1.4.0
5-
Release: 17%{?dist}
5+
Release: 18%{?dist}
66
License: MIT
77
Vendor: Microsoft Corporation
88
Distribution: Mariner
@@ -26,35 +26,48 @@ Source0: %{name}-%{version}.tar.gz
2626
Source1: %{name}-%{version}-vendor.tar.gz
2727
# If upstream ever upgrades client_goland to 1.11.1, we can get rid of this patch.
2828
Patch0: CVE-2022-21698.patch
29+
Patch1: CVE-2023-44487.patch
2930
BuildRequires: golang >= 1.13
31+
%if %{with_check}
32+
BuildRequires: helm
33+
%endif
3034

3135
%description
32-
This is an ingress controller that can be run on Azure Kubernetes Service (AKS) to allow an Azure Application Gateway
33-
to act as the ingress for an AKS cluster.
36+
This is an ingress controller that can be run on Azure Kubernetes Service (AKS) to allow an Azure Application Gateway
37+
to act as the ingress for an AKS cluster.
3438

3539
%prep
3640
%autosetup -N
3741
rm -rf vendor
3842
tar -xf %{SOURCE1} --no-same-owner
39-
%patch 0 -p1 -d vendor/github.com/prometheus/client_golang
43+
%autopatch -p1
4044

4145
%build
4246
export VERSION=%{version}
4347
export VERSION_PATH=github.com/Azure/application-gateway-kubernetes-ingress/pkg/version
4448

4549
go build -ldflags "-s -X $VERSION_PATH.Version=$VERSION" -mod=vendor -v -o appgw-ingress ./cmd/appgw-ingress
4650

51+
%check
52+
export VERSION=%{version}
53+
export VERSION_PATH=github.com/Azure/application-gateway-kubernetes-ingress/pkg/version
54+
# Helm chart generation is slightly off, skip these tests
55+
go test -ldflags "-s -X $VERSION_PATH.Version=$VERSION" -mod=vendor -v -tags unittest -skip 'TestChart' ./...
56+
4757
%install
4858
mkdir -p %{buildroot}%{_bindir}
4959
cp appgw-ingress %{buildroot}%{_bindir}/
5060

51-
5261
%files
5362
%defattr(-,root,root)
5463
%license LICENSE
5564
%{_bindir}/appgw-ingress
5665

5766
%changelog
67+
* Thu Feb 01 2024 Daniel McIlvaney <damcilva@microsoft.com> - 1.4.0-18
68+
- Address CVE-2023-44487 by patching vendored golang.org/x/net
69+
- Add check section
70+
5871
* Mon Jan 01 2024 Tobias Brick <tobiasb@microsoft.com> - 1.4.0-17
5972
- Patch for CVE-2022-21698
6073
- Moved vendored tarball extraction into %prep and changed from %autosetup to %setup

0 commit comments

Comments
 (0)