Skip to content

Commit 7888783

Browse files
vivierherbertx
authored andcommitted
hwrng: core - don't wait on add_early_randomness()
add_early_randomness() is called by hwrng_register() when the hardware is added. If this hardware and its module are present at boot, and if there is no data available the boot hangs until data are available and can't be interrupted. For instance, in the case of virtio-rng, in some cases the host can be not able to provide enough entropy for all the guests. We can have two easy ways to reproduce the problem but they rely on misconfiguration of the hypervisor or the egd daemon: - if virtio-rng device is configured to connect to the egd daemon of the host but when the virtio-rng driver asks for data the daemon is not connected, - if virtio-rng device is configured to connect to the egd daemon of the host but the egd daemon doesn't provide data. The guest kernel will hang at boot until the virtio-rng driver provides enough data. To avoid that, call rng_get_data() in non-blocking mode (wait=0) from add_early_randomness(). Signed-off-by: Laurent Vivier <[email protected]> Fixes: d9e7972 ("hwrng: add randomness to system from rng...") Cc: <[email protected]> Reviewed-by: Theodore Ts'o <[email protected]> Signed-off-by: Herbert Xu <[email protected]>
1 parent 62a9d9f commit 7888783

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

drivers/char/hw_random/core.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ static void add_early_randomness(struct hwrng *rng)
6868
size_t size = min_t(size_t, 16, rng_buffer_size());
6969

7070
mutex_lock(&reading_mutex);
71-
bytes_read = rng_get_data(rng, rng_buffer, size, 1);
71+
bytes_read = rng_get_data(rng, rng_buffer, size, 0);
7272
mutex_unlock(&reading_mutex);
7373
if (bytes_read > 0)
7474
add_device_randomness(rng_buffer, bytes_read);

0 commit comments

Comments
 (0)