8000 gh-104432: Use `memcpy()` to avoid misaligned loads by chrstphrchvz · Pull Request #104433 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-104432: Use memcpy() to avoid misaligned loads #104433

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jul 27, 2023

Conversation

chrstphrchvz
Copy link
Contributor
@chrstphrchvz chrstphrchvz commented May 12, 2023

@bedevere-bot
Copy link

A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated.

Once you have made the requested changes, please leave a comment on this pull request containing the phrase I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

Co-authored-by: Gregory P. Smith <greg@krypto.org>
@chrstphrchvz
Copy link
Contributor Author

I have made the requested changes; please review again

@bedevere-bot
Copy link

Thanks for making the requested changes!

@gpshead: please review the changes made to this pull request.

@bedevere-bot bedevere-bot requested a review from gpshead May 13, 2023 22:44
@chrstphrchvz chrstphrchvz changed the title gh-104432: Use memcpy() to avoid misaligned loads gh-104432: Use memcpy() to avoid misaligned loads Jul 23, 2023
@gpshead gpshead added type-bug An unexpected behavior, bug, or error needs backport to 3.11 only security fixes needs backport to 3.12 only security fixes labels Jul 27, 2023
@gpshead gpshead self-assigned this Jul 27, 2023
@gpshead gpshead enabled auto-merge (squash) July 27, 2023 18:49
@gpshead gpshead merged commit f01e4ce into python:main Jul 27, 2023
@miss-islington
Copy link
Contributor

Thanks @chrstphrchvz for the PR, and @gpshead for merging it 🌮🎉.. I'm working now to backport this PR to: 3.11, 3.12.
🐍🍒⛏🤖

@bedevere-bot
Copy link

GH-107355 is a backport of this pull request to the 3.12 branch.

@bedevere-bot bedevere-bot removed the needs backport to 3.12 only security fixes label Jul 27, 2023
@bedevere-bot
Copy link

GH-107356 is a backport of this pull request to the 3.11 branch.

@bedevere-bot bedevere-bot removed the needs backport to 3.11 only security fixes label Jul 27, 2023
miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Jul 27, 2023
…04433)

Fix potential unaligned memory access on C APIs involving returned sequences
of `char *` pointers within the :mod:`grp` and :mod:`socket` modules. These
were revealed using a ``-fsaniziter=alignment`` build on ARM macOS.
(cherry picked from commit f01e4ce)

Co-authored-by: Christopher Chavez <chrischavez@gmx.us>
miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Jul 27, 2023
…04433)

Fix potential unaligned memory access on C APIs involving returned sequences
of `char *` pointers within the :mod:`grp` and :mod:`socket` modules. These
were revealed using a ``-fsaniziter=alignment`` build on ARM macOS.
(cherry picked from commit f01e4ce)

Co-authored-by: Christopher Chavez <chrischavez@gmx.us>
@chrstphrchvz chrstphrchvz deleted the patch-104432 branch July 27, 2023 19:37
gpshead pushed a commit that referenced this pull request Jul 27, 2023
#107355)

gh-104432: Use `memcpy()` to avoid misaligned loads (GH-104433)

Fix potential unaligned memory access on C APIs involving returned sequences
of `char *` pointers within the :mod:`grp` and :mod:`socket` modules. These
were revealed using a ``-fsaniziter=alignment`` build on ARM macOS.
(cherry picked from commit f01e4ce)

Co-authored-by: Christopher Chavez <chrischavez@gmx.us>
@@ -0,0 +1,4 @@
Fix potential unaligned memory access on C APIs involving returned sequences
of `char *` pointers within the :mod:`grp` and :mod:`socket` modules. These
were revealed using a ``-fsaniziter=alignment`` build on ARM macOS. Patch by
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To clarify, I observed this on macOS for Intel. I have not confirmed if this also occurs on macOS for ARM, but I would not be surprised if it still does.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops I shouldn't have bothered mentioning the architecture. no big deal though (feel free to make an edit PR if it bothers you).

I chose the word "revealed" in the wording as a way to indicate how it was found which is more interesting. I suspect the alignment sanitizer may flag this regardless of compilation target architecture but I didn't try to reproduce it myself. :)

I expect the fixup applies all over the place. Regardless of native transparent hardware support (x86) or triggering a trap to the OS to fix the unaligned access up (Alpha & a pile of very RISC thing) they are usually less efficient - so directly using code that detects it and does it right rather than triggering an even slower path is good.

gpshead pushed a commit that referenced this pull request Jul 28, 2023
#107356)

gh-104432: Use `memcpy()` to avoid misaligned loads (GH-104433)

Fix potential unaligned memory access on C APIs involving returned sequences
of `char *` pointers within the :mod:`grp` and :mod:`socket` modules. These
were revealed using a ``-fsaniziter=alignment`` build on ARM macOS.
(cherry picked from commit f01e4ce)

Co-authored-by: Christopher Chavez <chrischavez@gmx.us>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

Successfully merging this pull request may close these issues.

UBSan misaligned load errors in gethost_common(), mkgrent()
4 participants
0