go/misc/cgo
Ian Lance Taylor 57ffa7b101 [release-branch.go1.14-security] cmd/go, cmd/cgo: don't let bogus symbol set cgo_ldflag
A hand-edited object file can have a symbol name that uses newline and
other normally invalid characters. The cgo tool will generate Go files
containing symbol names, unquoted. That can permit those symbol names
to inject Go code into a cgo-generated file. If that Go code uses the
//go:cgo_ldflag pragma, it can cause the C linker to run arbitrary
code when building a package. If you build an imported package we
permit arbitrary code at run time, but we don't want to permit it at
package build time. This CL prevents this in two ways.

In cgo, reject invalid symbols that contain non-printable or space
characters, or that contain anything that looks like a Go comment.

In the go tool, double check all //go:cgo_ldflag directives in
generated code, to make sure they follow the existing LDFLAG restrictions.

Thanks to Chris Brown and Tempus Ex for reporting this.

Fixes CVE-2020-28366

Change-Id: Ia1ad8f3791ea79612690fa7d26ac451d0f6df7c1
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go-private/+/895832
Reviewed-by: Than McIntosh <thanm@google.com>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
(cherry picked from commit 6bc814dd2bbfeaafa41d314dd4cc591b575dfbf6)
Reviewed-on: https://team-review.git.corp.google.com/c/golang/go-private/+/901055
Reviewed-by: Filippo Valsorda <valsorda@google.com>
Reviewed-by: Roland Shoemaker <bracewell@google.com>
2020-11-12 15:40:16 +01:00
..
errors [release-branch.go1.14-security] cmd/go, cmd/cgo: don't let bogus symbol set cgo_ldflag 2020-11-12 15:40:16 +01:00
fortran misc/cgo/fortran: avoid writing to $PWD 2019-11-20 22:37:23 +00:00
gmp all: make copyright headers consistent with one space after period 2016-05-02 13:43:18 +00:00
life misc: remove use of relative directories in overlayDir functions 2019-11-25 16:26:15 +00:00
nocgo
stdio misc: remove use of relative directories in overlayDir functions 2019-11-25 16:26:15 +00:00
test [release-branch.go1.14] cmd/cgo: use consistent tag for a particular struct 2020-04-14 22:36:35 +00:00
testasan misc: log 'ok' from 'go run' tests on success 2019-11-25 16:43:27 +00:00
testcarchive misc: remove use of relative directories in overlayDir functions 2019-11-25 16:26:15 +00:00
testcshared misc: remove use of relative directories in overlayDir functions 2019-11-25 16:26:15 +00:00
testgodefs [release-branch.go1.14] cmd/cgo, misc/cgo: only cache anonymous struct typedefs with parent name 2020-03-30 21:07:05 +00:00
testplugin misc: remove use of relative directories in overlayDir functions 2019-11-25 16:26:15 +00:00
testsanitizers runtime: save/restore callee saved registers in arm64's sigtramp 2019-06-03 19:02:11 +00:00
testshared [release-branch.go1.14] cmd/link: fix GC data reading from shared library (attempt 2) 2020-08-21 23:57:04 +00:00
testsigfwd misc: log 'ok' from 'go run' tests on success 2019-11-25 16:43:27 +00:00
testso misc: remove use of relative directories in overlayDir functions 2019-11-25 16:26:15 +00:00
testsovar misc: remove use of relative directories in overlayDir functions 2019-11-25 16:26:15 +00:00
testtls all: make copyright headers consistent with one space after period 2016-05-02 13:43:18 +00:00