[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Date: Mon, 4 Apr 2022 18:04:42 +0300
From: Jan Varho <jan.varho@...il.com>
To: "Jason A. Donenfeld" <Jason@...c4.com>,
"Theodore Ts'o" <tytso@....edu>
Cc: linux-kernel@...r.kernel.org, Jan Varho <jan.varho@...il.com>
Subject: [PATCH] random: fix add_hwgenerator_randomness entropy accounting
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@...il.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
Powered by blists - more mailing lists