Skip to content

Commit 9c3ddde

Browse files
committed
random: do not re-init if crng_reseed completes before primary init
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 <[email protected]> Signed-off-by: Jason A. Donenfeld <[email protected]>
1 parent f7e67b8 commit 9c3ddde

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

drivers/char/random.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -827,7 +827,7 @@ static void __init crng_initialize_primary(struct crng_state *crng)
827827
{
828828
chacha_init_consts(crng->state);
829829
_extract_entropy(&input_pool, &crng->state[4], sizeof(__u32) * 12, 0);
830-
if (crng_init_try_arch_early(crng) && trust_cpu) {
830+
if (crng_init_try_arch_early(crng) && trust_cpu && crng_init < 2) {
831831
invalidate_batched_entropy();
832832
numa_crng_init();
833833
crng_init = 2;

0 commit comments

Comments
 (0)