From: Jann Horn <jannh@google.com>
To: "Theodore Ts'o" <tytso@mit.edu>, "Jason A . Donenfeld" <Jason@zx2c4.com>
Cc: linux-kernel@vger.kernel.org, Jann Horn <jannh@google.com>
Subject: [PATCH] random: Fix signal_pending() usage
Date: Tue, 5 Apr 2022 18:39:31 +0200 [thread overview]
Message-ID: <20220405163931.1108442-1-jannh@google.com> (raw)
signal_pending() checks TIF_NOTIFY_SIGNAL and TIF_SIGPENDING, which signal
that the task should bail out of the syscall when possible.
This is a separate concept from need_resched(), which checks
TIF_NEED_RESCHED, signalling that the task should preempt.
In particular, with the current code, the signal_pending() bailout probably
won't work reliably.
Change this to look like other functions that read lots of data, such as
read_zero().
Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Signed-off-by: Jann Horn <jannh@google.com>
---
drivers/char/random.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/char/random.c b/drivers/char/random.c
index 1eb220a5f44f..7f0253455d4e 100644
--- a/drivers/char/random.c
+++ b/drivers/char/random.c
@@ -540,13 +540,13 @@ static ssize_t get_random_bytes_user(void __user *buf, size_t nbytes)
crng_make_state(chacha_state, (u8 *)&chacha_state[4], CHACHA_KEY_SIZE);
do {
- if (large_request && need_resched()) {
+ if (large_request) {
if (signal_pending(current)) {
if (!ret)
ret = -ERESTARTSYS;
break;
}
- schedule();
+ cond_resched();
}
chacha20_block(chacha_state, output);
base-commit: 0c3e7b36d92681bba4c73c198a35e5a806d6f3ff
--
2.35.1.1094.g7c7d902a7c-goog
next reply other threads:[~2022-04-06 0:10 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-04-05 16:39 Jann Horn [this message]
2022-04-05 18:07 ` Jason A. Donenfeld
2022-06-17 16:48 ` Sebastian Siewior
2022-06-17 22:47 ` Jason A. Donenfeld
2022-06-20 7:43 ` Sebastian Siewior
2022-06-20 8:14 ` Jason A. Donenfeld
2022-06-20 19:00 ` Linus Torvalds
2022-06-20 22:41 ` Jason A. Donenfeld
2022-06-21 7:03 ` Sebastian Siewior
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220405163931.1108442-1-jannh@google.com \
--to=jannh@google.com \
--cc=Jason@zx2c4.com \
--cc=linux-kernel@vger.kernel.org \
--cc=tytso@mit.edu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®