]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/commit
random: fix data race on crng_node_pool
authorEric Biggers <ebiggers@google.com>
Mon, 20 Dec 2021 22:41:56 +0000 (16:41 -0600)
committerAndrea Righi <andrea.righi@canonical.com>
Fri, 21 Jan 2022 14:49:36 +0000 (15:49 +0100)
commit8c2de93a3871ecf773f0eb029b63fffd94fb7a07
tree5a7e2af5259438687d075325aabdfdd1807975a6
parent143cbb8d4dbe0b4d0619f9745d9f8121e5408236
random: fix data race on crng_node_pool

BugLink: https://bugs.launchpad.net/bugs/1958418
commit 5d73d1e320c3fd94ea15ba5f79301da9a8bcc7de upstream.

extract_crng() and crng_backtrack_protect() load crng_node_pool with a
plain load, which causes undefined behavior if do_numa_crng_init()
modifies it concurrently.

Fix this by using READ_ONCE().  Note: as per the previous discussion
https://lore.kernel.org/lkml/20211219025139.31085-1-ebiggers@kernel.org/T/#u,
READ_ONCE() is believed to be sufficient here, and it was requested that
it be used here instead of smp_load_acquire().

Also change do_numa_crng_init() to set crng_node_pool using
cmpxchg_release() instead of mb() + cmpxchg(), as the former is
sufficient here but is more lightweight.

Fixes: 1e7f583af67b ("random: make /dev/urandom scalable for silly userspace programs")
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>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Paolo Pisati <p.pisati@gmail.com>
drivers/char/random.c