linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Theodore Ts'o" <tytso@mit.edu>
To: "Jason A. Donenfeld" <Jason@zx2c4.com>
Cc: linux-kernel@vger.kernel.org, linux-crypto@vger.kernel.org
Subject: Re: [PATCH] random: avoid superfluous call to RDRAND in CRNG extraction
Date: Thu, 30 Dec 2021 17:13:25 -0500	[thread overview]
Message-ID: <Yc4vBfiN529c06kI@mit.edu> (raw)
In-Reply-To: <20211230165052.2698-1-Jason@zx2c4.com>

On Thu, Dec 30, 2021 at 05:50:52PM +0100, Jason A. Donenfeld wrote:
> RDRAND is not fast. RDRAND is actually quite slow. We've known this for
> a while, which is why functions like get_random_u{32,64} were converted
> to use batching of our ChaCha-based CRNG instead.
> 
> Yet CRNG extraction still includes a call to RDRAND, in the hot path of
> every call to get_random_bytes(), /dev/urandom, and getrandom(2).
> 
> This call to RDRAND here seems quite superfluous. CRNG is already
> extracting things based on a 256-bit key, based on good entropy, which
> is then reseeded periodically, updated, backtrack-mutated, and so
> forth. The CRNG extraction construction is something that we're already
> relying on to be secure and solid. If it's not, that's a serious
> problem, and it's unlikely that mixing in a measly 32 bits from RDRAND
> is going to alleviate things.
> 
> There is one place, though, where such last-ditch moves might be
> quasi-sensible, and that's before the CRNG is actually ready. In that case,
> we're already very much operating from a position of trying to get
> whatever we can, so we might as well throw in the RDRAND call because
> why not.

So I'm not sure we how desperately we *need* the 370% performance
improvement, but realistically speaking, in
crng_init_try_arch_early(), which gets called from rand_initialize(),
we will have already set crng->state[4..15] via RDSEED or RDRAND.

So there's no point in setting crng->state[0] from RDRAND.  So if
we're wanting to speed things up, we should just remove the
crng->state[0] <= RDRAND entirely.

Or if we want to improve the security of get_random_bytes() pre
crng_ready(), then we should try to XOR RDRAND bytes into all returned
buffer from get_random_bytes().  In other words, I'd argue that we
should "go big, or go home".  (And if we do have some real,
security-critical users of get_random_bytes() pre-crng_ready(), maybe
"go big" is the right way to go.  Of course, if those do exist, we're
still screwed for those architectures which don't have an RDRAND or
equivalent --- arm32, RISC-V, I'm looking at you.)

					- Ted

  reply	other threads:[~2021-12-30 22:13 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-12-30 16:50 [PATCH] random: avoid superfluous call to RDRAND in CRNG extraction Jason A. Donenfeld
2021-12-30 22:13 ` Theodore Ts'o [this message]
2021-12-30 22:58   ` Jason A. Donenfeld
2021-12-31  3:35     ` Theodore Ts'o
2021-12-31 11:49       ` [PATCH v2] " Jason A. Donenfeld
2021-12-31 17:13         ` Theodore Ts'o
2022-01-04  5:03           ` Sandy Harris
2022-01-04  5:55             ` Theodore Ts'o
2022-01-20 15:03               ` Jason A. Donenfeld
2022-01-20 15:07                 ` [PATCH] random: use named fields for adjusting chacha state Jason A. Donenfeld
2022-01-20 17:50                   ` Theodore Ts'o
2022-01-20 21:53                     ` Jason A. Donenfeld
2022-01-05 15:28         ` [PATCH v2] random: avoid superfluous call to RDRAND in CRNG extraction Ard Biesheuvel

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=Yc4vBfiN529c06kI@mit.edu \
    --to=tytso@mit.edu \
    --cc=Jason@zx2c4.com \
    --cc=linux-crypto@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    /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 NNTP newsgroup(s).