Skip to content

cmd/go: unexpected code execution and arbitrary file write via Clang -gen-* and GCC -gnat* flags in cgo #82575

Closed

Description

@nicholashusin

When using Clang or GCC, building a malicious package that uses cgo could cause
unexpected code execution at build time or write files to arbitrary
directories via "-gen-" or "-gnat" flags in "#cgo" directives.

The "-g*" wildcard in the compiler and linker flag allowlists previously
matched Clang's two-argument "-gen-cdb-fragment-path

" flag and GCC's
two-argument "-gnatO " flag, permitting compilation database fragments
and sidecar output files to be written to arbitrary directories and
desynchronizing flag argument parsing between the go command and the compiler
driver so that subsequent arguments could be passed as unvalidated positional
inputs to the linker.

"-gen-" and "-gnat" flags are now disallowed in "#cgo" compiler and linker
flags.

This issue was found by the Go Security Team during an internal audit.

This is CVE-2026-97035 and Go issue https://go.dev/issue/82575.


This was a PRIVATE track issue originally tracked in http://b/568055959.

Activity

  1. added this to the Go1.28 milestone on Oct 26, 2026
  2. nicholashusin commented on Oct 26, 2026

    @nicholashusin
    MemberAuthor

    Hi @gopherbot, please open backport issues for this security issue.

  3. gopherbot commented on Oct 26, 2026

    @gopherbot
    Contributor

    Backport issue(s) opened: #82595 (for 1.26), #82596 (for 1.27).

    Remember to create the cherry-pick CL(s) as soon as the patch is submitted to master, according to https://go.dev/wiki/MinorReleases.

  4. gopherbot commented on Nov 10, 2026

    @gopherbot
    Contributor

    Change https://go.dev/cl/861486 mentions this issue: [release-branch.go1.27] cmd/go: disallow -gen-* and -gnat* in flag allowlists

  5. gopherbot commented on Nov 10, 2026

    @gopherbot
    Contributor

    Change https://go.dev/cl/861525 mentions this issue: [release-branch.go1.26] cmd/go: disallow -gen-* and -gnat* in flag allowlists

  6. changed the title [-]security: fix CVE-2026-97035[/-] [+]cmd/go: unexpected code execution and arbitrary file write via Clang -gen-* and GCC -gnat* flags in cgo[/+] on Nov 10, 2026
  7. gopherbot commented on Nov 10, 2026

    @gopherbot
    Contributor

    Change https://go.dev/cl/862148 mentions this issue: cmd/go: disallow -gen-* and -gnat* in flag allowlists

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions