Skip to content

proposal: os/exec: Add ability to limit or prohibit the use of spawning subprocess' #54621

@ecnepsnai

Description

@ecnepsnai

Background

The os/exec pacakge allows Go applications to spawn subprocesses, which can enable Go applications to interact with other executables on the system. This is a widely used practice, but presents a security risk for the running system.

Should the running application be impacted by a remote code execution vulnerability, the ability to spawn applications on the running system can pose a significant threat.

For example, a recurring trend on other langues like Go is malicious third-party packages that contain cryptocurrency mining malware, or "cryptominers". Typically, these malicious packages don't actually contain the mining code in package itself, but rather code that downloads a malicious binary and runs it, as reported on by Bleeping Computer

Some operating systems provide mechanisms to limit process spawning, such as Security Enhanced Linux (SELinux), or Windows AppLocker, however not all of the supported OS targets of Go offer such features. Additionally, these features can be difficult to configure and are often disabled.

Proposal

As an optional security hardening measure for Go applications, I am proposing that we add the ability to restrict or prohibit the use of spawning subprocesses through os/exec.

In cases where the functionality is disabled, no subprocesses can be spawned through os/exec. However, we could provide an allowlist mechanism where only specific binaries may be executed by their path.

In an application where the developers know there will not be any need for spaning subprocesses, disabling that functionality provides a layer of defence. In the example of malicious packages above, this mechanism would prevent the malicious mining binary from being executed. This should not be seen as a complete defence, but an additional safeguard used in conjuction with others.

This feature should be opt-in so that existing applications are unaffected.

Design

Disabling spawning subprocesses

At build time, set the GOEXECDISABLED=1 environment variable.

Then, any calls to os/exec.Cmd.Start() return an error indicating that the functionality is disabled.

Restrict spwaning subprocesses

At build time, set the GOEXECALLOW="/usr/bin/foo:/usr/bin/bar" environment variable, which takes a colon separated list of files that can be executed by os/exec. If GOEXECDISABLED is specified, it would take precedence over this.

Then, any calls to os/exec.Cmd.Start() return an error if the execuable path is not in the allowlist, otherwise it is executed normally.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions