Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/go: packages using cgo can cause arbitrary code execution on Windows #43783

rolandshoemaker opened this issue Jan 19, 2021 · 2 comments


Copy link

@rolandshoemaker rolandshoemaker commented Jan 19, 2021

The go command may execute arbitrary code at build time when using cgo on Windows. This can be triggered by running go get for a malicious package, or any other time the code is built.

This can be triggered by malicious packages which contain specifically named binaries which are executed when cgo is executed in the context of the malicious package directory. This is due to the path lookup behavior of os/exec.LookPath on Windows.

This will also affect Unix users who have “.” listed explicitly in their PATH and are running “go get” outside of a module or with module mode disabled.

This has been fixed by altering the usage of os/exec.LookPath by the go command to reject the usage of any binaries that reside in the current directory. If you are interested in understanding whether your own programs have a problem, we’ve written a blog post about the underlying issue:

Thanks to RyotaK ( for reporting this issue.

This issue is CVE-2021-3115.

Copy link

@gopherbot gopherbot commented Jan 21, 2021

Change mentions this issue: cmd/go: pass resolved CC, GCCGO to cgo

Copy link

@gopherbot gopherbot commented Jan 21, 2021

Change mentions this issue: all: introduce and use internal/execabs

@gopherbot gopherbot closed this in 46e2e2e Jan 21, 2021
gopherbot pushed a commit that referenced this issue Jan 21, 2021
Introduces a wrapper around os/exec, internal/execabs, for use in
all commands. This wrapper prevents exec.LookPath and exec.Command from
running executables in the current directory.

All imports of os/exec in non-test files in cmd/ are replaced with
imports of internal/execabs.

This issue was reported by RyotaK.

Fixes CVE-2021-3115
Fixes #43783

Change-Id: I0423451a6e27ec1e1d6f3fe929ab1ef69145c08f
Reviewed-by: Russ Cox <>
Reviewed-by: Katie Hockman <>
Run-TryBot: Roland Shoemaker <>
Reviewed-by: Katie Hockman <>
Trust: Roland Shoemaker <>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants