cmd/go: arbitrary code execution during “go get” · Issue #23672 · golang/go · GitHub
Skip to content You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session. Dismiss alert cmd/go: arbitrary code execution during “go get” #23672 New issue Copy link New issue Copy link Closed Closed cmd/go: arbitrary code execution during “go get” #23672 Copy link Labels FrozenDueToAge Security Milestone Go1.10 Description rsc opened on Feb 2, 2018 Issue body actions Go get downloads and builds source code.
It is not meant to execute arbitrary code. When cgo is enabled, the build step during “go get” invokes the host C compiler, gcc or clang, adding compiler flags specified in the Go source files. Both gcc and clang support a plugin mechanism in which a shared-library plugin is loaded into the compiler, as directed by compiler flags. This means that a Go package repository can contain an attack.so file along with a Go source file that says (for example) // #cgo CFLAGS: -fplugin=attack.so , causing the attack plugin to be loaded into the host C compiler during the build.
Gcc and clang plugins are completely unrestricted in their access to the host system. Thanks to Christopher Brown of Mattermost for reporting this problem. This issue is CVE-2018-6574 . Fixed in Go 1.8.7 by commit 44821583bc16 . Fixed in Go 1.9.4 by commit 867fb18b6d5b . Fixed in Go 1.10rc2 by commit 1dcb5836ad2c . The fix changes “go build” (used during “go get” and “go install”) to limit the flags that can appear in Go source file #cgo directives to a list of allowed compiler flags; -fplugin= and other variants are not on the allowed list.
The same restrictions are applied to compiler flags obtained from pkg-config. Flags obtained from the environment variables $CGO_CFLAGS and so on are not restricted, since those variables can only be set by the user running the build. To change the set of allowed compiler flags, new environment variables $CGO_CFLAGS_ALLOW and $CGO_CFLAGS_DISALLOW can set to regular expressions matching additional allowed and disallowed flags.
Run “go doc cgo” for details. Code that passes a flag and argument pair to the linker must now use one -Wl flag instead of two: use #cgo LDFLAGS: -Wl,-rpath,$ORIGIN , not #cgo LDFLAGS: -Wl,-rpath -Wl,$ORIGIN . Also, //go:cgo... directives, including //go:cgo_ldflag , are now disallowed except in cgo-generated source code and some special cases in the standard library. Packages outside the standard library that attempt to use these directives will no longer build.
Reacted by Emmanuel T Odeke, Juraj Bubniak, Pat Lathem, Marcin Tojek, Chris, Ryan Djurovich, Tim Strazzere, Andreas Auernhammer, Sen Han, Jared Folkins and 55 more Activity Next rsc added this to the Go1.10 milestone on Feb 2, 2018 rsc self-assigned this on Feb 2, 2018 gopherbot added a commit that references this issue on Feb 7, 2018 cmd/go: accept only limited compiler and linker flags in #cgo directives This issue will close once commit 1dcb583 is merged into the 'master' branch.
1dcb583 rsc changed the title [-] security: issue [Go 1.10rc1] [/-] [+] cmd/go: arbitrary code execution during “go get” [/+] on Feb 7, 2018 ilovezfs added 2 commits that reference this issue on Feb 8, 2018 go@1.6: delete ecbbe14 go@1.7: delete 56683ef mistydemeo added 2 commits that reference this issue on Feb 8, 2018 go@1.6: delete 4605f08 go@1.7: delete 1748e91 anacrolix commented on Feb 8, 2018 anacrolix on Feb 8, 2018 Contributor More actions Consider these compiler flags: -fno-exceptions -fno-rtti -fpermissive And also -framework as a linker option: -Wl,-framework See go-libutp and go-gtk . juniorz added a commit that references this issue on Feb 8, 2018 The security fix seems to break cgo-builds in macOS.
4db6921 mattn commented on Feb 8, 2018 mattn on Feb 8, 2018 Member More actions In the case of go-gtk, these flags are provided from pkg-config. Fortunately, I could build go-gtk on Windows. I still not confirm Linux. dmitris commented on Feb 8, 2018 dmitris on Feb 8, 2018 Contributor More actions miekg/pkcs11#63 - go1.9.4 breaks building github.com/miekg/pkcs11 on Linux as it does not allow -Wl,--no-as-needed - could that flag be added, please?
Otherwise users would have to run install and test as CGO_LDFLAGS_ALLOW='-Wl,--no-as-needed' go install and it will break lots of CI builds. anacrolix added a commit that references this issue on Feb 8, 2018 Remove "insecure" compiler flags 895ab77 ianlancetaylor commented on Feb 8, 2018 ianlancetaylor on Feb 8, 2018 Contributor More actions I've opened #23749 as a place to collect options that should be added to the whitelists. flx42 added a commit that references this issue on Feb 9, 2018 Update golang to 1.9.4 dbc8590 18 remaining items gopherbot added a commit that references this issue on Feb 16, 2018 [release-branch.go1.10] cmd/compile: permit go:cgo_import_dynamic any… d1fbe07 DarthSim added a commit that references this issue on Feb 22, 2018 cgo compilation workaround for go 1.9.4 ( #52 ) 5062e74 dtzWill added a commit that references this issue on Feb 23, 2018 Because of CVE-2018-6574 , some compiler options and linker options ar… a4a3d37 earl added a commit that references this issue on Feb 23, 2018 Because of CVE-2018-6574 , some compiler options and linker options ar… 466d8f9 jyknight added 2 commits that reference this issue on Mar 1, 2018 Merging r325946: 5b01000 Because of CVE-2018-6574 , some compiler options and linker options ar… 54ac35d krig added 2 commits that reference this issue on Mar 8, 2018 Drop LDFLAGS usage as this is now disallowed (see golang/go#23672 ) efe89cc bump github.com/krig/go-pacemaker 415df31 rn added a commit that references this issue on Mar 24, 2018 pkg: Fix cgo CFLAGS for rngd 998eaa7 llvm-git-migration added a commit that references this issue on Nov 6, 2018 Merging r325946: 85690a6 llvm-git-migration added a commit that references this issue on Jan 4, 2019 Merging r325946: ea0ca91 golang locked and limited conversation to collaborators on Feb 16, 2019 gopherbot added FrozenDueToAge on Feb 16, 2019 dvyukov added Security on May 15, 2019 rsc removed their assignment on Jun 23, 2022 Sign up for free to join this conversation on GitHub.
Already have an account? Sign in to comment Metadata Metadata Assignees No one assigned Labels FrozenDueToAge Security Type No type Projects No projects Milestone Go1.10 Relationships None yet Development No branches or pull requests Issue actions You can’t perform that action at this time.