random: fix locking in crng_fast_load()
authorDominik Brodowski <linux@dominikbrodowski.net>
Sat, 5 Feb 2022 10:34:57 +0000 (11:34 +0100)
committerJason A. Donenfeld <Jason@zx2c4.com>
Sun, 13 Feb 2022 23:46:08 +0000 (00:46 +0100)
commit519b52becb65e3d44d1f3b7bba4364ba8455ee00
tree95141da61e4f303caeda5944a36f9de727b87de1
parent6a1d5317ee05839620aa6a409295a60dd904acf1
random: fix locking in crng_fast_load()

crng_init is protected by primary_crng->lock, so keep holding that lock
when incrementing crng_init from 0 to 1 in crng_fast_load(). The call to
pr_notice() can wait until the lock is released; this code path cannot
be reached twice, as crng_fast_load() aborts early if crng_init > 0.

Signed-off-by: Dominik Brodowski <linux@dominikbrodowski.net>
[Jason: Note - this is only possible now that invalidate_batched_
 entropy() is a simple atomic_inc(), so this must be ordered after that,
 even though it appears on first glance as independent.]
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
drivers/char/random.c