lkml.org 
[lkml]   [2022]   [Apr]   [4]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH] random: fix add_hwgenerator_randomness entropy accounting
Date
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
\
 
 \ /
  Last update: 2022-04-04 17:08    [W:0.122 / U:0.168 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site