]> git.ipfire.org Git - thirdparty/kernel/stable.git/commit
hwrng: core - don't wait on add_early_randomness()
authorLaurent Vivier <lvivier@redhat.com>
Tue, 17 Sep 2019 09:54:50 +0000 (11:54 +0200)
committerBen Hutchings <ben@decadent.org.uk>
Tue, 10 Dec 2019 18:01:22 +0000 (18:01 +0000)
commit0e0b9c1bf74dfd3020e4b53e403ca570a1e25d5a
tree5e0a16668bb0e7a9c87f22ea313754b3470f8140
parentfa4fb29a16694477c90b9352f247b7a06b35462e
hwrng: core - don't wait on add_early_randomness()

commit 78887832e76541f77169a24ac238fccb51059b63 upstream.

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 <lvivier@redhat.com>
Fixes: d9e797261933 ("hwrng: add randomness to system from rng...")
Reviewed-by: Theodore Ts'o <tytso@mit.edu>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
[bwh: Backported to 3.16: adjust context]
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
drivers/char/hw_random/core.c