]> git.baikalelectronics.ru Git - kernel.git/commitdiff
random: clamp credited irq bits to maximum mixed
authorJason A. Donenfeld <Jason@zx2c4.com>
Fri, 23 Sep 2022 00:42:51 +0000 (02:42 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sat, 15 Oct 2022 05:54:39 +0000 (07:54 +0200)
commit 9cf56e5cebbaf6cb6c2c7c54ac41903ecc0152c1 upstream.

Since the most that's mixed into the pool is sizeof(long)*2, don't
credit more than that many bytes of entropy.

Fixes: bcd9fd8727b6 ("random: do not use input pool from hard IRQs")
Cc: stable@vger.kernel.org
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/char/random.c

index 1ef94d11252105875166e0c399de0339ef280965..29886cde114e1d7765b7dfda12bc3f8fae714aaf 100644 (file)
@@ -976,7 +976,7 @@ static void mix_interrupt_randomness(struct work_struct *work)
        local_irq_enable();
 
        mix_pool_bytes(pool, sizeof(pool));
-       credit_init_bits(max(1u, (count & U16_MAX) / 64));
+       credit_init_bits(clamp_t(unsigned int, (count & U16_MAX) / 64, 1, sizeof(pool) * 8));
 
        memzero_explicit(pool, sizeof(pool));
 }