public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] random: fix add_hwgenerator_randomness entropy accounting
@ 2022-04-04 15:04 Jan Varho
  2022-04-04 15:20 ` Jason A. Donenfeld
  0 siblings, 1 reply; 7+ messages in thread
From: Jan Varho @ 2022-04-04 15:04 UTC (permalink / raw)
  To: Jason A. Donenfeld, Theodore Ts'o; +Cc: linux-kernel, Jan Varho

add_hwgenerator_randomness tries to only use the required amound of input
for fast init, but credits all the entropy if even a byte was left over.

Fix by not crediting entropy if any input was consumed for fast init.

Signed-off-by: Jan Varho <jan.varho@gmail.com>
---
 drivers/char/random.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/drivers/char/random.c b/drivers/char/random.c
index 1d8242969751..fb20178f1044 100644
--- a/drivers/char/random.c
+++ b/drivers/char/random.c
@@ -1141,12 +1141,10 @@ void add_hwgenerator_randomness(const void *buffer, size_t count,
 				size_t entropy)
 {
 	if (unlikely(crng_init == 0 && entropy < POOL_MIN_BITS)) {
-		size_t ret = crng_pre_init_inject(buffer, count, true);
-		mix_pool_bytes(buffer, ret);
-		count -= ret;
-		buffer += ret;
-		if (!count || crng_init == 0)
+		if (crng_pre_init_inject(buffer, count, true) > 0) {
+			mix_pool_bytes(buffer, count);
 			return;
+		}
 	}
 
 	/*
-- 
2.25.1


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

end of thread, other threads:[~2022-04-04 21:59 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-04-04 15:04 [PATCH] random: fix add_hwgenerator_randomness entropy accounting Jan Varho
2022-04-04 15:20 ` Jason A. Donenfeld
2022-04-04 15:29   ` Jan Varho
2022-04-04 16:10     ` Jason A. Donenfeld
2022-04-04 16:20   ` [PATCH v2] " Jan Varho
2022-04-04 16:42     ` [PATCH v3] " Jan Varho
2022-04-04 17:37       ` Jason A. Donenfeld

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