diff options
| -rw-r--r-- | meta/recipes-devtools/go/go-1.22.12.inc | 1 | ||||
| -rw-r--r-- | meta/recipes-devtools/go/go/CVE-2025-22871.patch | 172 |
2 files changed, 173 insertions, 0 deletions
diff --git a/meta/recipes-devtools/go/go-1.22.12.inc b/meta/recipes-devtools/go/go-1.22.12.inc index df77794506..b154aa3984 100644 --- a/meta/recipes-devtools/go/go-1.22.12.inc +++ b/meta/recipes-devtools/go/go-1.22.12.inc | |||
| @@ -15,5 +15,6 @@ SRC_URI += "\ | |||
| 15 | file://0008-src-cmd-dist-buildgo.go-do-not-hardcode-host-compile.patch \ | 15 | file://0008-src-cmd-dist-buildgo.go-do-not-hardcode-host-compile.patch \ |
| 16 | file://0009-go-Filter-build-paths-on-staticly-linked-arches.patch \ | 16 | file://0009-go-Filter-build-paths-on-staticly-linked-arches.patch \ |
| 17 | file://CVE-2025-22870.patch \ | 17 | file://CVE-2025-22870.patch \ |
| 18 | file://CVE-2025-22871.patch \ | ||
| 18 | " | 19 | " |
| 19 | SRC_URI[main.sha256sum] = "012a7e1f37f362c0918c1dfa3334458ac2da1628c4b9cf4d9ca02db986e17d71" | 20 | SRC_URI[main.sha256sum] = "012a7e1f37f362c0918c1dfa3334458ac2da1628c4b9cf4d9ca02db986e17d71" |
diff --git a/meta/recipes-devtools/go/go/CVE-2025-22871.patch b/meta/recipes-devtools/go/go/CVE-2025-22871.patch new file mode 100644 index 0000000000..2750178a42 --- /dev/null +++ b/meta/recipes-devtools/go/go/CVE-2025-22871.patch | |||
| @@ -0,0 +1,172 @@ | |||
| 1 | From 15e01a2e43ecb8c7e15ff7e9d62fe3f10dcac931 Mon Sep 17 00:00:00 2001 | ||
| 2 | From: Damien Neil <dneil@google.com> | ||
| 3 | Date: Wed, 26 Feb 2025 13:40:00 -0800 | ||
| 4 | Subject: [PATCH] [release-branch.go1.23] net/http: reject newlines in | ||
| 5 | chunk-size lines | ||
| 6 | |||
| 7 | Unlike request headers, where we are allowed to leniently accept | ||
| 8 | a bare LF in place of a CRLF, chunked bodies must always use CRLF | ||
| 9 | line terminators. We were already enforcing this for chunk-data lines; | ||
| 10 | do so for chunk-size lines as well. Also reject bare CRs anywhere | ||
| 11 | other than as part of the CRLF terminator. | ||
| 12 | |||
| 13 | Fixes CVE-2025-22871 | ||
| 14 | Fixes #72010 | ||
| 15 | For #71988 | ||
| 16 | |||
| 17 | Change-Id: Ib0e21af5a8ba28c2a1ca52b72af8e2265ec79e4a | ||
| 18 | Reviewed-on: https://go-review.googlesource.com/c/go/+/652998 | ||
| 19 | Reviewed-by: Jonathan Amsterdam <jba@google.com> | ||
| 20 | LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> | ||
| 21 | (cherry picked from commit d31c805535f3fde95646ee4d87636aaaea66847b) | ||
| 22 | Reviewed-on: https://go-review.googlesource.com/c/go/+/657216 | ||
| 23 | |||
| 24 | Upstream-Status: Backport [https://github.com/golang/go/commit/15e01a2e43ecb8c7e15ff7e9d62fe3f10dcac931] | ||
| 25 | CVE: CVE-2025-22871 | ||
| 26 | Signed-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 | |||
| 33 | diff --git a/src/net/http/internal/chunked.go b/src/net/http/internal/chunked.go | ||
| 34 | index 196b5d8..0b08a97 100644 | ||
| 35 | --- a/src/net/http/internal/chunked.go | ||
| 36 | +++ b/src/net/http/internal/chunked.go | ||
| 37 | @@ -164,6 +164,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 | @@ -171,14 +184,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 | var semi = []byte(";") | ||
| 75 | diff --git a/src/net/http/internal/chunked_test.go b/src/net/http/internal/chunked_test.go | ||
| 76 | index af79711..312f173 100644 | ||
| 77 | --- a/src/net/http/internal/chunked_test.go | ||
| 78 | +++ b/src/net/http/internal/chunked_test.go | ||
| 79 | @@ -280,6 +280,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 | ||
| 113 | diff --git a/src/net/http/serve_test.go b/src/net/http/serve_test.go | ||
| 114 | index 0c76f1b..0e8af02 100644 | ||
| 115 | --- a/src/net/http/serve_test.go | ||
| 116 | +++ b/src/net/http/serve_test.go | ||
| 117 | @@ -6980,3 +6980,52 @@ func testDisableContentLength(t *testing.T, mode testMode) { | ||
| 118 | t.Fatal(err) | ||
| 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 | -- | ||
| 171 | 2.25.1 | ||
| 172 | |||
