Skip to content

cmd/go: reject cgo -sectcreate linker flags by default#80491

Open
carrerasdarren-cell wants to merge 1 commit into
golang:masterfrom
carrerasdarren-cell:fix-cgo-darwin-sectcreate-78750
Open

cmd/go: reject cgo -sectcreate linker flags by default#80491
carrerasdarren-cell wants to merge 1 commit into
golang:masterfrom
carrerasdarren-cell:fix-cgo-darwin-sectcreate-78750

Conversation

@carrerasdarren-cell

@carrerasdarren-cell carrerasdarren-cell commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

The Darwin linker -sectcreate option reads a file and embeds its contents.
The existing cgo linker allowlist accepts this option, so a dependency can
make go build read an arbitrary file available to the build process.

Reject file-backed -Wl,-sectcreate,... flags in package-provided #cgo
LDFLAGS by default. Preserve the established
-Wl,-sectcreate,__RESTRICT,__restrict,/dev/null hardening form because it
does not expose useful file contents. Trusted uses can explicitly opt in
with CGO_LDFLAGS_ALLOW, as with other rejected flags.

Add a script test for default rejection, explicit opt-in, and the preserved
hardening form.

Fixes #78750.

@gopherbot

Copy link
Copy Markdown
Contributor

This PR (HEAD: bfc86b7) has been imported to Gerrit for code review.

Please visit Gerrit at https://go-review.googlesource.com/c/go/+/803620.

Important tips:

  • Don't comment on this PR. All discussion takes place in Gerrit.
  • You need a Gmail or other Google account to log in to Gerrit.
  • To change your code in response to feedback:
    • Push a new commit to the branch used by your GitHub PR.
    • A new "patch set" will then appear in Gerrit.
    • Respond to each comment by marking as Done in Gerrit if implemented as suggested. You can alternatively write a reply.
    • Critical: you must click the blue Reply button near the top to publish your Gerrit responses.
    • Multiple commits in the PR will be squashed by GerritBot.
  • The title and description of the GitHub PR are used to construct the final commit message.
    • Edit these as needed via the GitHub web interface (not via Gerrit or git).
    • You should word wrap the PR description at ~76 characters unless you need longer lines (e.g., for tables or URLs).
  • See the Sending a change via GitHub and Reviews sections of the Contribution Guide as well as the FAQ for details.

@gopherbot

Copy link
Copy Markdown
Contributor

Message from Gopher Robot:

Patch Set 1:

(1 comment)


Please don’t reply on this GitHub thread. Visit golang.org/cl/803620.
After addressing review feedback, remember to publish your drafts!

@gopherbot

Copy link
Copy Markdown
Contributor

Message from Ian Lance Taylor:

Patch Set 2:

(1 comment)


Please don’t reply on this GitHub thread. Visit golang.org/cl/803620.
After addressing review feedback, remember to publish your drafts!

The Darwin linker reads the file named by -sectcreate and embeds its
contents in the output. Allowing dependency-supplied #cgo LDFLAGS to
use it lets a module read arbitrary files available to the build.

Reject file-backed uses by default. Preserve the established
__RESTRICT,__restrict,/dev/null form used for Darwin hardening, since
it cannot expose file contents. Users who explicitly trust another
use can retain the existing CGO_LDFLAGS_ALLOW override.

Fixes golang#78750.
@carrerasdarren-cell
carrerasdarren-cell force-pushed the fix-cgo-darwin-sectcreate-78750 branch from bfc86b7 to 26dcf14 Compare July 21, 2026 23:31
@gopherbot

Copy link
Copy Markdown
Contributor

This PR (HEAD: 26dcf14) has been imported to Gerrit for code review.

Please visit Gerrit at https://go-review.googlesource.com/c/go/+/803620.

Important tips:

  • Don't comment on this PR. All discussion takes place in Gerrit.
  • You need a Gmail or other Google account to log in to Gerrit.
  • To change your code in response to feedback:
    • Push a new commit to the branch used by your GitHub PR.
    • A new "patch set" will then appear in Gerrit.
    • Respond to each comment by marking as Done in Gerrit if implemented as suggested. You can alternatively write a reply.
    • Critical: you must click the blue Reply button near the top to publish your Gerrit responses.
    • Multiple commits in the PR will be squashed by GerritBot.
  • The title and description of the GitHub PR are used to construct the final commit message.
    • Edit these as needed via the GitHub web interface (not via Gerrit or git).
    • You should word wrap the PR description at ~76 characters unless you need longer lines (e.g., for tables or URLs).
  • See the Sending a change via GitHub and Reviews sections of the Contribution Guide as well as the FAQ for details.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

cmd/go: harden against cgo LDFLAGS allowing arbitrary file read at build time on darwin

2 participants