]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/commitdiff
4.9-stable patches
authorGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 13 Oct 2022 17:01:40 +0000 (19:01 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 13 Oct 2022 17:01:40 +0000 (19:01 +0200)
added patches:
random-restore-o_nonblock-support.patch

queue-4.9/random-restore-o_nonblock-support.patch [new file with mode: 0644]
queue-4.9/series

diff --git a/queue-4.9/random-restore-o_nonblock-support.patch b/queue-4.9/random-restore-o_nonblock-support.patch
new file mode 100644 (file)
index 0000000..ff22d04
--- /dev/null
@@ -0,0 +1,50 @@
+From cd4f24ae9404fd31fc461066e57889be3b68641b Mon Sep 17 00:00:00 2001
+From: "Jason A. Donenfeld" <Jason@zx2c4.com>
+Date: Thu, 8 Sep 2022 16:14:00 +0200
+Subject: random: restore O_NONBLOCK support
+
+From: Jason A. Donenfeld <Jason@zx2c4.com>
+
+commit cd4f24ae9404fd31fc461066e57889be3b68641b upstream.
+
+Prior to 5.6, when /dev/random was opened with O_NONBLOCK, it would
+return -EAGAIN if there was no entropy. When the pools were unified in
+5.6, this was lost. The post 5.6 behavior of blocking until the pool is
+initialized, and ignoring O_NONBLOCK in the process, went unnoticed,
+with no reports about the regression received for two and a half years.
+However, eventually this indeed did break somebody's userspace.
+
+So we restore the old behavior, by returning -EAGAIN if the pool is not
+initialized. Unlike the old /dev/random, this can only occur during
+early boot, after which it never blocks again.
+
+In order to make this O_NONBLOCK behavior consistent with other
+expectations, also respect users reading with preadv2(RWF_NOWAIT) and
+similar.
+
+Fixes: 30c08efec888 ("random: make /dev/random be almost like /dev/urandom")
+Reported-by: Guozihua <guozihua@huawei.com>
+Reported-by: Zhongguohua <zhongguohua1@huawei.com>
+Cc: Al Viro <viro@zeniv.linux.org.uk>
+Cc: Theodore Ts'o <tytso@mit.edu>
+Cc: Andrew Lutomirski <luto@kernel.org>
+Cc: stable@vger.kernel.org
+Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+---
+ drivers/char/random.c |    4 ++++
+ 1 file changed, 4 insertions(+)
+
+--- a/drivers/char/random.c
++++ b/drivers/char/random.c
+@@ -1295,6 +1295,10 @@ static ssize_t random_read_iter(struct k
+ {
+       int ret;
++      if (!crng_ready() &&
++          (kiocb->ki_filp->f_flags & O_NONBLOCK))
++              return -EAGAIN;
++
+       ret = wait_for_random_bytes();
+       if (ret != 0)
+               return ret;
index b16142b6120239b6806b8af9de0f2d674970bfd1..d0032980da79ec25d407ac7f3d21c361d1d06322 100644 (file)
@@ -34,3 +34,4 @@ scsi-stex-properly-zero-out-the-passthrough-command-structure.patch
 usb-serial-qcserial-add-new-usb-id-for-dell-branded-em7455.patch
 random-avoid-reading-two-cache-lines-on-irq-randomness.patch
 wifi-mac80211_hwsim-avoid-mac80211-warning-on-bad-rate.patch
+random-restore-o_nonblock-support.patch