Skip to content

Memory sanitizer generates false positives on data returned by os.getrandom() #148850

@petervanvugt

Description

@petervanvugt

Bug report

Bug description:

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.

CPython versions tested on:

CPython main branch

Operating systems tested on:

Linux

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    extension-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