]> git.itanic.dy.fi Git - linux-stable/commitdiff
random: mix in cycle counter when jitter timer fires
authorJason A. Donenfeld <Jason@zx2c4.com>
Wed, 30 Nov 2022 02:14:15 +0000 (03:14 +0100)
committerJason A. Donenfeld <Jason@zx2c4.com>
Sun, 4 Dec 2022 13:37:08 +0000 (14:37 +0100)
Rather than just relying on interaction between cache lines of the timer
and the main loop, also explicitly take into account the fact that the
timer might fire at some time that's hard to predict, due to scheduling,
interrupts, or cross-CPU conditions. Mix in a cycle counter during the
firing of the timer, in addition to the existing one during the
scheduling of the timer. It can't hurt and can only help.

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
drivers/char/random.c

index 3db4bf6f9b43941915e34366a91d9d4d5d9986f2..36d29da31af0e1d9f97df4bfdadcef569eeef47e 100644 (file)
@@ -1251,7 +1251,9 @@ struct entropy_timer_state {
 static void __cold entropy_timer(struct timer_list *timer)
 {
        struct entropy_timer_state *state = container_of(timer, struct entropy_timer_state, timer);
+       unsigned long entropy = random_get_entropy();
 
+       mix_pool_bytes(&entropy, sizeof(entropy));
        if (atomic_inc_return(&state->samples) % state->samples_per_bit == 0)
                credit_init_bits(1);
 }