GrapheneOS / hardened_malloc

Hardened allocator designed for modern systems. It has integration into Android's Bionic libc and can be used externally with musl and glibc as a dynamic library for use on other Linux-based platforms. It will gain more portability / integration over time.
https://grapheneos.org/
MIT License
1.26k stars 96 forks source link

malloc(0) should allow over-fetching #204

Closed jreiser closed 2 years ago

jreiser commented 2 years ago

malloc(0) currently returns a pointer into a page that has no Read and no Write access. Instead, the page should allow Read, so that a program can "over-fetch" without triggering SIGSEGV. Of course it is a logical error to use any of the fetched bytes, but delaying the effective check for logically-permitted access (such as by checking independently for length of zero) can be useful to increase speed by overlapping the check with the fetch.

thestinger commented 2 years ago

I don't see a reason to permit read access. It's undefined behavior to read the memory.