Skip to content

Commit c321e90

Browse files
Dominik Brodowskizx2c4
authored andcommitted
random: continually use hwgenerator randomness
The rngd kernel thread may sleep indefinitely if the entropy count is kept above random_write_wakeup_bits by other entropy sources. To make best use of multiple sources of randomness, mix entropy from hardware RNGs into the pool at least once within CRNG_RESEED_INTERVAL. Cc: Herbert Xu <[email protected]> Cc: Jason A. Donenfeld <[email protected]> Signed-off-by: Dominik Brodowski <[email protected]> Signed-off-by: Jason A. Donenfeld <[email protected]>
1 parent d2a02e3 commit c321e90

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

drivers/char/random.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2205,13 +2205,15 @@ void add_hwgenerator_randomness(const char *buffer, size_t count,
22052205
return;
22062206
}
22072207

2208-
/* Suspend writing if we're above the trickle threshold.
2208+
/* Throttle writing if we're above the trickle threshold.
22092209
* We'll be woken up again once below random_write_wakeup_thresh,
2210-
* or when the calling thread is about to terminate.
2210+
* when the calling thread is about to terminate, or once
2211+
* CRNG_RESEED_INTERVAL has lapsed.
22112212
*/
2212-
wait_event_interruptible(random_write_wait,
2213+
wait_event_interruptible_timeout(random_write_wait,
22132214
!system_wq || kthread_should_stop() ||
2214-
POOL_ENTROPY_BITS() <= random_write_wakeup_bits);
2215+
POOL_ENTROPY_BITS() <= random_write_wakeup_bits,
2216+
CRNG_RESEED_INTERVAL);
22152217
mix_pool_bytes(buffer, count);
22162218
credit_entropy_bits(entropy);
22172219
}

0 commit comments

Comments
 (0)