Skip to content

unix: align Ifreq so its union accessors cannot fault - #287

Closed
shalseth wants to merge 1 commit into
golang:masterfrom
shalseth:sparc64-ifreq
Closed

unix: align Ifreq so its union accessors cannot fault#287
shalseth wants to merge 1 commit into
golang:masterfrom
shalseth:sparc64-ifreq

Conversation

@shalseth

@shalseth shalseth commented Aug 23, 2026

Copy link
Copy Markdown
Contributor

Uint16, SetUint16, Uint32, SetUint32, Inet4Addr and SetInet4Addr cast the
ifreq union to uint16, uint32 or RawSockaddrInet4 and access it in place.
The generated ifreq declares that union as a byte array, so the type
guarantees only byte alignment and the compiler may put an Ifreq at any
address - as it does for the elements of a []Ifreq, which pack at the
struct's size with an alignment of one.

A misaligned access is merely slow on amd64 and arm64; on sparc64 it
faults, and TestIoctlIfreq died with SIGBUS.

Align the wrapper rather than changing the accessors. The union lies at
offset 16 within ifreq on every architecture, so aligning the wrapper
aligns the union, and all six accessors are covered instead of only the
four integer ones.

TestIfreqAlignment pins the invariant. Without the fix it fails on every
architecture, reporting an alignment of 1, so catching a regression does
not need sparc64 hardware.

Updates golang/go#55000

@gopherbot

Copy link
Copy Markdown
Contributor

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

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

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/820000.
After addressing review feedback, remember to publish your drafts!

@gopherbot

Copy link
Copy Markdown
Contributor

Message from Gopher Robot:

Patch Set 1:

Congratulations on opening your first change. Thank you for your contribution!

Next steps:
A maintainer will review your change and provide feedback. See
https://go.dev/doc/contribute#review for more info and tips to get your
patch through code review.

Most changes in the Go project go through a few rounds of revision. This can be
surprising to people new to the project. The careful, iterative review process
is our way of helping mentor contributors and ensuring that their contributions
have a lasting impact.

During May-July and Nov-Jan the Go project is in a code freeze, during which
little code gets reviewed or merged. If a reviewer responds with a comment like
R=go1.11 or adds a tag like "wait-release", it means that this CL will be
reviewed as part of the next development cycle. See https://go.dev/s/release
for more details.


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

@gopherbot

Copy link
Copy Markdown
Contributor

Message from Stian Halseth:

Patch Set 2:

(2 comments)


Please don’t reply on this GitHub thread. Visit golang.org/cl/820000.
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/820000.
After addressing review feedback, remember to publish your drafts!

@shalseth shalseth changed the title unix: avoid unaligned loads in the Ifreq union accessors unix: align Ifreq so its union accessors cannot fault Aug 24, 2026
@gopherbot

Copy link
Copy Markdown
Contributor

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

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

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 Stian Halseth:

Patch Set 3:

(1 comment)


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

@gopherbot

Copy link
Copy Markdown
Contributor

Message from Ian Lance Taylor:

Patch Set 3: Auto-Submit+1 Code-Review+2 Commit-Queue+1

(1 comment)


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

@gopherbot

Copy link
Copy Markdown
Contributor

Message from golang-scoped@luci-project-accounts.iam.gserviceaccount.com:

Patch Set 3:

Dry run: CV is trying the patch.

Bot data: {"action":"start","triggered_at":"2026-08-24T18:54:20Z","revision":"d497ef75ba518b96f76efd842f85c3a146911661"}


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

@gopherbot

Copy link
Copy Markdown
Contributor

Message from Ian Lance Taylor:

Patch Set 3: -Commit-Queue

(Performed by <GERRIT_ACCOUNT_60063> on behalf of <GERRIT_ACCOUNT_5206>)


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

@gopherbot

Copy link
Copy Markdown
Contributor

Message from golang-scoped@luci-project-accounts.iam.gserviceaccount.com:

Patch Set 3:

This CL has failed the run. Reason:

Tryjob golang/try/x_sys-gotip-linux-386 has failed with summary (view all results):


To reproduce, try gomote repro 8672561707948982449.

Additional links for debugging:


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

@gopherbot

Copy link
Copy Markdown
Contributor

Message from golang-scoped@luci-project-accounts.iam.gserviceaccount.com:

Patch Set 3: LUCI-TryBot-Result-1


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

@gopherbot

Copy link
Copy Markdown
Contributor

Message from Ian Lance Taylor:

Patch Set 3: -Auto-Submit -Code-Review

(1 comment)


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

Uint16, SetUint16, Uint32, SetUint32, Inet4Addr and SetInet4Addr cast the
ifreq union to uint16, uint32 or RawSockaddrInet4 and access it in place.
The generated ifreq declares that union as a byte array, so the type
guarantees only byte alignment and the compiler may put an Ifreq at any
address - as it does for the elements of a []Ifreq, which pack at the
struct's size with an alignment of one.

A misaligned access is merely slow on amd64 and arm64; on sparc64 it
faults, and TestIoctlIfreq died with SIGBUS.

Align the wrapper rather than changing the accessors. The union lies at
offset 16 within ifreq on every architecture, so aligning the wrapper
aligns the union, and all six accessors are covered instead of only the
four integer ones.

TestIfreqAlignment pins the invariant. Without the fix it fails on every
architecture, reporting an alignment of 1, so catching a regression does
not need sparc64 hardware.

Updates golang/go#55000

Change-Id: I9c5c04515c42702ffec583881b09745f6a52b167
@gopherbot

Copy link
Copy Markdown
Contributor

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

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

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 Stian Halseth:

Patch Set 4:

(1 comment)


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

@gopherbot

Copy link
Copy Markdown
Contributor

Message from Ian Lance Taylor:

Patch Set 4: Commit-Queue+1


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

@gopherbot

Copy link
Copy Markdown
Contributor

Message from golang-scoped@luci-project-accounts.iam.gserviceaccount.com:

Patch Set 4:

Dry run: CV is trying the patch.

Bot data: {"action":"start","triggered_at":"2026-08-25T05:01:43Z","revision":"a6f78ab5cd4df617dd12f22c7c192b55aec1e2e8"}


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

@gopherbot

Copy link
Copy Markdown
Contributor

Message from Ian Lance Taylor:

Patch Set 4: -Commit-Queue

(Performed by <GERRIT_ACCOUNT_60063> on behalf of <GERRIT_ACCOUNT_5206>)


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

@gopherbot

Copy link
Copy Markdown
Contributor

Message from golang-scoped@luci-project-accounts.iam.gserviceaccount.com:

Patch Set 4:

This CL has passed the run


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

@gopherbot

Copy link
Copy Markdown
Contributor

Message from golang-scoped@luci-project-accounts.iam.gserviceaccount.com:

Patch Set 4: LUCI-TryBot-Result+1


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

@gopherbot

Copy link
Copy Markdown
Contributor

Message from Ian Lance Taylor:

Patch Set 4: Code-Review+2

(1 comment)


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

@gopherbot

Copy link
Copy Markdown
Contributor

Message from David Chase:

Patch Set 4: Code-Review+1


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

gopherbot pushed a commit that referenced this pull request Aug 25, 2026
Uint16, SetUint16, Uint32, SetUint32, Inet4Addr and SetInet4Addr cast the
ifreq union to uint16, uint32 or RawSockaddrInet4 and access it in place.
The generated ifreq declares that union as a byte array, so the type
guarantees only byte alignment and the compiler may put an Ifreq at any
address - as it does for the elements of a []Ifreq, which pack at the
struct's size with an alignment of one.

A misaligned access is merely slow on amd64 and arm64; on sparc64 it
faults, and TestIoctlIfreq died with SIGBUS.

Align the wrapper rather than changing the accessors. The union lies at
offset 16 within ifreq on every architecture, so aligning the wrapper
aligns the union, and all six accessors are covered instead of only the
four integer ones.

TestIfreqAlignment pins the invariant. Without the fix it fails on every
architecture, reporting an alignment of 1, so catching a regression does
not need sparc64 hardware.

Updates golang/go#55000

Change-Id: I70aca33419086de9eb68032e354e5f666cc20562
GitHub-Last-Rev: 637b50d
GitHub-Pull-Request: #287
Reviewed-on: https://go-review.googlesource.com/c/sys/+/820000
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Reviewed-by: David Chase <drchase@google.com>
LUCI-TryBot-Result: golang-scoped@luci-project-accounts.iam.gserviceaccount.com <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
@gopherbot

Copy link
Copy Markdown
Contributor

This PR is being closed because golang.org/cl/820000 has been merged.

@gopherbot gopherbot closed this Aug 25, 2026
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.

2 participants