Skip to content

Commit d775335

Browse files
committed
random: throttle hwrng writes if no entropy is credited
If a hwrng source does not provide an entropy estimate, it currently does not contribute at all to the CRNG. In order to help fix this, 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. Cc: Herbert Xu <herbert@gondor.apana.org.au> Reviewed-by: Dominik Brodowski <linux@dominikbrodowski.net> Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
1 parent 745558f commit d775335

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

drivers/char/random.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -865,9 +865,9 @@ void add_hwgenerator_randomness(const void *buf, size_t len, size_t entropy)
865865

866866
/*
867867
* Throttle writing to once every reseed interval, unless we're not yet
868-
* initialized.
868+
* initialized or no entropy is credited.
869869
*/
870-
if (!kthread_should_stop() && crng_ready())
870+
if (!kthread_should_stop() && (crng_ready() || !entropy))
871871
schedule_timeout_interruptible(crng_reseed_interval());
872872
}
873873
EXPORT_SYMBOL_GPL(add_hwgenerator_randomness);

0 commit comments

Comments
 (0)