Re: [PATCH] hw_random: use add_hwgenerator_randomness() for early entropy

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Sat, Nov 5, 2022 at 9:44 PM Jason A. Donenfeld <Jason@xxxxxxxxx> wrote:
>
> Rather than calling add_device_randomness(), the add_early_randomness()
> function should use add_hwgenerator_randomness(), so that the early
> entropy can be potentially credited, which allows for the RNG to
> initialize earlier without having to wait for the kthread to come up.
>
> Cc: Herbert Xu <herbert@xxxxxxxxxxxxxxxxxxx>
> Signed-off-by: Jason A. Donenfeld <Jason@xxxxxxxxx>
> ---
>  drivers/char/hw_random/core.c | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/char/hw_random/core.c b/drivers/char/hw_random/core.c
> index cc002b0c2f0c..8c0819ce2781 100644
> --- a/drivers/char/hw_random/core.c
> +++ b/drivers/char/hw_random/core.c
> @@ -69,8 +69,10 @@ static void add_early_randomness(struct hwrng *rng)
>         mutex_lock(&reading_mutex);
>         bytes_read = rng_get_data(rng, rng_fillbuf, 32, 0);
>         mutex_unlock(&reading_mutex);
> -       if (bytes_read > 0)
> -               add_device_randomness(rng_fillbuf, bytes_read);
> +       if (bytes_read > 0) {
> +               size_t entropy = bytes_read * 8 * rng->quality / 1024;
> +               add_hwgenerator_randomness(rng_fillbuf, bytes_read, entropy);
> +       }

This will cause problems, because add_hwgenerator_randomness() will
sleep. I'll look into a more robust change.

Jason



[Index of Archives]     [Kernel]     [Gnu Classpath]     [Gnu Crypto]     [DM Crypt]     [Netfilter]     [Bugtraq]
  Powered by Linux