Skip to content

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

Closed
@chrstphrchvz

Description

@chrstphrchvz

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

Metadata

Metadata

Assignees

Labels

3.11only security fixes3.12only security fixesOS-macextension-modulesC modules in the Modules dirtype-bugAn unexpected behavior, bug, or error

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions