On Mon, 10 Aug 2020, Amit Kulkarni wrote:

> moving to tech@
> 
> ---------- Forwarded message ---------
> From: Philipp Klaus Krause <p...@spth.de>
> Date: Mon, Aug 10, 2020 at 4:34 AM
> Subject: explicit_bzero vs. alternatives
> To: <m...@openbsd.org>
> 
> 
> OpenBSD has the explicit_bzero function to reliably (i.e. even if not
> observable in the C abstract machine) overwrite memory with zeroes.
> 
> WG14 is currently considering adding similar functionality to C2X.
> 
> Considered options include:
> 
> * A function like explicit_bzero or memset_explicit, that overwrites the
> memory with a known value.
> * A function like memclear, that overwrites the memory in an
> implementation-defined manner, possibly using random data.
> 
> Is there a rationale why OpenBSD went with their explicit_bzero design?
> Were alternatives considered and rejected?

We went with explict_bzero because our only use-case for this was
safe erasure that could not be elided by the compiler.

I don't see any need for explicit_memset() - if anything depends on
the overwritten value then simple memset() should be sufficient as
the compiler should detect the dependency and refuse to elide the
memset() to begin with.

Likewise, I can see no benefit for overwriting with random data. Doing
this is always going to be more expensive and more likely to leak
secrets, e.g. the length of cleared objects.

Hopefully C2X is taking a more broad approach to this problem than
considering new library calls. Over-eager optimisation (especially when
done at link-time over the whole program) is a major for anyone trying
to write safe C code.

-d

Reply via email to