diff options
author | Archana Polampalli <archana.polampalli@windriver.com> | 2025-01-08 05:54:21 +0000 |
---|---|---|
committer | Steve Sakoman <steve@sakoman.com> | 2025-01-18 06:21:02 -0800 |
commit | 4f959ce14c7693c6df713bb99d6ef15337d37d98 (patch) | |
tree | 187c2154e245ec70aa2e26c8976e5ad6ed147341 | |
parent | 0c88d20540f0513c3d79d10f34132b2296ac246c (diff) | |
download | poky-4f959ce14c7693c6df713bb99d6ef15337d37d98.tar.gz |
go: Fix CVE-2024-34158
Calling Parse on a "// +build" build tag line with deeply nested
expressions can cause a panic due to stack exhaustion.
Reference:
https://nvd.nist.gov/vuln/detail/CVE-2024-34158
Upstream-patch:
https://github.com/golang/go/commit/d4c53812e6ce2ac368173d7fcd31d0ecfcffb002
(From OE-Core rev: eb14e9722d023b4d1668c55ce4bc6ef02f8ce6c2)
Signed-off-by: Archana Polampalli <archana.polampalli@windriver.com>
Signed-off-by: Steve Sakoman <steve@sakoman.com>
-rw-r--r-- | meta/recipes-devtools/go/go-1.17.13.inc | 1 | ||||
-rw-r--r-- | meta/recipes-devtools/go/go-1.21/CVE-2024-34158.patch | 205 |
2 files changed, 206 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 53ca869221..c483590931 100644 --- a/meta/recipes-devtools/go/go-1.17.13.inc +++ b/meta/recipes-devtools/go/go-1.17.13.inc | |||
@@ -60,6 +60,7 @@ SRC_URI += "\ | |||
60 | file://CVE-2024-24791.patch \ | 60 | file://CVE-2024-24791.patch \ |
61 | file://CVE-2024-34155.patch \ | 61 | file://CVE-2024-34155.patch \ |
62 | file://CVE-2024-34156.patch \ | 62 | file://CVE-2024-34156.patch \ |
63 | file://CVE-2024-34158.patch \ | ||
63 | " | 64 | " |
64 | SRC_URI[main.sha256sum] = "a1a48b23afb206f95e7bbaa9b898d965f90826f6f1d1fc0c1d784ada0cd300fd" | 65 | SRC_URI[main.sha256sum] = "a1a48b23afb206f95e7bbaa9b898d965f90826f6f1d1fc0c1d784ada0cd300fd" |
65 | 66 | ||
diff --git a/meta/recipes-devtools/go/go-1.21/CVE-2024-34158.patch b/meta/recipes-devtools/go/go-1.21/CVE-2024-34158.patch new file mode 100644 index 0000000000..ad4d4f092c --- /dev/null +++ b/meta/recipes-devtools/go/go-1.21/CVE-2024-34158.patch | |||
@@ -0,0 +1,205 @@ | |||
1 | From d4c53812e6ce2ac368173d7fcd31d0ecfcffb002 Mon Sep 17 00:00:00 2001 | ||
2 | From: Roland Shoemaker <bracewell@google.com> | ||
3 | Date: Thu, 20 Jun 2024 10:45:30 -0700 | ||
4 | Subject: [PATCH] go/build/constraint: add parsing limits | ||
5 | |||
6 | Limit the size of build constraints that we will parse. This prevents a | ||
7 | number of stack exhaustions that can be hit when parsing overly complex | ||
8 | constraints. The imposed limits are unlikely to ever be hit in real | ||
9 | world usage. | ||
10 | |||
11 | Updates #69141 | ||
12 | Fixes #69148 | ||
13 | Fixes CVE-2024-34158 | ||
14 | |||
15 | Change-Id: I38b614bf04caa36eefc6a4350d848588c4cef3c4 | ||
16 | Reviewed-on: https://go-internal-review.googlesource.com/c/go/+/1540 | ||
17 | Reviewed-by: Damien Neil <dneil@google.com> | ||
18 | Reviewed-by: Russ Cox <rsc@google.com> | ||
19 | (cherry picked from commit 0c74dc9e0da0cf1e12494b514d822b5bebbc9f04) | ||
20 | Reviewed-on: https://go-internal-review.googlesource.com/c/go/+/1582 | ||
21 | Reviewed-by: Tatiana Bradley <tatianabradley@google.com> | ||
22 | Reviewed-on: https://go-review.googlesource.com/c/go/+/611183 | ||
23 | Auto-Submit: Dmitri Shuralyov <dmitshur@google.com> | ||
24 | Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> | ||
25 | Reviewed-by: Michael Pratt <mpratt@google.com> | ||
26 | TryBot-Bypass: Dmitri Shuralyov <dmitshur@google.com> | ||
27 | |||
28 | CVE: CVE-2024-34158 | ||
29 | |||
30 | Upstream-Status: Backport [https://github.com/golang/go/commit/d4c53812e6ce2ac368173d7fcd31d0ecfcffb002] | ||
31 | |||
32 | Signed-off-by: Archana Polampalli <archana.polampalli@windriver.com> | ||
33 | --- | ||
34 | src/go/build/constraint/expr.go | 28 ++++++++++-- | ||
35 | src/go/build/constraint/expr_test.go | 65 +++++++++++++++++++++++++++- | ||
36 | 2 files changed, 89 insertions(+), 4 deletions(-) | ||
37 | |||
38 | diff --git a/src/go/build/constraint/expr.go b/src/go/build/constraint/expr.go | ||
39 | index 957eb9b..85897e2 100644 | ||
40 | --- a/src/go/build/constraint/expr.go | ||
41 | +++ b/src/go/build/constraint/expr.go | ||
42 | @@ -18,6 +18,10 @@ import ( | ||
43 | "unicode/utf8" | ||
44 | ) | ||
45 | |||
46 | +// maxSize is a limit used to control the complexity of expressions, in order | ||
47 | +// to prevent stack exhaustion issues due to recursion. | ||
48 | +const maxSize = 1000 | ||
49 | + | ||
50 | // An Expr is a build tag constraint expression. | ||
51 | // The underlying concrete type is *AndExpr, *OrExpr, *NotExpr, or *TagExpr. | ||
52 | type Expr interface { | ||
53 | @@ -153,7 +157,7 @@ func Parse(line string) (Expr, error) { | ||
54 | return parseExpr(text) | ||
55 | } | ||
56 | if text, ok := splitPlusBuild(line); ok { | ||
57 | - return parsePlusBuildExpr(text), nil | ||
58 | + return parsePlusBuildExpr(text) | ||
59 | } | ||
60 | return nil, errNotConstraint | ||
61 | } | ||
62 | @@ -203,6 +207,8 @@ type exprParser struct { | ||
63 | tok string // last token read | ||
64 | isTag bool | ||
65 | pos int // position (start) of last token | ||
66 | + | ||
67 | + size int | ||
68 | } | ||
69 | |||
70 | // parseExpr parses a boolean build tag expression. | ||
71 | @@ -251,6 +257,10 @@ func (p *exprParser) and() Expr { | ||
72 | // On entry, the next input token has not yet been lexed. | ||
73 | // On exit, the next input token has been lexed and is in p.tok. | ||
74 | func (p *exprParser) not() Expr { | ||
75 | + p.size++ | ||
76 | + if p.size > maxSize { | ||
77 | + panic(&SyntaxError{Offset: p.pos, Err: "build expression too large"}) | ||
78 | + } | ||
79 | p.lex() | ||
80 | if p.tok == "!" { | ||
81 | p.lex() | ||
82 | @@ -391,7 +401,13 @@ func splitPlusBuild(line string) (expr string, ok bool) { | ||
83 | } | ||
84 | |||
85 | // parsePlusBuildExpr parses a legacy build tag expression (as used with “// +build”). | ||
86 | -func parsePlusBuildExpr(text string) Expr { | ||
87 | +func parsePlusBuildExpr(text string) (Expr, error) { | ||
88 | + // Only allow up to 100 AND/OR operators for "old" syntax. | ||
89 | + // This is much less than the limit for "new" syntax, | ||
90 | + // but uses of old syntax were always very simple. | ||
91 | + const maxOldSize = 100 | ||
92 | + size := 0 | ||
93 | + | ||
94 | var x Expr | ||
95 | for _, clause := range strings.Fields(text) { | ||
96 | var y Expr | ||
97 | @@ -417,19 +433,25 @@ func parsePlusBuildExpr(text string) Expr { | ||
98 | if y == nil { | ||
99 | y = z | ||
100 | } else { | ||
101 | + if size++; size > maxOldSize { | ||
102 | + return nil, errComplex | ||
103 | + } | ||
104 | y = and(y, z) | ||
105 | } | ||
106 | } | ||
107 | if x == nil { | ||
108 | x = y | ||
109 | } else { | ||
110 | + if size++; size > maxOldSize { | ||
111 | + return nil, errComplex | ||
112 | + } | ||
113 | x = or(x, y) | ||
114 | } | ||
115 | } | ||
116 | if x == nil { | ||
117 | x = tag("ignore") | ||
118 | } | ||
119 | - return x | ||
120 | + return x, nil | ||
121 | } | ||
122 | |||
123 | // isValidTag reports whether the word is a valid build tag. | ||
124 | diff --git a/src/go/build/constraint/expr_test.go b/src/go/build/constraint/expr_test.go | ||
125 | index 15d1890..ac38ba6 100644 | ||
126 | --- a/src/go/build/constraint/expr_test.go | ||
127 | +++ b/src/go/build/constraint/expr_test.go | ||
128 | @@ -222,7 +222,7 @@ var parsePlusBuildExprTests = []struct { | ||
129 | func TestParsePlusBuildExpr(t *testing.T) { | ||
130 | for i, tt := range parsePlusBuildExprTests { | ||
131 | t.Run(fmt.Sprint(i), func(t *testing.T) { | ||
132 | - x := parsePlusBuildExpr(tt.in) | ||
133 | + x, _ := parsePlusBuildExpr(tt.in) | ||
134 | if x.String() != tt.x.String() { | ||
135 | t.Errorf("parsePlusBuildExpr(%q):\nhave %v\nwant %v", tt.in, x, tt.x) | ||
136 | } | ||
137 | @@ -319,3 +319,66 @@ func TestPlusBuildLines(t *testing.T) { | ||
138 | }) | ||
139 | } | ||
140 | } | ||
141 | + | ||
142 | +func TestSizeLimits(t *testing.T) { | ||
143 | + for _, tc := range []struct { | ||
144 | + name string | ||
145 | + expr string | ||
146 | + }{ | ||
147 | + { | ||
148 | + name: "go:build or limit", | ||
149 | + expr: "//go:build " + strings.Repeat("a || ", maxSize+2), | ||
150 | + }, | ||
151 | + { | ||
152 | + name: "go:build and limit", | ||
153 | + expr: "//go:build " + strings.Repeat("a && ", maxSize+2), | ||
154 | + }, | ||
155 | + { | ||
156 | + name: "go:build and depth limit", | ||
157 | + expr: "//go:build " + strings.Repeat("(a &&", maxSize+2), | ||
158 | + }, | ||
159 | + { | ||
160 | + name: "go:build or depth limit", | ||
161 | + expr: "//go:build " + strings.Repeat("(a ||", maxSize+2), | ||
162 | + }, | ||
163 | + } { | ||
164 | + t.Run(tc.name, func(t *testing.T) { | ||
165 | + _, err := Parse(tc.expr) | ||
166 | + if err == nil { | ||
167 | + t.Error("expression did not trigger limit") | ||
168 | + } else if syntaxErr, ok := err.(*SyntaxError); !ok || syntaxErr.Err != "build expression too large" { | ||
169 | + if !ok { | ||
170 | + t.Errorf("unexpected error: %v", err) | ||
171 | + } else { | ||
172 | + t.Errorf("unexpected syntax error: %s", syntaxErr.Err) | ||
173 | + } | ||
174 | + } | ||
175 | + }) | ||
176 | + } | ||
177 | +} | ||
178 | + | ||
179 | +func TestPlusSizeLimits(t *testing.T) { | ||
180 | + maxOldSize := 100 | ||
181 | + for _, tc := range []struct { | ||
182 | + name string | ||
183 | + expr string | ||
184 | + }{ | ||
185 | + { | ||
186 | + name: "+build or limit", | ||
187 | + expr: "// +build " + strings.Repeat("a ", maxOldSize+2), | ||
188 | + }, | ||
189 | + { | ||
190 | + name: "+build and limit", | ||
191 | + expr: "// +build " + strings.Repeat("a,", maxOldSize+2), | ||
192 | + }, | ||
193 | + } { | ||
194 | + t.Run(tc.name, func(t *testing.T) { | ||
195 | + _, err := Parse(tc.expr) | ||
196 | + if err == nil { | ||
197 | + t.Error("expression did not trigger limit") | ||
198 | + } else if err != errComplex { | ||
199 | + t.Errorf("unexpected error: got %q, want %q", err, errComplex) | ||
200 | + } | ||
201 | + }) | ||
202 | + } | ||
203 | +} | ||
204 | -- | ||
205 | 2.40.0 | ||