mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] random: Fix signal_pending() usage
@ 2022-04-05 16:39 Jann Horn
  2022-04-05 18:07 ` Jason A. Donenfeld
  0 siblings, 1 reply; 9+ messages in thread
From: Jann Horn @ 2022-04-05 16:39 UTC (permalink / raw)
  To: Theodore Ts'o, Jason A . Donenfeld; +Cc: linux-kernel, Jann Horn

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


^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2022-06-21  7:03 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-05 16:39 [PATCH] random: Fix signal_pending() usage Jann Horn
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

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®