CVE-2022-30635,CVE-2022-30630,CVE-2022-30632,CVE-2022-28131, CVE-2022-30631,CVE-2022-30629,CVE-2022-30634 Conflict: NA Score: CVE-2022-32148: 5.3 CVE-2022-1962: 6.2 CVE-2022-1705: 5.3 CVE-2022-30633: 6.2 CVE-2022-30635: 5.5 CVE-2022-30630: 6.2 CVE-2022-30632: 6.2 CVE-2022-28131: 6.2 CVE-2022-30631: 7.5 CVE-2022-30629: 2.6 CVE-2022-30634: 7.5 Reference: CVE-2022-32148: https://go-review.googlesource.com/c/go/+/415221 CVE-2022-1962: https://go-review.googlesource.com/c/go/+/417070 CVE-2022-1705: https://go-review.googlesource.com/c/go/+/415217 CVE-2022-30633: https://go-review.googlesource.com/c/go/+/417069 CVE-2022-30635: https://go-review.googlesource.com/c/go/+/417074 CVE-2022-30630: https://go-review.googlesource.com/c/go/+/417072 CVE-2022-30632: https://go-review.googlesource.com/c/go/+/417073 CVE-2022-28131: https://go-review.googlesource.com/c/go/+/417068 CVE-2022-30631: https://go-review.googlesource.com/c/go/+/417071 CVE-2022-30629: https://go-review.googlesource.com/c/go/+/408574 CVE-2022-30634: https://go-review.googlesource.com/c/go/+/406635 Reason: fix CVE: CVE-2022-32148: 0005-release-branch.go1.17-net-http-preserve-nil-values-i.patch CVE-2022-1962: 0006-release-branch.go1.17-go-parser-limit-recursion-dept.patch CVE-2022-1705: 0007-release-branch.go1.17-net-http-don-t-strip-whitespac.patch CVE-2022-30633: 0008-release-branch.go1.17-encoding-xml-limit-depth-of-ne.patch CVE-2022-30635: 0009-release-branch.go1.17-encoding-gob-add-a-depth-limit.patch CVE-2022-30630: 0010-release-branch.go1.17-io-fs-fix-stack-exhaustion-in-.patch CVE-2022-30632: 0011-release-branch.go1.17-path-filepath-fix-stack-exhaus.patch CVE-2022-28131: 0012-release-branch.go1.17-encoding-xml-use-iterative-Ski.patch CVE-2022-30631: 0013-release-branch.go1.17-compress-gzip-fix-stack-exhaus.patch CVE-2022-30629: 0014-release-branch.go1.17-crypto-tls-randomly-generate-t.patch CVE-2022-30634: 0015-release-branch.go1.17-crypto-rand-properly-handle-la.patch
134 lines
3.9 KiB
Diff
134 lines
3.9 KiB
Diff
From 8a445abc7f7e2ed41112f176a169b97859c8d425 Mon Sep 17 00:00:00 2001
|
|
From: Tatiana Bradley <tatiana@golang.org>
|
|
Date: Fri, 6 May 2022 11:25:06 -0400
|
|
Subject: [PATCH 09/11] [release-branch.go1.17] compress/gzip: fix stack
|
|
exhaustion bug in Reader.Read
|
|
|
|
Replace recursion with iteration in Reader.Read to avoid stack
|
|
exhaustion when there are a large number of files.
|
|
|
|
Fixes CVE-2022-30631
|
|
Fixes #53717
|
|
Updates #53168
|
|
|
|
Change-Id: I47d8afe3f2d40b0213ab61431df9b221794dbfe0
|
|
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go-private/+/1455673
|
|
Reviewed-by: Roland Shoemaker <bracewell@google.com>
|
|
Reviewed-by: Julie Qiu <julieqiu@google.com>
|
|
(cherry picked from commit cf498969c8a0bae9d7a24b98fc1f66c824a4775d)
|
|
Reviewed-on: https://go-review.googlesource.com/c/go/+/417071
|
|
Reviewed-by: Heschi Kreinick <heschi@google.com>
|
|
Run-TryBot: Michael Knyszek <mknyszek@google.com>
|
|
TryBot-Result: Gopher Robot <gobot@golang.org>
|
|
|
|
Conflict: NA
|
|
Reference: https://go-review.googlesource.com/c/go/+/417071
|
|
---
|
|
src/compress/gzip/gunzip.go | 60 +++++++++++++++-----------------
|
|
src/compress/gzip/gunzip_test.go | 16 +++++++++
|
|
2 files changed, 45 insertions(+), 31 deletions(-)
|
|
|
|
diff --git a/src/compress/gzip/gunzip.go b/src/compress/gzip/gunzip.go
|
|
index 924bce10b7c..237b2b928bf 100644
|
|
--- a/src/compress/gzip/gunzip.go
|
|
+++ b/src/compress/gzip/gunzip.go
|
|
@@ -248,42 +248,40 @@ func (z *Reader) Read(p []byte) (n int, err error) {
|
|
return 0, z.err
|
|
}
|
|
|
|
- n, z.err = z.decompressor.Read(p)
|
|
- z.digest = crc32.Update(z.digest, crc32.IEEETable, p[:n])
|
|
- z.size += uint32(n)
|
|
- if z.err != io.EOF {
|
|
- // In the normal case we return here.
|
|
- return n, z.err
|
|
- }
|
|
+ for n == 0 {
|
|
+ n, z.err = z.decompressor.Read(p)
|
|
+ z.digest = crc32.Update(z.digest, crc32.IEEETable, p[:n])
|
|
+ z.size += uint32(n)
|
|
+ if z.err != io.EOF {
|
|
+ // In the normal case we return here.
|
|
+ return n, z.err
|
|
+ }
|
|
|
|
- // Finished file; check checksum and size.
|
|
- if _, err := io.ReadFull(z.r, z.buf[:8]); err != nil {
|
|
- z.err = noEOF(err)
|
|
- return n, z.err
|
|
- }
|
|
- digest := le.Uint32(z.buf[:4])
|
|
- size := le.Uint32(z.buf[4:8])
|
|
- if digest != z.digest || size != z.size {
|
|
- z.err = ErrChecksum
|
|
- return n, z.err
|
|
- }
|
|
- z.digest, z.size = 0, 0
|
|
+ // Finished file; check checksum and size.
|
|
+ if _, err := io.ReadFull(z.r, z.buf[:8]); err != nil {
|
|
+ z.err = noEOF(err)
|
|
+ return n, z.err
|
|
+ }
|
|
+ digest := le.Uint32(z.buf[:4])
|
|
+ size := le.Uint32(z.buf[4:8])
|
|
+ if digest != z.digest || size != z.size {
|
|
+ z.err = ErrChecksum
|
|
+ return n, z.err
|
|
+ }
|
|
+ z.digest, z.size = 0, 0
|
|
|
|
- // File is ok; check if there is another.
|
|
- if !z.multistream {
|
|
- return n, io.EOF
|
|
- }
|
|
- z.err = nil // Remove io.EOF
|
|
+ // File is ok; check if there is another.
|
|
+ if !z.multistream {
|
|
+ return n, io.EOF
|
|
+ }
|
|
+ z.err = nil // Remove io.EOF
|
|
|
|
- if _, z.err = z.readHeader(); z.err != nil {
|
|
- return n, z.err
|
|
+ if _, z.err = z.readHeader(); z.err != nil {
|
|
+ return n, z.err
|
|
+ }
|
|
}
|
|
|
|
- // Read from next file, if necessary.
|
|
- if n > 0 {
|
|
- return n, nil
|
|
- }
|
|
- return z.Read(p)
|
|
+ return n, nil
|
|
}
|
|
|
|
// Close closes the Reader. It does not close the underlying io.Reader.
|
|
diff --git a/src/compress/gzip/gunzip_test.go b/src/compress/gzip/gunzip_test.go
|
|
index 17c23e8a9be..6fe8ddcf558 100644
|
|
--- a/src/compress/gzip/gunzip_test.go
|
|
+++ b/src/compress/gzip/gunzip_test.go
|
|
@@ -515,3 +515,19 @@ func TestTruncatedStreams(t *testing.T) {
|
|
}
|
|
}
|
|
}
|
|
+
|
|
+func TestCVE202230631(t *testing.T) {
|
|
+ var empty = []byte{0x1f, 0x8b, 0x08, 0x00, 0xa7, 0x8f, 0x43, 0x62, 0x00,
|
|
+ 0x03, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
|
|
+ r := bytes.NewReader(bytes.Repeat(empty, 4e6))
|
|
+ z, err := NewReader(r)
|
|
+ if err != nil {
|
|
+ t.Fatalf("NewReader: got %v, want nil", err)
|
|
+ }
|
|
+ // Prior to CVE-2022-30631 fix, this would cause an unrecoverable panic due
|
|
+ // to stack exhaustion.
|
|
+ _, err = z.Read(make([]byte, 10))
|
|
+ if err != io.EOF {
|
|
+ t.Errorf("Reader.Read: got %v, want %v", err, io.EOF)
|
|
+ }
|
|
+}
|
|
--
|
|
2.30.2
|
|
|