Re:Stop Memsetting Structures
by blattimwind on Saturday April 27, 2019 @09:00PM
(#19768649)
Also don't expect memset() to actually be a library call at all.
[ Parent
| on HN ]
And most importantly dont expect memset to be executed at all. Most -O2 compilers happily optimize the memset away if if doesn't care about the sideeffects. Therefore there exists the "secure" memset variants, which are the insecure variants adding a simple compiler barrier, so it isn't optimized away.
And there exists the very few really secure memset_s variants with a real memory barrier which guarantees memset to be executed in load and store order, flushing the cache, so that Spectre attacks are mitigated. security-relevant crypto libraries, like openssl and variants don't care about that, because memory barriers are "too slow". only the Linux kernel does it properly. It's still a mess.
Re:Stop Memsetting Structures
by FrozenVoid on Sunday April 28, 2019 @12:21AM
(#19769331)
you can write your own memset that bypasses all of that.
Its just 2 lines of code.
And that will be slower than calling memset() unless you have a really smart compiler.
I don't trust any memset at all. Literally every single memset I looked at was either broken, too slow or insecure.
Mostly the wellknown glibc, freebsd, msvcrt and compiler implementations.
That's quite a bold claim. Care to explain further?