This is a note to let you know that I've just added the patch titled random: Add a urandom_read_nowait() for random APIs that don't warn to the 4.19-stable tree which can be found at: http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary The filename of the patch is: random-add-a-urandom_read_nowait-for-random-apis-that-don-t-warn.patch and it can be found in the queue-4.19 subdirectory. If you, or anyone else, feels it should not be added to the stable tree, please let <stable@xxxxxxxxxxxxxxx> know about it. >From foo@baz Fri Jun 17 08:58:56 AM CEST 2022 From: Andy Lutomirski <luto@xxxxxxxxxx> Date: Mon, 23 Dec 2019 00:20:45 -0800 Subject: random: Add a urandom_read_nowait() for random APIs that don't warn From: Andy Lutomirski <luto@xxxxxxxxxx> commit c6f1deb158789abba02a7eba600747843eeb3a57 upstream. /dev/random and getrandom() never warn. Split the meat of urandom_read() into urandom_read_nowarn() and leave the warning code in urandom_read(). This has no effect on kernel behavior, but it makes subsequent patches more straightforward. It also makes the fact that getrandom() never warns more obvious. Signed-off-by: Andy Lutomirski <luto@xxxxxxxxxx> Link: https://lore.kernel.org/r/c87ab200588de746431d9f916501ef11e5242b13.1577088521.git.luto@xxxxxxxxxx Signed-off-by: Theodore Ts'o <tytso@xxxxxxx> Signed-off-by: Jason A. Donenfeld <Jason@xxxxxxxxx> Signed-off-by: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx> --- drivers/char/random.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) --- a/drivers/char/random.c +++ b/drivers/char/random.c @@ -2025,11 +2025,22 @@ random_read(struct file *file, char __us } static ssize_t +urandom_read_nowarn(struct file *file, char __user *buf, size_t nbytes, + loff_t *ppos) +{ + int ret; + + nbytes = min_t(size_t, nbytes, INT_MAX >> (ENTROPY_SHIFT + 3)); + ret = extract_crng_user(buf, nbytes); + trace_urandom_read(8 * nbytes, 0, ENTROPY_BITS(&input_pool)); + return ret; +} + +static ssize_t urandom_read(struct file *file, char __user *buf, size_t nbytes, loff_t *ppos) { unsigned long flags; static int maxwarn = 10; - int ret; if (!crng_ready() && maxwarn > 0) { maxwarn--; @@ -2041,10 +2052,8 @@ urandom_read(struct file *file, char __u crng_init_cnt = 0; spin_unlock_irqrestore(&primary_crng.lock, flags); } - nbytes = min_t(size_t, nbytes, INT_MAX >> (ENTROPY_SHIFT + 3)); - ret = extract_crng_user(buf, nbytes); - trace_urandom_read(8 * nbytes, 0, ENTROPY_BITS(&input_pool)); - return ret; + + return urandom_read_nowarn(file, buf, nbytes, ppos); } static __poll_t @@ -2204,7 +2213,7 @@ SYSCALL_DEFINE3(getrandom, char __user * if (unlikely(ret)) return ret; } - return urandom_read(NULL, buf, count, NULL); + return urandom_read_nowarn(NULL, buf, count, NULL); } /******************************************************************** Patches currently in stable-queue which might be from luto@xxxxxxxxxx are queue-4.19/random-remove-kernel.random.read_wakeup_threshold.patch queue-4.19/random-initialize-chacha20-constants-with-correct-endianness.patch queue-4.19/random-make-dev-random-be-almost-like-dev-urandom.patch queue-4.19/random-remove-batched-entropy-locking.patch queue-4.19/random-remove-the-blocking-pool.patch queue-4.19/random-ignore-grnd_random-in-getentropy-2.patch queue-4.19/random-delete-code-to-pull-data-into-pools.patch queue-4.19/random-don-t-wake-crng_init_wait-when-crng_init-1.patch queue-4.19/random-add-a-urandom_read_nowait-for-random-apis-that-don-t-warn.patch queue-4.19/random-remove-dead-code-left-over-from-blocking-pool.patch queue-4.19/random-add-grnd_insecure-to-return-best-effort-non-cryptographic-bytes.patch