Messages in this thread Patch in this message | | | From | "Jason A. Donenfeld" <> | Subject | [PATCH v3 2/2] random: invalidate crngs and batches in cpuhp prepare | Date | Mon, 14 Feb 2022 16:14:15 +0100 |
| |
Now that we have a cpuhp prepare 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 | 8 ++++++++ 1 file changed, 8 insertions(+)
diff --git a/drivers/char/random.c b/drivers/char/random.c index 2e25e3aa6506..6870b5068a75 100644 --- a/drivers/char/random.c +++ b/drivers/char/random.c @@ -1229,6 +1229,14 @@ int random_prepare_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 we always use 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
| |