From: Florian Weimer <fweimer@redhat.com>
To: Zack Weinberg <zackw@panix.com>
Cc: Joseph Myers <joseph@codesourcery.com>,
GNU C Library <libc-alpha@sourceware.org>
Subject: Re: arc4random
Date: Sat, 30 Sep 2017 06:22:00 -0000 [thread overview]
Message-ID: <be62b836-34db-26d5-8d27-72a315449a89@redhat.com> (raw)
In-Reply-To: <CAKCAbMhfO-0wT9oJcAbRQquz3iBkJuVeejk4su73FmhUgG-C6Q@mail.gmail.com>
On 09/30/2017 01:58 AM, Zack Weinberg wrote:
>> I think I found a way to do full fork protection even without
>> MADV_WIPEONFORK, using a global counter in a MAP_SHARED segment. Reseeding
>> is still needed to deal with a counter overflow on 32-bit architectures, and
>> there is some overhead by the globally shared counter, but I think it is
>> superior to all approaches I've seen so far (and it does not require a fork
>> handler or a system call for every random number generation).
>
> Is the idea that after a fork, processes may share RNG state but they
> see each others' counter increments so they won't return the same
> random bits from paired calls? Kind of like how it would work for
> multiple threads with a shared but atomically accessed RNG state?
Exactly. There's also a per-thread cache of an output block from the
underlying DRBG, but without MADV_WIPEONFORK, that's invalidated if
arc4random is called from multiple threads (because the global counter
does not match the expected value anymore). But at least it's not
necessary to acquire a lock around the actual cryptographic operation.
But all this is only possible for 64-bit atomics. If those are not
available, I'm not sure what we can do. The initial implementation will
have a 32-bit counter in the shared page and a lock (not shared across
processes) which is acquired around the entire arc4random operation. If
the 32-bit counter overflows, we need to replace the page with the
global state with a new one (using MAP_FIXED) and reinitialize the
secrets. I don't think we can use any of the usual techniques for
building a >32-bit counter from two 32-bit values because they rely on
flag bits and waiting, but the other process can die at any time, and a
waiting operation would get stuck at that point.
Thanks,
Florian
prev parent reply other threads:[~2017-09-30 6:22 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-09-29 23:58 arc4random (was Re: Remove add-ons mechanism) Zack Weinberg
2017-09-30 6:22 ` Florian Weimer [this message]
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=be62b836-34db-26d5-8d27-72a315449a89@redhat.com \
--to=fweimer@redhat.com \
--cc=joseph@codesourcery.com \
--cc=libc-alpha@sourceware.org \
--cc=zackw@panix.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.
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 read-only IMAP folder(s) and NNTP newsgroup(s).