[RFC] [PATCH] Support explicit_bzero, memset_s, memzero_explicit, or similar.
Florian Weimer
fweimer@redhat.com
Wed Dec 17 12:32:00 GMT 2014
On 12/16/2014 07:01 PM, Rich Felker wrote:
> But in the case of a function like:
>
> int foo = 42;
> memset(&foo, 0, sizeof foo);
> __asm__ __volatile__ ( "" : : : "memory" );
>
> after analysis based on compiler knowledge of the memset function, the
> object foo is not "memory" because its address has never leaked. Since
> the asm cannot see it, it can be optimized out to never exist at all
> independently of handling the asm. If this weren't the case, presence
> of asm with memory clobbers anywhere in the whole program would
> prevent the compiler from optimizing out objects like this anywhere in
> the whole program, which is obviously not correct.
Curiously, this is the case where use of memset_s would *force* the
creation of a copy of the value, just so that it can be zapped immediately:
<https://gcc.gnu.org/ml/gcc-help/2014-10/msg00071.html>
--
Florian Weimer / Red Hat Product Security
More information about the Libc-alpha
mailing list