]> git.ipfire.org Git - thirdparty/kernel/stable.git/commit
random: do not re-init if crng_reseed completes before primary init
authorJason A. Donenfeld <Jason@zx2c4.com>
Wed, 29 Dec 2021 21:10:04 +0000 (22:10 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sat, 25 Jun 2022 09:46:30 +0000 (11:46 +0200)
commite59fd7eb5ca0883059222dbb4ad771904d59b7c0
tree4636a1ffa4197903ca90cf8a1882d6b132a208f3
parenteaa94d939f2f5799b1ef1fe565164f55c10a483a
random: do not re-init if crng_reseed completes before primary init

commit 9c3ddde3f811aabbb83778a2a615bf141b4909ef upstream.

If the bootloader supplies sufficient material and crng_reseed() is called
very early on, but not too early that wqs aren't available yet, then we
might transition to crng_init==2 before rand_initialize()'s call to
crng_initialize_primary() made. Then, when crng_initialize_primary() is
called, if we're trusting the CPU's RDRAND instructions, we'll
needlessly reinitialize the RNG and emit a message about it. This is
mostly harmless, as numa_crng_init() will allocate and then free what it
just allocated, and excessive calls to invalidate_batched_entropy()
aren't so harmful. But it is funky and the extra message is confusing,
so avoid the re-initialization all together by checking for crng_init <
2 in crng_initialize_primary(), just as we already do in crng_reseed().

Reviewed-by: Dominik Brodowski <linux@dominikbrodowski.net>
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/char/random.c