8000 UBSan misaligned load errors in `gethost_common()`, `mkgrent()` · Issue #104432 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

UBSan misaligned load errors in gethost_common(), mkgrent() #104432

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

Closed
chrstphrchvz opened this issue May 12, 2023 · 1 comment · Fixed by #104433
Closed

UBSan misaligned load errors in gethost_common(), mkgrent() #104432

chrstphrchvz opened this issue May 12, 2023 · 1 comment · Fixed by #104433
Assignees
Labels
3.11 only security fixes 3.12 only security fixes extension-modules C modules in the Modules dir OS-mac type-bug An unexpected behavior, bug, or error

Comments

@chrstphrchvz
Copy link
Contributor
chrstphrchvz commented May 12, 2023

test.test_asyncio.test_events.KqueueEventLoopTests.test_create_connection triggers -fsanitize=alignment errors on macOS (i.e. Darwin):

Modules/socketmodule.c:5790:34: runtime error: load of misaligned address 0x60d0001ca152 for type 'char *', which requires 8 byte alignment
0x60d0001ca152: note: pointer points here
 6f 73  74 00 62 a1 1c 00 d0 60  00 00 00 00 00 00 00 00  00 00 31 2e 30 2e 30 2e  31 32 37 2e 69 6e
              ^ 
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior Modules/socketmodule.c:5790:34 in 
Modules/socketmodule.c:5792:40: runtime error: load of misaligned address 0x60d0001ca152 for type 'char *', which requires 8 byte alignment
0x60d0001ca152: note: pointer points here
 6f 73  74 00 62 a1 1c 00 d0 60  00 00 00 00 00 00 00 00  00 00 31 2e 30 2e 30 2e  31 32 37 2e 69 6e
              ^ 
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior Modules/socketmodule.c:5792:40 in 
Modules/socketmodule.c:5804:32: runtime error: load of misaligned address 0x60d0001ca179 for type 'char *', which requires 8 byte alignment
0x60d0001ca179: note: pointer points here
 72 70 61  00 89 a1 1c 00 d0 60 00  00 00 00 00 00 00 00 00  00 7f 00 00 01 00 00 00  b9 96 6e cc b9
              ^ 
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior Modules/socketmodule.c:5804:32 in 
Modules/socketmodule.c:5817:35: runtime error: load of misaligned address 0x60d0001ca179 for type 'char *', which requires 8 byte alignment
0x60d0001ca179: note: pointer points here
 72 70 61  00 89 a1 1c 00 d0 60 00  00 00 00 00 00 00 00 00  00 7f 00 00 01 00 00 00  b9 96 6e cc b9
              ^ 
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior Modules/socketmodule.c:5817:35 in 

I believe this issue is also present in this line (but I am not aware if any tests cover it):

memcpy(&sin6.sin6_addr, *pch, sizeof(sin6.sin6_addr));

Likewise in test.test_grp.GroupDatabaseTestCase.test_errors:

Modules/grpmodule.c:68:30: runtime error: load of misaligned address 0x6080006331f4 for type 'char *', which requires 8 byte alignment
0x6080006331f4: note: pointer points here
  72 00 2a 00 00 00 00 00  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  10 32 63 00 80 60 00 00
              ^ 
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior Modules/grpmodule.c:68:30 in 
Modules/grpmodule.c:69:49: runtime error: load of misaligned address 0x60c00474bcdb for type 'char *', which requires 8 byte alignment
0x60c00474bcdb: note: pointer points here
 64  00 2a 00 eb bc 74 04 c0  60 00 00 00 00 00 00 00  00 00 00 5f 6b 6e 6f 77  6c 65 64 67 65 67 72
              ^ 
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior Modules/grpmodule.c:69:49 in 

To be clear, these tests pass, and the misaligned pointers are produced by the OS and not Python. The misaligned pointers appear to be a known issue, presumably one which Apple may never resolve (given these are functions inherited from BSD, and newer functions like getaddrinfo() are preferred according to man pages). The workaround is to use memcpy() (see e.g. php/php-src@26ac6cb).

Linked PRs

@chrstphrchvz chrstphrchvz added the type-bug An unexpected behavior, bug, or error label May 12, 2023
chrstphrchvz added a commit to chrstphrchvz/cpython that referenced this issue May 12, 2023
@gpshead gpshead self-assigned this Jul 27, 2023
@gpshead gpshead added 3.11 only security fixes 3.12 only security fixes OS-mac extension-modules C modules in the Modules dir labels Jul 27, 2023
gpshead pushed a commit that referenced this issue Jul 27, 2023
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.
miss-islington pushed a commit to miss-islington/cpython that referenced this issue 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 issue 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>
gpshead pushed a commit that referenced this issue 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>
@gpshead
Copy link
Member
gpshead commented Jul 27, 2023

thanks!

gpshead pushed a commit that referenced this issue 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
3.11 only security fixes 3.12 only security fixes extension-modules C modules in the Modules dir OS-mac type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants
@gpshead @chrstphrchvz and others
0