Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

What does safe mean here? Everything can be interpreted as a [u8], right?


[u8] guarantees to the compiler that two reads through the array at the same location without any intervening writes return the same value.

Turns out that's not the case on freshly returned uninitiated allocations. The first read could return old data (say "1"), and the second read could return a freshly zeroed page ("0").


No, it's not so.

If the allocation is backed by the kernel, then it will be zero-filled for security reasons. If it's backed by user-space malloc then who knows; but there's never a scenario where a mallocated page is quietly replaced by a zero-filled page behind the scenes.


Ctrl-f tautology in the article, it turns out that is not the case because of madvise free.


https://www.ralfj.de/blog/2019/07/14/uninit.html perhaps (the OP also talks about this when linking to a talk about jemalloc)


Interesting.

Tl;dr: its not to do with any hardware concept, the compiler can substitute any value for a read of uninitialised memory, and the value does not have to be stable.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: