From 3b3e60ba53e0a8aedcfb8165b8a1dbc7ea0bfdce Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Thu, 13 Oct 2022 18:21:17 +0200 Subject: [PATCH] 4.14-stable patches added patches: random-restore-o_nonblock-support.patch --- .../random-restore-o_nonblock-support.patch | 65 +++++++++++++++++++ queue-4.14/series | 1 + 2 files changed, 66 insertions(+) create mode 100644 queue-4.14/random-restore-o_nonblock-support.patch diff --git a/queue-4.14/random-restore-o_nonblock-support.patch b/queue-4.14/random-restore-o_nonblock-support.patch new file mode 100644 index 00000000000..06daff979bf --- /dev/null +++ b/queue-4.14/random-restore-o_nonblock-support.patch @@ -0,0 +1,65 @@ +From cd4f24ae9404fd31fc461066e57889be3b68641b Mon Sep 17 00:00:00 2001 +From: "Jason A. Donenfeld" +Date: Thu, 8 Sep 2022 16:14:00 +0200 +Subject: random: restore O_NONBLOCK support + +From: Jason A. Donenfeld + +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 +Reported-by: Zhongguohua +Cc: Al Viro +Cc: Theodore Ts'o +Cc: Andrew Lutomirski +Cc: stable@vger.kernel.org +Signed-off-by: Jason A. Donenfeld +Signed-off-by: Greg Kroah-Hartman +--- + drivers/char/mem.c | 4 ++-- + drivers/char/random.c | 5 +++++ + 2 files changed, 7 insertions(+), 2 deletions(-) + +--- a/drivers/char/mem.c ++++ b/drivers/char/mem.c +@@ -887,8 +887,8 @@ static const struct memdev { + #endif + [5] = { "zero", 0666, &zero_fops, 0 }, + [7] = { "full", 0666, &full_fops, 0 }, +- [8] = { "random", 0666, &random_fops, 0 }, +- [9] = { "urandom", 0666, &urandom_fops, 0 }, ++ [8] = { "random", 0666, &random_fops, FMODE_NOWAIT }, ++ [9] = { "urandom", 0666, &urandom_fops, FMODE_NOWAIT }, + #ifdef CONFIG_PRINTK + [11] = { "kmsg", 0644, &kmsg_fops, 0 }, + #endif +--- a/drivers/char/random.c ++++ b/drivers/char/random.c +@@ -1294,6 +1294,11 @@ static ssize_t random_read_iter(struct k + { + int ret; + ++ if (!crng_ready() && ++ ((kiocb->ki_flags & IOCB_NOWAIT) || ++ (kiocb->ki_filp->f_flags & O_NONBLOCK))) ++ return -EAGAIN; ++ + ret = wait_for_random_bytes(); + if (ret != 0) + return ret; diff --git a/queue-4.14/series b/queue-4.14/series index d8605ee9d76..afcf3c76cee 100644 --- a/queue-4.14/series +++ b/queue-4.14/series @@ -41,3 +41,4 @@ random-clamp-credited-irq-bits-to-maximum-mixed.patch alsa-hda-fix-position-reporting-on-poulsbo.patch scsi-stex-properly-zero-out-the-passthrough-command-structure.patch usb-serial-qcserial-add-new-usb-id-for-dell-branded-em7455.patch +random-restore-o_nonblock-support.patch -- 2.47.3