]> git.baikalelectronics.ru Git - kernel.git/commit
random: fix data race on crng init time
authorEric Biggers <ebiggers@google.com>
Mon, 20 Dec 2021 22:41:57 +0000 (16:41 -0600)
committerJason A. Donenfeld <Jason@zx2c4.com>
Thu, 6 Jan 2022 23:25:25 +0000 (00:25 +0100)
commit0cd32fc290c301eb2ff2bb14278277ce45942fd3
tree1adc5b2e17ac2cbce18f6a1cd2a42078225769bb
parenta419615416bba12045d7b0a40822519d33b77b7f
random: fix data race on crng init time

_extract_crng() does plain loads of crng->init_time and
crng_global_init_time, which causes undefined behavior if
crng_reseed() and RNDRESEEDCRNG modify these corrently.

Use READ_ONCE() and WRITE_ONCE() to make the behavior defined.

Don't fix the race on crng->init_time by protecting it with crng->lock,
since it's not a problem for duplicate reseedings to occur.  I.e., the
lockless access with READ_ONCE() is fine.

Fixes: 97ee58ae85c7 ("random: add new ioctl RNDRESEEDCRNG")
Fixes: a3804d807fe1 ("random: replace non-blocking pool with a Chacha20-based CRNG")
Cc: stable@vger.kernel.org
Signed-off-by: Eric Biggers <ebiggers@google.com>
Acked-by: Paul E. McKenney <paulmck@kernel.org>
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
drivers/char/random.c