public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] random: invalidate crngs and batches on cpuhp teardown
@ 2022-02-14 13:48 Jason A. Donenfeld
  2022-02-14 14:00 ` Jason A. Donenfeld
  2022-02-14 14:26 ` Sebastian Andrzej Siewior
  0 siblings, 2 replies; 3+ messages in thread
From: Jason A. Donenfeld @ 2022-02-14 13:48 UTC (permalink / raw)
  To: linux-kernel, linux
  Cc: Jason A. Donenfeld, Sebastian Andrzej Siewior, Sultan Alsawaf,
	Theodore Ts'o

Now that we have a cpuhp teardown notifier, we can invalidate the keys
used by the per-cpu crngs and the batches used by per-cpu batched
entropy, so that if the cpus come back online, and the generation
counter happens to have cycled all the way around to where it was
before, it doesn't mistakenly use the old data. The chances of this
happening are exceedingly rare, but since we now have the notifier
setup, doing this is basically free.

Cc: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Cc: Sultan Alsawaf <sultan@kerneltoast.com>
Cc: Dominik Brodowski <linux@dominikbrodowski.net>
Cc: Theodore Ts'o <tytso@mit.edu>
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
---
 drivers/char/random.c | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/drivers/char/random.c b/drivers/char/random.c
index df5aef93da34..ce199af9bc56 100644
--- a/drivers/char/random.c
+++ b/drivers/char/random.c
@@ -1225,6 +1225,15 @@ int random_dead_cpu(unsigned int cpu)
 	 * since the MIX_INFLIGHT flag will be cleared.
 	 */
 	per_cpu_ptr(&irq_randomness, cpu)->count = 0;
+
+	/*
+	 * We also want to invalidate per-cpu crngs and batches,
+	 * so that if the CPU does come back online, it uses
+	 * fresh entropy.
+	 */
+	per_cpu_ptr(&crngs, cpu)->generation = ULONG_MAX;
+	per_cpu_ptr(&batched_entropy_u32, cpu)->position = UINT_MAX;
+	per_cpu_ptr(&batched_entropy_u64, cpu)->position = UINT_MAX;
 	return 0;
 }
 
-- 
2.35.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-02-14 14:26 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-02-14 13:48 [PATCH] random: invalidate crngs and batches on cpuhp teardown Jason A. Donenfeld
2022-02-14 14:00 ` Jason A. Donenfeld
2022-02-14 14:26 ` Sebastian Andrzej Siewior

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox