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
139 lines
5.6 KiB
Diff
139 lines
5.6 KiB
Diff
From 8747af9a1098e8fa497441be4c4a79a23de31a98 Mon Sep 17 00:00:00 2001
|
|
From: Roland Shoemaker <bracewell@google.com>
|
|
Date: Tue, 7 Jun 2022 13:00:43 -0700
|
|
Subject: [PATCH 05/11] [release-branch.go1.17] encoding/gob: add a depth limit
|
|
for ignored fields
|
|
|
|
Enforce a nesting limit of 10,000 for ignored fields during decoding
|
|
of messages. This prevents the possibility of triggering stack
|
|
exhaustion.
|
|
|
|
Fixes #53709
|
|
Updates #53615
|
|
Fixes CVE-2022-30635
|
|
|
|
Change-Id: I05103d06dd5ca3945fcba3c1f5d3b5a645e8fb0f
|
|
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go-private/+/1484771
|
|
Reviewed-by: Damien Neil <dneil@google.com>
|
|
Reviewed-by: Tatiana Bradley <tatianabradley@google.com>
|
|
(cherry picked from commit 55e8f938d22bfec29cc9dc9671044c5a41d1ea9c)
|
|
Reviewed-on: https://go-review.googlesource.com/c/go/+/417074
|
|
Run-TryBot: Heschi Kreinick <heschi@google.com>
|
|
TryBot-Result: Gopher Robot <gobot@golang.org>
|
|
Reviewed-by: Heschi Kreinick <heschi@google.com>
|
|
|
|
Conflict: NA
|
|
Reference: https://go-review.googlesource.com/c/go/+/417074
|
|
---
|
|
src/encoding/gob/decode.go | 19 ++++++++++++-------
|
|
src/encoding/gob/gobencdec_test.go | 24 ++++++++++++++++++++++++
|
|
2 files changed, 36 insertions(+), 7 deletions(-)
|
|
|
|
diff --git a/src/encoding/gob/decode.go b/src/encoding/gob/decode.go
|
|
index d2f6c749b1b..0e0ec75cccc 100644
|
|
--- a/src/encoding/gob/decode.go
|
|
+++ b/src/encoding/gob/decode.go
|
|
@@ -871,8 +871,13 @@ func (dec *Decoder) decOpFor(wireId typeId, rt reflect.Type, name string, inProg
|
|
return &op
|
|
}
|
|
|
|
+var maxIgnoreNestingDepth = 10000
|
|
+
|
|
// decIgnoreOpFor returns the decoding op for a field that has no destination.
|
|
-func (dec *Decoder) decIgnoreOpFor(wireId typeId, inProgress map[typeId]*decOp) *decOp {
|
|
+func (dec *Decoder) decIgnoreOpFor(wireId typeId, inProgress map[typeId]*decOp, depth int) *decOp {
|
|
+ if depth > maxIgnoreNestingDepth {
|
|
+ error_(errors.New("invalid nesting depth"))
|
|
+ }
|
|
// If this type is already in progress, it's a recursive type (e.g. map[string]*T).
|
|
// Return the pointer to the op we're already building.
|
|
if opPtr := inProgress[wireId]; opPtr != nil {
|
|
@@ -896,7 +901,7 @@ func (dec *Decoder) decIgnoreOpFor(wireId typeId, inProgress map[typeId]*decOp)
|
|
errorf("bad data: undefined type %s", wireId.string())
|
|
case wire.ArrayT != nil:
|
|
elemId := wire.ArrayT.Elem
|
|
- elemOp := dec.decIgnoreOpFor(elemId, inProgress)
|
|
+ elemOp := dec.decIgnoreOpFor(elemId, inProgress, depth+1)
|
|
op = func(i *decInstr, state *decoderState, value reflect.Value) {
|
|
state.dec.ignoreArray(state, *elemOp, wire.ArrayT.Len)
|
|
}
|
|
@@ -904,15 +909,15 @@ func (dec *Decoder) decIgnoreOpFor(wireId typeId, inProgress map[typeId]*decOp)
|
|
case wire.MapT != nil:
|
|
keyId := dec.wireType[wireId].MapT.Key
|
|
elemId := dec.wireType[wireId].MapT.Elem
|
|
- keyOp := dec.decIgnoreOpFor(keyId, inProgress)
|
|
- elemOp := dec.decIgnoreOpFor(elemId, inProgress)
|
|
+ keyOp := dec.decIgnoreOpFor(keyId, inProgress, depth+1)
|
|
+ elemOp := dec.decIgnoreOpFor(elemId, inProgress, depth+1)
|
|
op = func(i *decInstr, state *decoderState, value reflect.Value) {
|
|
state.dec.ignoreMap(state, *keyOp, *elemOp)
|
|
}
|
|
|
|
case wire.SliceT != nil:
|
|
elemId := wire.SliceT.Elem
|
|
- elemOp := dec.decIgnoreOpFor(elemId, inProgress)
|
|
+ elemOp := dec.decIgnoreOpFor(elemId, inProgress, depth+1)
|
|
op = func(i *decInstr, state *decoderState, value reflect.Value) {
|
|
state.dec.ignoreSlice(state, *elemOp)
|
|
}
|
|
@@ -1073,7 +1078,7 @@ func (dec *Decoder) compileSingle(remoteId typeId, ut *userTypeInfo) (engine *de
|
|
func (dec *Decoder) compileIgnoreSingle(remoteId typeId) *decEngine {
|
|
engine := new(decEngine)
|
|
engine.instr = make([]decInstr, 1) // one item
|
|
- op := dec.decIgnoreOpFor(remoteId, make(map[typeId]*decOp))
|
|
+ op := dec.decIgnoreOpFor(remoteId, make(map[typeId]*decOp), 0)
|
|
ovfl := overflow(dec.typeString(remoteId))
|
|
engine.instr[0] = decInstr{*op, 0, nil, ovfl}
|
|
engine.numInstr = 1
|
|
@@ -1118,7 +1123,7 @@ func (dec *Decoder) compileDec(remoteId typeId, ut *userTypeInfo) (engine *decEn
|
|
localField, present := srt.FieldByName(wireField.Name)
|
|
// TODO(r): anonymous names
|
|
if !present || !isExported(wireField.Name) {
|
|
- op := dec.decIgnoreOpFor(wireField.Id, make(map[typeId]*decOp))
|
|
+ op := dec.decIgnoreOpFor(wireField.Id, make(map[typeId]*decOp), 0)
|
|
engine.instr[fieldnum] = decInstr{*op, fieldnum, nil, ovfl}
|
|
continue
|
|
}
|
|
diff --git a/src/encoding/gob/gobencdec_test.go b/src/encoding/gob/gobencdec_test.go
|
|
index 6d2c8db42d0..1b52ecc6c84 100644
|
|
--- a/src/encoding/gob/gobencdec_test.go
|
|
+++ b/src/encoding/gob/gobencdec_test.go
|
|
@@ -12,6 +12,7 @@ import (
|
|
"fmt"
|
|
"io"
|
|
"net"
|
|
+ "reflect"
|
|
"strings"
|
|
"testing"
|
|
"time"
|
|
@@ -796,3 +797,26 @@ func TestNetIP(t *testing.T) {
|
|
t.Errorf("decoded to %v, want 1.2.3.4", ip.String())
|
|
}
|
|
}
|
|
+
|
|
+func TestIngoreDepthLimit(t *testing.T) {
|
|
+ // We don't test the actual depth limit because it requires building an
|
|
+ // extremely large message, which takes quite a while.
|
|
+ oldNestingDepth := maxIgnoreNestingDepth
|
|
+ maxIgnoreNestingDepth = 100
|
|
+ defer func() { maxIgnoreNestingDepth = oldNestingDepth }()
|
|
+ b := new(bytes.Buffer)
|
|
+ enc := NewEncoder(b)
|
|
+ typ := reflect.TypeOf(int(0))
|
|
+ nested := reflect.ArrayOf(1, typ)
|
|
+ for i := 0; i < 100; i++ {
|
|
+ nested = reflect.ArrayOf(1, nested)
|
|
+ }
|
|
+ badStruct := reflect.New(reflect.StructOf([]reflect.StructField{{Name: "F", Type: nested}}))
|
|
+ enc.Encode(badStruct.Interface())
|
|
+ dec := NewDecoder(b)
|
|
+ var output struct{ Hello int }
|
|
+ expectedErr := "invalid nesting depth"
|
|
+ if err := dec.Decode(&output); err == nil || err.Error() != expectedErr {
|
|
+ t.Errorf("Decode didn't fail with depth limit of 100: want %q, got %q", expectedErr, err)
|
|
+ }
|
|
+}
|
|
--
|
|
2.30.2
|
|
|