]> git.proxmox.com Git - mirror_ubuntu-impish-kernel.git/commitdiff
UBUNTU: SAUCE: random: properly make getrandom() ready earlier
authorAndrea Righi <andrea.righi@canonical.com>
Fri, 30 Jul 2021 09:19:44 +0000 (11:19 +0200)
committerAndrea Righi <andrea.righi@canonical.com>
Mon, 2 Aug 2021 11:26:48 +0000 (13:26 +0200)
This replaces commit 4d75a68d22d7 ("UBUNTU: SAUCE: random: Make
getrandom() ready earlier") with a proper implementation.

We want to make getrandom() available when crng is initialized at least
to the first stage (not necessarily initialized from input_pool). To do
so we need to check this in wait_for_random_bytes() using a wait_event
with a proper timeout and try to generate some entropy when the timeout
expires to prevent the system to get stuck indefinitely.

This indefinite wait issue has been systematically reproduced on some
arm64 ThunderX boards. With this new patch applied the problem doesn't
seem to happen anymore.

Signed-off-by: Andrea Righi <andrea.righi@canonical.com>
drivers/char/random.c

index 605969ed0f965c224b3d562ce9dd976a56aab717..acc0cab71dae1ce8e0593578563fbd1cd0c774c8 100644 (file)
@@ -1619,7 +1619,7 @@ int wait_for_random_bytes(void)
 
        do {
                int ret;
-               ret = wait_event_interruptible_timeout(crng_init_wait, crng_ready(), HZ);
+               ret = wait_event_interruptible_timeout(crng_init_wait, crng_init > 0, HZ);
                if (ret)
                        return ret > 0 ? 0 : ret;
 
@@ -1998,7 +1998,7 @@ SYSCALL_DEFINE3(getrandom, char __user *, buf, size_t, count,
        if (count > INT_MAX)
                count = INT_MAX;
 
-       if (!(flags & GRND_INSECURE) && !crng_ready()) {
+       if (!(flags & GRND_INSECURE) && (crng_init == 0)) {
                if (flags & GRND_NONBLOCK)
                        return -EAGAIN;
                ret = wait_for_random_bytes();