Skip to contentSkip to conversation

random: clamp credited irq bits to maximum mixed

PATCH Superseded Jason A. Donenfeld 1 participant 2 messages Sep 23, 2022 Random number driver

lore
Share & tools
lore

Jason A. Donenfeld

author maintainer
#0 lore raw

PATCH 1/1 random: clamp credited irq bits to maximum mixed

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

Fixes e3e33fc2ea7f ("random: do not use input pool from hard IRQs")
---
 drivers/char/random.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/char/random.c +1 -1
index 520a385c7dab..593fb3b3cf74 100644
@@ -1004,7 +1004,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, 1, (count & U16_MAX) / 64, sizeof(pool) * 8));
 
 	memzero_explicit(pool, sizeof(pool));
 }
Signature · 1 line
2.37.3
author maintainer
#1 lore raw

PATCH v2 1/1 random: clamp credited irq bits to maximum mixed

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

Fixes e3e33fc2ea7f ("random: do not use input pool from hard IRQs")
---
 drivers/char/random.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/char/random.c +1 -1
index 520a385c7dab..2f370aa248b2 100644
@@ -1004,7 +1004,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));
 }
Signature · 1 line
2.37.3