From: Jann Horn Date: Tue, 5 Apr 2022 16:39:31 +0000 (+0200) Subject: random: check for signal_pending() outside of need_resched() check X-Git-Tag: v6.1-rc5~1604^2~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=1448769c9cdb69ad65287f4f7ab58bc5f2f5d7ba;p=platform%2Fkernel%2Flinux-starfive.git random: check for signal_pending() outside of need_resched() check 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, signaling 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 Signed-off-by: Jason A. Donenfeld --- diff --git a/drivers/char/random.c b/drivers/char/random.c index 47f01b1..394cbd8 100644 --- a/drivers/char/random.c +++ b/drivers/char/random.c @@ -549,13 +549,13 @@ static ssize_t get_random_bytes_user(void __user *buf, size_t nbytes) } 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);