summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHitendra Prajapati <hprajapati@mvista.com>2025-04-11 11:46:18 +0530
committerSteve Sakoman <steve@sakoman.com>2025-04-18 08:30:51 -0700
commit0a3231570d7ac206d022c455fb8e8e1f8db6f1d5 (patch)
treea904af55079b3dd20a26aaa1467df16870b0e2fb
parent408aeb7aae7e39efc7fc99f29e1c7366d3c1890d (diff)
downloadpoky-0a3231570d7ac206d022c455fb8e8e1f8db6f1d5.tar.gz
go: fix CVE-2025-22871
Upstream-Status: Backport from https://github.com/golang/go/commit/15e01a2e43ecb8c7e15ff7e9d62fe3f10dcac931 (From OE-Core rev: 2a9f47eb507cf57b58c4aa1baf0ef645b699fd6c) Signed-off-by: Hitendra Prajapati <hprajapati@mvista.com> Signed-off-by: Steve Sakoman <steve@sakoman.com>
-rw-r--r--meta/recipes-devtools/go/go-1.17.13.inc1
-rw-r--r--meta/recipes-devtools/go/go-1.21/CVE-2025-22871.patch172
2 files changed, 173 insertions, 0 deletions
diff --git a/meta/recipes-devtools/go/go-1.17.13.inc b/meta/recipes-devtools/go/go-1.17.13.inc
index 34ad70572f..e54205d48c 100644
--- a/meta/recipes-devtools/go/go-1.17.13.inc
+++ b/meta/recipes-devtools/go/go-1.17.13.inc
@@ -62,6 +62,7 @@ SRC_URI += "\
62 file://CVE-2024-34156.patch \ 62 file://CVE-2024-34156.patch \
63 file://CVE-2024-34158.patch \ 63 file://CVE-2024-34158.patch \
64 file://CVE-2024-45336.patch \ 64 file://CVE-2024-45336.patch \
65 file://CVE-2025-22871.patch \
65" 66"
66SRC_URI[main.sha256sum] = "a1a48b23afb206f95e7bbaa9b898d965f90826f6f1d1fc0c1d784ada0cd300fd" 67SRC_URI[main.sha256sum] = "a1a48b23afb206f95e7bbaa9b898d965f90826f6f1d1fc0c1d784ada0cd300fd"
67 68
diff --git a/meta/recipes-devtools/go/go-1.21/CVE-2025-22871.patch b/meta/recipes-devtools/go/go-1.21/CVE-2025-22871.patch
new file mode 100644
index 0000000000..06e0fa77de
--- /dev/null
+++ b/meta/recipes-devtools/go/go-1.21/CVE-2025-22871.patch
@@ -0,0 +1,172 @@
1From 15e01a2e43ecb8c7e15ff7e9d62fe3f10dcac931 Mon Sep 17 00:00:00 2001
2From: Damien Neil <dneil@google.com>
3Date: Wed, 26 Feb 2025 13:40:00 -0800
4Subject: [PATCH] [release-branch.go1.23] net/http: reject newlines in
5 chunk-size lines
6
7Unlike request headers, where we are allowed to leniently accept
8a bare LF in place of a CRLF, chunked bodies must always use CRLF
9line terminators. We were already enforcing this for chunk-data lines;
10do so for chunk-size lines as well. Also reject bare CRs anywhere
11other than as part of the CRLF terminator.
12
13Fixes CVE-2025-22871
14Fixes #72010
15For #71988
16
17Change-Id: Ib0e21af5a8ba28c2a1ca52b72af8e2265ec79e4a
18Reviewed-on: https://go-review.googlesource.com/c/go/+/652998
19Reviewed-by: Jonathan Amsterdam <jba@google.com>
20LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
21(cherry picked from commit d31c805535f3fde95646ee4d87636aaaea66847b)
22Reviewed-on: https://go-review.googlesource.com/c/go/+/657216
23
24Upstream-Status: Backport [https://github.com/golang/go/commit/15e01a2e43ecb8c7e15ff7e9d62fe3f10dcac931]
25CVE: CVE-2025-22871
26Signed-off-by: Hitendra Prajapati <hprajapati@mvista.com>
27---
28 src/net/http/internal/chunked.go | 19 +++++++++--
29 src/net/http/internal/chunked_test.go | 27 +++++++++++++++
30 src/net/http/serve_test.go | 49 +++++++++++++++++++++++++++
31 3 files changed, 92 insertions(+), 3 deletions(-)
32
33diff --git a/src/net/http/internal/chunked.go b/src/net/http/internal/chunked.go
34index ddbaacb..dd79afc 100644
35--- a/src/net/http/internal/chunked.go
36+++ b/src/net/http/internal/chunked.go
37@@ -159,6 +159,19 @@ func readChunkLine(b *bufio.Reader) ([]byte, error) {
38 }
39 return nil, err
40 }
41+
42+ // RFC 9112 permits parsers to accept a bare \n as a line ending in headers,
43+ // but not in chunked encoding lines. See https://www.rfc-editor.org/errata/eid7633,
44+ // which explicitly rejects a clarification permitting \n as a chunk terminator.
45+ //
46+ // Verify that the line ends in a CRLF, and that no CRs appear before the end.
47+ if idx := bytes.IndexByte(p, '\r'); idx == -1 {
48+ return nil, errors.New("chunked line ends with bare LF")
49+ } else if idx != len(p)-2 {
50+ return nil, errors.New("invalid CR in chunked line")
51+ }
52+ p = p[:len(p)-2] // trim CRLF
53+
54 if len(p) >= maxLineLength {
55 return nil, ErrLineTooLong
56 }
57@@ -166,14 +179,14 @@ func readChunkLine(b *bufio.Reader) ([]byte, error) {
58 }
59
60 func trimTrailingWhitespace(b []byte) []byte {
61- for len(b) > 0 && isASCIISpace(b[len(b)-1]) {
62+ for len(b) > 0 && isOWS(b[len(b)-1]) {
63 b = b[:len(b)-1]
64 }
65 return b
66 }
67
68-func isASCIISpace(b byte) bool {
69- return b == ' ' || b == '\t' || b == '\n' || b == '\r'
70+func isOWS(b byte) bool {
71+ return b == ' ' || b == '\t'
72 }
73
74 // removeChunkExtension removes any chunk-extension from p.
75diff --git a/src/net/http/internal/chunked_test.go b/src/net/http/internal/chunked_test.go
76index 5fbeb08..51ecd62 100644
77--- a/src/net/http/internal/chunked_test.go
78+++ b/src/net/http/internal/chunked_test.go
79@@ -251,6 +251,33 @@ func TestChunkReaderByteAtATime(t *testing.T) {
80 }
81 }
82
83+func TestChunkInvalidInputs(t *testing.T) {
84+ for _, test := range []struct {
85+ name string
86+ b string
87+ }{{
88+ name: "bare LF in chunk size",
89+ b: "1\na\r\n0\r\n",
90+ }, {
91+ name: "extra LF in chunk size",
92+ b: "1\r\r\na\r\n0\r\n",
93+ }, {
94+ name: "bare LF in chunk data",
95+ b: "1\r\na\n0\r\n",
96+ }, {
97+ name: "bare LF in chunk extension",
98+ b: "1;\na\r\n0\r\n",
99+ }} {
100+ t.Run(test.name, func(t *testing.T) {
101+ r := NewChunkedReader(strings.NewReader(test.b))
102+ got, err := io.ReadAll(r)
103+ if err == nil {
104+ t.Fatalf("unexpectedly parsed invalid chunked data:\n%q", got)
105+ }
106+ })
107+ }
108+}
109+
110 type funcReader struct {
111 f func(iteration int) ([]byte, error)
112 i int
113diff --git a/src/net/http/serve_test.go b/src/net/http/serve_test.go
114index bfac783..944cd46 100644
115--- a/src/net/http/serve_test.go
116+++ b/src/net/http/serve_test.go
117@@ -6610,3 +6610,52 @@ func testQuerySemicolon(t *testing.T, query string, wantX string, allowSemicolon
118 }
119 }
120 }
121+
122+func TestInvalidChunkedBodies(t *testing.T) {
123+ for _, test := range []struct {
124+ name string
125+ b string
126+ }{{
127+ name: "bare LF in chunk size",
128+ b: "1\na\r\n0\r\n\r\n",
129+ }, {
130+ name: "bare LF at body end",
131+ b: "1\r\na\r\n0\r\n\n",
132+ }} {
133+ t.Run(test.name, func(t *testing.T) {
134+ reqc := make(chan error)
135+ ts := newClientServerTest(t, http1Mode, HandlerFunc(func(w ResponseWriter, r *Request) {
136+ got, err := io.ReadAll(r.Body)
137+ if err == nil {
138+ t.Logf("read body: %q", got)
139+ }
140+ reqc <- err
141+ })).ts
142+
143+ serverURL, err := url.Parse(ts.URL)
144+ if err != nil {
145+ t.Fatal(err)
146+ }
147+
148+ conn, err := net.Dial("tcp", serverURL.Host)
149+ if err != nil {
150+ t.Fatal(err)
151+ }
152+
153+ if _, err := conn.Write([]byte(
154+ "POST / HTTP/1.1\r\n" +
155+ "Host: localhost\r\n" +
156+ "Transfer-Encoding: chunked\r\n" +
157+ "Connection: close\r\n" +
158+ "\r\n" +
159+ test.b)); err != nil {
160+ t.Fatal(err)
161+ }
162+ conn.(*net.TCPConn).CloseWrite()
163+
164+ if err := <-reqc; err == nil {
165+ t.Errorf("server handler: io.ReadAll(r.Body) succeeded, want error")
166+ }
167+ })
168+ }
169+}
170--
1712.25.1
172