Skip to contentSkip to conversation

random: only wake up writers after zap if threshold was passed

PATCH In review Jason A. Donenfeld 2 participants 2 messages Feb 22, 2022 – Feb 24, 2022 Random number driver

lore
Share & tools
lore

Jason A. Donenfeld

author maintainer
#0 lore raw

PATCH 1/1 random: only wake up writers after zap if threshold was passed

The only time that we need to wake up /dev/random writers on RNDCLEARPOOL/RNDZAPPOOL is when we're changing from a value that is greater than or equal to POOL_MIN_BITS to zero, because if we're changing from below POOL_MIN_BITS to zero, the writers are already unblocked.

Cc Dominik Brodowski <[email protected]>
Cc Theodore Ts'o <[email protected]>
---
 drivers/char/random.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/char/random.c +1 -1
index a4dedeea35e9..536237a0f073 100644
@@ -1582,7 +1582,7 @@ static long random_ioctl(struct file *f, unsigned int cmd, unsigned long arg)
 		 */
 		if (!capable(CAP_SYS_ADMIN))
 			return -EPERM;
-		if (xchg(&input_pool.entropy_count, 0)) {
+		if (xchg(&input_pool.entropy_count, 0) >= POOL_MIN_BITS) {
 			wake_up_interruptible(&random_write_wait);
 			kill_fasync(&fasync, SIGIO, POLL_OUT);
 		}
Signature · 1 line
2.35.1
Reviewed-by on v1 1/1
#1 lore raw

Am Tue, Feb 22, 2022 at 02:05:03PM +0100 schrieb Jason A. Donenfeld:

Quoted 9 lines

The only time that we need to wake up /dev/random writers on RNDCLEARPOOL/RNDZAPPOOL is when we're changing from a value that is greater than or equal to POOL_MIN_BITS to zero, because if we're changing from below POOL_MIN_BITS to zero, the writers are already unblocked.

Cc Dominik Brodowski <[email protected]>
Cc Theodore Ts'o <[email protected]>

Thanks,
Dominik