Linux cryptographic layer development
 help / color / mirror / Atom feed
* [PATCH] random: throttle hwrng writes if no entropy is credited
@ 2022-09-20 14:14 Jason A. Donenfeld
  2022-09-22 13:51 ` Dominik Brodowski
  0 siblings, 1 reply; 3+ messages in thread
From: Jason A. Donenfeld @ 2022-09-20 14:14 UTC (permalink / raw)
  To: linux-crypto, linux-kernel
  Cc: Jason A. Donenfeld, Dominik Brodowski, Herbert Xu

This value is currently never set to zero, because the hwrng thread only
runs if it's going to be non-zero. This is an oversight, however, that
Dominik is working on fixing. In preparation for this, and so that
there's less coordination required between my tree and Herbert's, make
this currently useless, but not harmful, change here now, in hopes that
Dominik can make the corresponding change in the hwrng core later.

Cc: Dominik Brodowski <linux@dominikbrodowski.net>
Cc: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
---
 drivers/char/random.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/char/random.c b/drivers/char/random.c
index 16e0c5f6cf2f..520a385c7dab 100644
--- a/drivers/char/random.c
+++ b/drivers/char/random.c
@@ -865,9 +865,9 @@ void add_hwgenerator_randomness(const void *buf, size_t len, size_t entropy)
 
 	/*
 	 * Throttle writing to once every reseed interval, unless we're not yet
-	 * initialized.
+	 * initialized or no entropy is credited.
 	 */
-	if (!kthread_should_stop() && crng_ready())
+	if (!kthread_should_stop() && (crng_ready() || !entropy))
 		schedule_timeout_interruptible(crng_reseed_interval());
 }
 EXPORT_SYMBOL_GPL(add_hwgenerator_randomness);
-- 
2.37.3


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

* Re: [PATCH] random: throttle hwrng writes if no entropy is credited
  2022-09-20 14:14 [PATCH] random: throttle hwrng writes if no entropy is credited Jason A. Donenfeld
@ 2022-09-22 13:51 ` Dominik Brodowski
  2022-09-22 14:38   ` Jason A. Donenfeld
  0 siblings, 1 reply; 3+ messages in thread
From: Dominik Brodowski @ 2022-09-22 13:51 UTC (permalink / raw)
  To: Jason A. Donenfeld; +Cc: linux-crypto, linux-kernel, Herbert Xu

Hi Jason,

thanks for splitting this change out of my other patch. You can add my
Signed-off-by, but I'd like to suggest rewriting the commit message as
follows (please modify as needed):


In case a hwrng source does not provide (trusted) entropy, it cannot
assist in initializing the CRNG. Therefore, in case
add_hwgenerator_randomness() is called with the entropy parameter set
to zero, go to sleep until one reseed interval has passed.

While the hwrng thread currently only runs under conditions where this
is non-zero, this change is not harmful and prepares for future updates
to the hwrng core.


Thanks,
	Dominik




Am Tue, Sep 20, 2022 at 04:14:38PM +0200 schrieb Jason A. Donenfeld:
> This value is currently never set to zero, because the hwrng thread only
> runs if it's going to be non-zero. This is an oversight, however, that
> Dominik is working on fixing. In preparation for this, and so that
> there's less coordination required between my tree and Herbert's, make
> this currently useless, but not harmful, change here now, in hopes that
> Dominik can make the corresponding change in the hwrng core later.
> 
> Cc: Dominik Brodowski <linux@dominikbrodowski.net>
> Cc: Herbert Xu <herbert@gondor.apana.org.au>
> Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
> ---
>  drivers/char/random.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/char/random.c b/drivers/char/random.c
> index 16e0c5f6cf2f..520a385c7dab 100644
> --- a/drivers/char/random.c
> +++ b/drivers/char/random.c
> @@ -865,9 +865,9 @@ void add_hwgenerator_randomness(const void *buf, size_t len, size_t entropy)
>  
>  	/*
>  	 * Throttle writing to once every reseed interval, unless we're not yet
> -	 * initialized.
> +	 * initialized or no entropy is credited.
>  	 */
> -	if (!kthread_should_stop() && crng_ready())
> +	if (!kthread_should_stop() && (crng_ready() || !entropy))
>  		schedule_timeout_interruptible(crng_reseed_interval());
>  }
>  EXPORT_SYMBOL_GPL(add_hwgenerator_randomness);
> -- 
> 2.37.3
> 

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

* Re: [PATCH] random: throttle hwrng writes if no entropy is credited
  2022-09-22 13:51 ` Dominik Brodowski
@ 2022-09-22 14:38   ` Jason A. Donenfeld
  0 siblings, 0 replies; 3+ messages in thread
From: Jason A. Donenfeld @ 2022-09-22 14:38 UTC (permalink / raw)
  To: linux; +Cc: linux-crypto, linux-kernel, Herbert Xu

On Thu, Sep 22, 2022 at 4:01 PM Dominik Brodowski
<linux@dominikbrodowski.net> wrote:
>
> Hi Jason,
>
> thanks for splitting this change out of my other patch. You can add my
> Signed-off-by, but I'd like to suggest rewriting the commit message as
> follows (please modify as needed):
>
>
> In case a hwrng source does not provide (trusted) entropy, it cannot
> assist in initializing the CRNG. Therefore, in case
> add_hwgenerator_randomness() is called with the entropy parameter set
> to zero, go to sleep until one reseed interval has passed.
>
> While the hwrng thread currently only runs under conditions where this
> is non-zero, this change is not harmful and prepares for future updates
> to the hwrng core.

Will do.

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

end of thread, other threads:[~2022-09-22 14:40 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-09-20 14:14 [PATCH] random: throttle hwrng writes if no entropy is credited Jason A. Donenfeld
2022-09-22 13:51 ` Dominik Brodowski
2022-09-22 14:38   ` 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