linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] random: wake up /dev/random writers after zap
@ 2022-01-28 22:49 Jason A. Donenfeld
  2022-01-29 15:08 ` Dominik Brodowski
  0 siblings, 1 reply; 2+ messages in thread
From: Jason A. Donenfeld @ 2022-01-28 22:49 UTC (permalink / raw)
  To: linux-kernel, tytso, linux; +Cc: Jason A. Donenfeld

When account() is called, and the amount of entropy dips below
random_write_wakeup_bits, we wake up the random writers, so that they
can write some more in. However, the RNDZAPENTCNT/RNDCLEARPOOL ioctl
sets the entropy count to zero -- a potential reduction just like
account() -- but does not unblock writers. This commit adds the missing
logic to that ioctl to unblock waiting writers.

Cc: Dominik Brodowski <linux@dominikbrodowski.net>
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
---
 drivers/char/random.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/char/random.c b/drivers/char/random.c
index 6919837fe4e9..d4111220bbb0 100644
--- a/drivers/char/random.c
+++ b/drivers/char/random.c
@@ -1856,7 +1856,10 @@ static long random_ioctl(struct file *f, unsigned int cmd, unsigned long arg)
 		 */
 		if (!capable(CAP_SYS_ADMIN))
 			return -EPERM;
-		input_pool.entropy_count = 0;
+		if (xchg(&input_pool.entropy_count, 0) && random_write_wakeup_bits) {
+			wake_up_interruptible(&random_write_wait);
+			kill_fasync(&fasync, SIGIO, POLL_OUT);
+		}
 		return 0;
 	case RNDRESEEDCRNG:
 		if (!capable(CAP_SYS_ADMIN))
-- 
2.35.0


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

* Re: [PATCH] random: wake up /dev/random writers after zap
  2022-01-28 22:49 [PATCH] random: wake up /dev/random writers after zap Jason A. Donenfeld
@ 2022-01-29 15:08 ` Dominik Brodowski
  0 siblings, 0 replies; 2+ messages in thread
From: Dominik Brodowski @ 2022-01-29 15:08 UTC (permalink / raw)
  To: Jason A. Donenfeld; +Cc: linux-kernel, tytso

Am Fri, Jan 28, 2022 at 11:49:06PM +0100 schrieb Jason A. Donenfeld:
> When account() is called, and the amount of entropy dips below
> random_write_wakeup_bits, we wake up the random writers, so that they
> can write some more in. However, the RNDZAPENTCNT/RNDCLEARPOOL ioctl
> sets the entropy count to zero -- a potential reduction just like
> account() -- but does not unblock writers. This commit adds the missing
> logic to that ioctl to unblock waiting writers.
> 
> Cc: Dominik Brodowski <linux@dominikbrodowski.net>
> Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>

Reviewed-by: Dominik Brodowski <linux@dominikbrodowski.net>

Thanks,
	Dominik

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

end of thread, other threads:[~2022-01-29 15:09 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-28 22:49 [PATCH] random: wake up /dev/random writers after zap Jason A. Donenfeld
2022-01-29 15:08 ` Dominik Brodowski

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).