Skip to content
Threat Feed
high advisory

Golang Go: Arbitrary code execution and file writing in cgo build process (CVE-2026-97035)

The Go toolchain's cmd/go component is vulnerable to arbitrary code execution and arbitrary file writes during build time when processing malicious packages using cgo, due to improper flag allowlisting.

CVE search metadata

CVE search record: CVE-2026-97035. Severity: high. CVSS: 8.8. EPSS: 0.25%. KEV: no. Product: cmd/go. Brief: Golang Go: Arbitrary code execution and file writing in cgo build process (CVE-2026-97035). Brief link: https://feed.craftedsignal.io/briefs/2026-11-golang-go-cgo-build-vulnerability-cve-2026-97035/

Triage facts

Revision 1
Applicability
cmd/go
Evidence
Unknown
Severity
High
Sources
2 public sources
Freshness
Revision 1Nov 16, 23:46 UTC
Vulnerabilities
1 CVE
Source quality
A2Roughly even chance

Overview

The Go toolchain's cmd/go component is affected by CVE-2026-97035, where the -g* wildcard in compiler and linker flag allowlists improperly matches certain Clang and GCC flags. Specifically, -gen-* (e.g., -gen-cdb-fragment-path) and -gnat* (e.g., -gnatO) flags in #cgo directives permit compilation database fragments or sidecar output files to be written to arbitrary directories. This desynchronizes flag argument parsing between the go command and the compiler driver, allowing subsequent arguments to be passed as unvalidated positional inputs to the linker, which can lead to unexpected code execution at build time.

Attack Chain

An attacker can construct a malicious Go package containing #cgo directives that use the disallowed -gen-* or -gnat* flags. When this package is built, the cmd/go tool processes these flags, potentially resulting in arbitrary file writes or the injection of unvalidated positional arguments to the linker.

Impact

Successful exploitation allows an attacker to achieve arbitrary code execution during the package build process or write files to arbitrary directories on the build system.

Recommendation

The Go project now disallows the use of -gen-* and -gnat* flags in #cgo compiler and linker flags. Users should upgrade to Go versions 1.26.11 or 1.27.4 or later.

Threat Hunt

Identify Go build processes or CGO compilation activities that reference '-gen-' or '-gnat' flags within '#cgo' directives, which are now disallowed as they allow for arbitrary file writes and potential code execution.

T1195.002 high high confidence hunt now

Data: Process command-line arguments, File system activity, Source code/build configuration analysis