You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Memory sanitizer generates false positives on data returned by os.getrandom() #148850
When python is built with memory sanitizer enabled, reading any data returned by os.getrandom() will trigger a memory sanitizer false positive, because the buffer is filled using a syscall, and the memory isn't marked as having been written to.
Currently,
$ cat test.py
import os
data = os.getrandom(32)
h = data.hex()
print(f'h={h}')
$ ./python ./test.py
Uninitialized bytes in memchr at offset 18 inside [0x707000006458, 66)
==242471==WARNING: MemorySanitizer: use-of-uninitialized-value
...
SUMMARY: MemorySanitizer: use-of-uninitialized-value /home/peter/dev/pvanvugt-cpython/Objects/stringlib/fastsearch.h:58:13 in ucs1lib_find_char
Exiting
I have verified that applying __masan_unpoison() to the data fixes this.
Is __masan_unpoison available everywhere? isn't it possible to suppress this without this builtin call? because it may not be portable enough on all PEP-11 platforms and compilers. Is it also a possible issue in MSAN itself? can we fix it using some build options instead?
Yes, __msan_unpoison is available on any platform with (clang-style) MSAN support. That's not all PEP-11 platforms, but that's OK.
We already use __msan_unpoison in a bunch of places.
See also #11375. 2018 was a different time though :)
I'd prefer adding a wrapper macro to pyport.h, in the spirit of _Py_MEMORY_SANITIZER or _Py_NO_SANITIZE_THREAD: e.g. _Py_MSAN_UNPOISON(p, sz) should call __msan_unpoison if it's available, and do nothing otherwise.
Activity
picnixz commentedon Apr 22, 2026
Is
__masan_unpoisonavailable everywhere? isn't it possible to suppress this without this builtin call? because it may not be portable enough on all PEP-11 platforms and compilers. Is it also a possible issue in MSAN itself? can we fix it using some build options instead?encukou commentedon Apr 22, 2026
Yes,
__msan_unpoisonis available on any platform with (clang-style) MSAN support. That's not all PEP-11 platforms, but that's OK.We already use
__msan_unpoisonin a bunch of places.See also #11375. 2018 was a different time though :)
I'd prefer adding a wrapper macro to
pyport.h, in the spirit of_Py_MEMORY_SANITIZERor_Py_NO_SANITIZE_THREAD: e.g._Py_MSAN_UNPOISON(p, sz)should call__msan_unpoisonif it's available, and do nothing otherwise.petervanvugt commentedon Apr 23, 2026
Thank you, @encukou , #148851 has been updated per your feedback.
pythongh-148850: Fix msan false positive in os.getrandom
gh-148850: Fix memory sanitizer false positive in os.getrandom (GH-14…