Patch "random: fix data race on crng_node_pool" has been added to the 4.9-stable tree

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This is a note to let you know that I've just added the patch titled

    random: fix data race on crng_node_pool

to the 4.9-stable tree which can be found at:
    http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary

The filename of the patch is:
     random-fix-data-race-on-crng_node_pool.patch
and it can be found in the queue-4.9 subdirectory.

If you, or anyone else, feels it should not be added to the stable tree,
please let <stable@xxxxxxxxxxxxxxx> know about it.


>From foo@baz Thu Jun 16 06:59:24 PM CEST 2022
From: Eric Biggers <ebiggers@xxxxxxxxxx>
Date: Mon, 20 Dec 2021 16:41:56 -0600
Subject: random: fix data race on crng_node_pool

From: Eric Biggers <ebiggers@xxxxxxxxxx>

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@xxxxxxxxxx/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@xxxxxxxxxxxxxxx
Signed-off-by: Eric Biggers <ebiggers@xxxxxxxxxx>
Acked-by: Paul E. McKenney <paulmck@xxxxxxxxxx>
Signed-off-by: Jason A. Donenfeld <Jason@xxxxxxxxx>
Signed-off-by: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx>
Signed-off-by: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx>
---
 drivers/char/random.c |   22 ++++++++++++++++++++--
 1 file changed, 20 insertions(+), 2 deletions(-)

--- a/drivers/char/random.c
+++ b/drivers/char/random.c
@@ -814,8 +814,8 @@ static void do_numa_crng_init(struct wor
 		crng_initialize(crng);
 		pool[i] = crng;
 	}
-	mb();
-	if (cmpxchg(&crng_node_pool, NULL, pool)) {
+	/* pairs with READ_ONCE() in select_crng() */
+	if (cmpxchg_release(&crng_node_pool, NULL, pool) != NULL) {
 		for_each_node(i)
 			kfree(pool[i]);
 		kfree(pool);
@@ -828,8 +828,26 @@ static void numa_crng_init(void)
 {
 	schedule_work(&numa_crng_init_work);
 }
+
+static struct crng_state *select_crng(void)
+{
+	struct crng_state **pool;
+	int nid = numa_node_id();
+
+	/* pairs with cmpxchg_release() in do_numa_crng_init() */
+	pool = READ_ONCE(crng_node_pool);
+	if (pool && pool[nid])
+		return pool[nid];
+
+	return &primary_crng;
+}
 #else
 static void numa_crng_init(void) {}
+
+static struct crng_state *select_crng(void)
+{
+	return &primary_crng;
+}
 #endif
 
 /*


Patches currently in stable-queue which might be from ebiggers@xxxxxxxxxx are

queue-4.9/random-do-not-take-pool-spinlock-at-boot.patch
queue-4.9/random-introduce-drain_entropy-helper-to-declutter-crng_reseed.patch
queue-4.9/random-fix-locking-in-crng_fast_load.patch
queue-4.9/random-group-userspace-read-write-functions.patch
queue-4.9/random-make-credit_entropy_bits-always-safe.patch
queue-4.9/crypto-chacha20-fix-chacha20_block-keystream-alignment-again.patch
queue-4.9/random-pull-add_hwgenerator_randomness-declaration-into-random.h.patch
queue-4.9/random-unify-early-init-crng-load-accounting.patch
queue-4.9/random-use-blake2s-instead-of-sha1-in-extraction.patch
queue-4.9/random-initialize-chacha20-constants-with-correct-endianness.patch
queue-4.9/random-group-entropy-extraction-functions.patch
queue-4.9/random-rewrite-header-introductory-comment.patch
queue-4.9/random-remove-ifdef-d-out-interrupt-bench.patch
queue-4.9/random-tie-batched-entropy-generation-to-base_crng-generation.patch
queue-4.9/random-use-linear-min-entropy-accumulation-crediting.patch
queue-4.9/random-remove-batched-entropy-locking.patch
queue-4.9/random-inline-leaves-of-rand_initialize.patch
queue-4.9/random-remove-use_input_pool-parameter-from-crng_reseed.patch
queue-4.9/random-zero-buffer-after-reading-entropy-from-userspace.patch
queue-4.9/random-remove-whitespace-and-reorder-includes.patch
queue-4.9/random-simplify-entropy-debiting.patch
queue-4.9/random-document-crng_fast_key_erasure-destination-possibility.patch
queue-4.9/random-fix-data-race-on-crng_node_pool.patch
queue-4.9/random-absorb-fast-pool-into-input-pool-after-fast-load.patch
queue-4.9/random-use-rdseed-instead-of-rdrand-in-entropy-extraction.patch
queue-4.9/random-remove-dead-code-left-over-from-blocking-pool.patch
queue-4.9/random-use-computational-hash-for-entropy-extraction.patch
queue-4.9/random-always-wake-up-entropy-writers-after-extraction.patch
queue-4.9/random-do-not-xor-rdrand-when-writing-into-dev-random.patch
queue-4.9/random-group-initialization-wait-functions.patch
queue-4.9/random-remove-unused-tracepoints.patch
queue-4.9/crypto-chacha20-fix-keystream-alignment-for-chacha20_block.patch
queue-4.9/random-check-for-crng_init-0-in-add_device_randomness.patch
queue-4.9/crypto-blake2s-include-linux-bug.h-instead-of-asm-bug.h.patch
queue-4.9/random-group-entropy-collection-functions.patch
queue-4.9/random-remove-useless-header-comment.patch
queue-4.9/random-remove-outdated-int_max-6-check-in-urandom_read.patch
queue-4.9/random-do-not-pretend-to-handle-premature-next-security-model.patch
queue-4.9/random-avoid-arch_get_random_seed_long-when-collecting-irq-randomness.patch
queue-4.9/random-reseed-more-often-immediately-after-booting.patch
queue-4.9/random-ensure-early-rdseed-goes-through-mixer-on-init.patch
queue-4.9/crypto-blake2s-adjust-include-guard-naming.patch
queue-4.9/random-use-hash-function-for-crng_slow_load.patch



[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux