• Laurent Vivier's avatar
    hwrng: core - don't wait on add_early_randomness() · fec38267
    Laurent Vivier authored
    commit 78887832 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: default avatarLaurent Vivier <lvivier@redhat.com>
    Fixes: d9e79726 ("hwrng: add randomness to system from rng...")
    Cc: <stable@vger.kernel.org>
    Reviewed-by: default avatarTheodore Ts'o <tytso@mit.edu>
    Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
    Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
    fec38267
core.c 12.8 KB