All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Jason A. Donenfeld" <Jason@zx2c4.com>
To: linux-kernel@vger.kernel.org,
	Dominik Brodowski <linux@dominikbrodowski.net>,
	"Theodore Ts'o" <tytso@mit.edu>,
	Hsin-Yi Wang <hsinyi@chromium.org>,
	"Ivan T. Ivanov" <iivanov@suse.de>,
	Ard Biesheuvel <ardb@kernel.org>,
	linux-efi@vger.kernel.org
Cc: "Jason A. Donenfeld" <Jason@zx2c4.com>
Subject: [PATCH v7 4/4] random: mix bootloader randomness into pool
Date: Tue, 28 Dec 2021 16:38:26 +0100	[thread overview]
Message-ID: <20211228153826.448805-4-Jason@zx2c4.com> (raw)
In-Reply-To: <20211228153826.448805-1-Jason@zx2c4.com>

If we're trusting bootloader randomness, crng_fast_load() is called by
add_hwgenerator_randomness(), which sets us to crng_init==1. However, if
it's not called after that initial 64-byte push, it won't additionally
mix any bytes into the entropy pool. So it's conceivable that
crng_init==1 when later crng_initialize_primary() is called, but the
entropy pool is empty. When that happens, the crng state key will then
be overwritten with extracted output from the empty input pool. That's
bad.

In contrast, if we're not trusting bootloader randomness, we call
crng_slow_load() *and* we call mix_pool_bytes(), so that later
crng_initialize_primary() isn't drawing on nothing.

In order to prevent crng_initialize_primary() from extracting an empty
pool, have the trusted bootloader case mirror that of the untrusted
bootloader case, mixing the input into the pool.

Cc: Dominik Brodowski <linux@dominikbrodowski.net>
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
---
 drivers/char/random.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/char/random.c b/drivers/char/random.c
index 020443e34603..3499f6762ac1 100644
--- a/drivers/char/random.c
+++ b/drivers/char/random.c
@@ -2298,6 +2298,7 @@ void add_hwgenerator_randomness(const char *buffer, size_t count,
 
 	if (unlikely(crng_init == 0)) {
 		size_t ret = crng_fast_load(buffer, count);
+		mix_pool_bytes(poolp, buffer, ret);
 		count -= ret;
 		buffer += ret;
 		if (!count || crng_init == 0)
-- 
2.34.1


  parent reply	other threads:[~2021-12-28 15:39 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-12-23 19:04 [PATCH v6] random: fix crash on multiple early calls to add_bootloader_randomness() Dominik Brodowski
2021-12-28 14:06 ` Jason A. Donenfeld
2021-12-28 15:38   ` [PATCH v7 1/4] " Jason A. Donenfeld
2021-12-28 15:38     ` [PATCH v7 2/4] random: do not re-init if crng_reseed completes before primary init Jason A. Donenfeld
2021-12-28 15:38     ` [PATCH v7 3/4] random: do not throw away excess input to crng_fast_load Jason A. Donenfeld
2021-12-28 15:38     ` Jason A. Donenfeld [this message]
2021-12-29 21:10     ` [PATCH v8 1/7] random: fix crash on multiple early calls to add_bootloader_randomness() Dominik Brodowski
2021-12-29 21:10       ` [PATCH v8 2/7] random: do not re-init if crng_reseed completes before primary init Dominik Brodowski
2021-12-30 14:31         ` Jason A. Donenfeld
2021-12-29 21:10       ` [PATCH v8 3/7] random: do not throw away excess input to crng_fast_load Dominik Brodowski
2021-12-30 14:32         ` Jason A. Donenfeld
2021-12-29 21:10       ` [PATCH v8 4/7] random: mix bootloader randomness into pool Dominik Brodowski
2021-12-30 14:33         ` Jason A. Donenfeld
2021-12-29 21:10       ` [PATCH v8 5/7] random: harmonize "crng init done" messages Dominik Brodowski
2021-12-30 14:34         ` Jason A. Donenfeld
2021-12-29 21:10       ` [PATCH v8 6/7] random: early initialization of ChaCha constants Dominik Brodowski
2021-12-30 14:40         ` Jason A. Donenfeld
2021-12-29 21:10       ` [PATCH v8 7/7] random: move crng_initialize_secondary to CONFIG_NUMA section Dominik Brodowski
2021-12-30  8:59         ` [PATCH v8.1 7/7] random: move NUMA-related code " Dominik Brodowski
2021-12-30 15:12           ` Jason A. Donenfeld
2021-12-30 15:14             ` [PATCH] random: use IS_ENABLED(CONFIG_NUMA) instead of ifdefs Jason A. Donenfeld
2021-12-31  8:27               ` Dominik Brodowski
2021-12-30 14:31       ` [PATCH v8 1/7] random: fix crash on multiple early calls to add_bootloader_randomness() Jason A. Donenfeld

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=20211228153826.448805-4-Jason@zx2c4.com \
    --to=jason@zx2c4.com \
    --cc=ardb@kernel.org \
    --cc=hsinyi@chromium.org \
    --cc=iivanov@suse.de \
    --cc=linux-efi@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@dominikbrodowski.net \
    --cc=tytso@mit.edu \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.