Skip to content

Commit ec06b6d

Browse files
ianlancetaylorkatiehockman
authored andcommitted
[release-branch.go1.15-security] cmd/go: in cgoflags, permit -DX1, prohibit -Wp,-D,opt
Restrict -D and -U to ASCII C identifiers, but do permit trailing digits. When using -Wp, prohibit commas in -D values. Thanks to Imre Rad (https://www.linkedin.com/in/imre-rad-2358749b) for reporting this. Fixes CVE-2020-28367 Change-Id: Ibfc4dfdd6e6c258e131448e7682610c44eee9492 Reviewed-on: https://go-review.googlesource.com/c/go/+/267277 Trust: Ian Lance Taylor <[email protected]> Run-TryBot: Ian Lance Taylor <[email protected]> TryBot-Result: Go Bot <[email protected]> Reviewed-by: Bryan C. Mills <[email protected]> Reviewed-on: https://team-review.git.corp.google.com/c/golang/go-private/+/899924 Reviewed-by: Filippo Valsorda <[email protected]>
1 parent 3215982 commit ec06b6d

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

src/cmd/go/internal/work/security.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,17 +42,17 @@ import (
4242
var re = lazyregexp.New
4343

4444
var validCompilerFlags = []*lazyregexp.Regexp{
45-
re(`-D([A-Za-z_].*)`),
46-
re(`-U([A-Za-z_]*)`),
45+
re(`-D([A-Za-z_][A-Za-z0-9_]*)(=[^@\-]*)?`),
46+
re(`-U([A-Za-z_][A-Za-z0-9_]*)`),
4747
re(`-F([^@\-].*)`),
4848
re(`-I([^@\-].*)`),
4949
re(`-O`),
5050
re(`-O([^@\-].*)`),
5151
re(`-W`),
5252
re(`-W([^@,]+)`), // -Wall but not -Wa,-foo.
5353
re(`-Wa,-mbig-obj`),
54-
re(`-Wp,-D([A-Za-z_].*)`),
55-
re(`-Wp,-U([A-Za-z_]*)`),
54+
re(`-Wp,-D([A-Za-z_][A-Za-z0-9_]*)(=[^@,\-]*)?`),
55+
re(`-Wp,-U([A-Za-z_][A-Za-z0-9_]*)`),
5656
re(`-ansi`),
5757
re(`-f(no-)?asynchronous-unwind-tables`),
5858
re(`-f(no-)?blocks`),

src/cmd/go/internal/work/security_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ var goodCompilerFlags = [][]string{
1313
{"-DFOO"},
1414
{"-Dfoo=bar"},
1515
{"-Ufoo"},
16+
{"-Ufoo1"},
1617
{"-F/Qt"},
1718
{"-I/"},
1819
{"-I/etc/passwd"},
@@ -24,6 +25,8 @@ var goodCompilerFlags = [][]string{
2425
{"-Wall"},
2526
{"-Wp,-Dfoo=bar"},
2627
{"-Wp,-Ufoo"},
28+
{"-Wp,-Dfoo1"},
29+
{"-Wp,-Ufoo1"},
2730
{"-fobjc-arc"},
2831
{"-fno-objc-arc"},
2932
{"-fomit-frame-pointer"},
@@ -78,6 +81,8 @@ var badCompilerFlags = [][]string{
7881
{"-O@1"},
7982
{"-Wa,-foo"},
8083
{"-W@foo"},
84+
{"-Wp,-DX,-D@X"},
85+
{"-Wp,-UX,-U@X"},
8186
{"-g@gdb"},
8287
{"-g-gdb"},
8388
{"-march=@dawn"},

0 commit comments

Comments
 (0)