mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Rich Felker <dalias@libc.org>
To: musl@lists.openwall.com
Subject: Re: thoughts on reallocarray, explicit_bzero?
Date: Mon, 19 May 2014 12:58:57 -0400	[thread overview]
Message-ID: <20140519165857.GQ507@brightrain.aerifal.cx> (raw)
In-Reply-To: <CAPLrYERvsFF=0UN-gRchd7zY0ViKNf6QA5bt7Oj5mGcxpLzbdA@mail.gmail.com>

On Mon, May 19, 2014 at 06:45:08PM +0200, Daniel Cegiełka wrote:
> 2014-05-19 18:25 GMT+02:00 Szabolcs Nagy <nsz@port70.net>:
> 
> > i don't see how the openbsd explicit_bzero stops the
> > compiler to do optimizations..
> >
> > (i guess they rely on that their gcc does not do lto
> > or that libc is dynamic linked and the compiler has no
> > 'explicit_bzero' builtin, neither of which is a great
> > solution..)
> >
> > the usual approach to this is volatile function pointer:
> >
> > static void *(*volatile force_memset)(void,int,size_t) = memset;
> >
> > in general in c one cannot be sure that the secret bits
> > are not leaked somewhere since the languge spec cannot
> > give such guarantees
> >
> > that said either the volatile funcptr or actually reusing
> > the memory such that it cannot be optimized away works in
> > practice
> 
> first version:
> 
> void explicit_bzero(void * const b, const size_t l)
> {
>     volatile unsigned char *p = (volatile unsigned char *) b;
>     size_t i = (size_t) 0U;
> 
>     while (i < l) {
>         p[i++] = 0U;
>     }
> }
> 
> Of course, if someone has better ideas... I'm very curious :)

I'm pretty sure this does not work. The volatile pointer cast (which
BTW is not necessary; it happens implicitly) does not, as far as I can
tell, mean "access the object via an overlapped volatile object".
Rather, it just means that the compiler cannot _automatically_ assume
the pointed-to object is non-volatile. It's still free to determine
via other means (e.g. inter-procedural analysis/LTO/etc.) that the
pointed-to object is non-volatile (and of course, in cases where this
matters, that its lifetime is ending) and thereby optimize out the
whole thing as dead code.

Rich


  reply	other threads:[~2014-05-19 16:58 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-05-19 15:31 Isaac Dunham
2014-05-19 15:43 ` Rich Felker
2014-05-19 16:19   ` Daniel Cegiełka
2014-05-20  6:19     ` Rich Felker
2014-05-20 15:50       ` Daniel Cegiełka
2014-05-19 15:44 ` Daniel Cegiełka
2014-05-19 16:16   ` Rich Felker
2014-05-19 16:30     ` Daniel Cegiełka
2014-05-19 16:32     ` Szabolcs Nagy
2015-01-28 22:01     ` Daniel Cegiełka
2015-01-28 22:34       ` Daniel Cegiełka
2015-01-28 22:38         ` Nathan McSween
2015-01-28 22:54           ` Daniel Cegiełka
2015-01-28 23:02             ` Josiah Worcester
2015-01-29  2:19         ` Rich Felker
2015-01-29  4:03           ` Brent Cook
2015-01-29  4:15             ` Rich Felker
2015-01-29  9:30               ` Daniel Cegiełka
2015-01-29 10:04                 ` Szabolcs Nagy
2015-01-29 10:31                   ` Daniel Cegiełka
2015-01-29 10:54                   ` Daniel Cegiełka
2014-05-19 16:25 ` Szabolcs Nagy
2014-05-19 16:45   ` Daniel Cegiełka
2014-05-19 16:58     ` Rich Felker [this message]
2014-05-19 16:55   ` Rich Felker
2014-05-19 18:12     ` Szabolcs Nagy
2014-05-19 22:08   ` Andy Lutomirski
2014-05-20  0:41     ` Szabolcs Nagy
2014-06-11  9:59   ` Thorsten Glaser
2014-06-11 12:59     ` Rich Felker

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20140519165857.GQ507@brightrain.aerifal.cx \
    --to=dalias@libc.org \
    --cc=musl@lists.openwall.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).