lkml.org 
[lkml]   [2022]   [Apr]   [5]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH] random: Fix signal_pending() usage
Date
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

\
 
 \ /
  Last update: 2022-04-06 01:52    [W:0.106 / U:0.124 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site