Re: [PATCH] random: opportunistically initialize on /dev/urandom reads

From: Linus Torvalds
Date: Tue Apr 05 2022 - 18:41:36 EST


On Tue, Apr 5, 2022 at 11:31 AM Jason A. Donenfeld <Jason@xxxxxxxxx> wrote:
>
> It sounds like your suggestion would be to make that:
>
> while (!crng_ready()) {
> int ret;
>
> try_to_generate_entropy();
> if (nodelay && !crng_ready()) {
> warn(...);
> return -EBUSY;
> }
> ret = wait_event_interruptible_timeout(crng_init_wait, crng_ready(), HZ);
> if (ret)
> return ret > 0 ? 0 : ret;
> }

Yes. Except I'd almost warn for the "ret < 0" case too, since almost
nobody seems to check it.

But hey, maybe callers that are interrupted by a signal check for that
separately. I guess it's _possible_.

Linus