]> Cypherpunks.ru repositories - gostls13.git/commit
cmd/go, cmd/cgo: don't let bogus symbol set cgo_ldflag
authorIan Lance Taylor <iant@golang.org>
Fri, 6 Nov 2020 17:38:38 +0000 (09:38 -0800)
committerKatie Hockman <katie@golang.org>
Thu, 12 Nov 2020 20:58:06 +0000 (20:58 +0000)
commit062e0e5ce6df339dc26732438ad771f73dbf2292
tree41cbca4ad13ccbda047133c39b61496df97225c7
parent1e1fa5903b760c6714ba17e50bf850b01f49135c
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 Imre Rad / https://www.linkedin.com/in/imre-rad-2358749b for
reporting this.

Fixes CVE-2020-28367

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>
Reviewed-on: https://go-review.googlesource.com/c/go/+/269658
Trust: Katie Hockman <katie@golang.org>
Trust: Roland Shoemaker <roland@golang.org>
Run-TryBot: Katie Hockman <katie@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Roland Shoemaker <roland@golang.org>
misc/cgo/errors/badsym_test.go [new file with mode: 0644]
src/cmd/cgo/out.go
src/cmd/go/internal/work/exec.go