Skip to content

Commit 128f2bf

Browse files
committed
Merge tag 'random_for_linus_stable' of git://git.kernel.org/pub/scm/linux/kernel/git/tytso/random
Pull /dev/random fix from Ted Ts'o: "Fix a soft lockup regression when reading from /dev/random in early boot" * tag 'random_for_linus_stable' of git://git.kernel.org/pub/scm/linux/kernel/git/tytso/random: random: fix soft lockup when trying to read from an uninitialized blocking pool
2 parents 35efb51 + 58be010 commit 128f2bf

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

drivers/char/random.c

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -772,8 +772,11 @@ static void credit_entropy_bits(struct entropy_store *r, int nbits)
772772
if (cmpxchg(&r->entropy_count, orig, entropy_count) != orig)
773773
goto retry;
774774

775-
if (has_initialized)
775+
if (has_initialized) {
776776
r->initialized = 1;
777+
wake_up_interruptible(&random_read_wait);
778+
kill_fasync(&fasync, SIGIO, POLL_IN);
779+
}
777780

778781
trace_credit_entropy_bits(r->name, nbits,
779782
entropy_count >> ENTROPY_SHIFT, _RET_IP_);
@@ -789,6 +792,13 @@ static void credit_entropy_bits(struct entropy_store *r, int nbits)
789792
entropy_bits = r->entropy_count >> ENTROPY_SHIFT;
790793
}
791794

795+
/* initialize the blocking pool if necessary */
796+
if (entropy_bits >= random_read_wakeup_bits &&
797+
!other->initialized) {
798+
schedule_work(&other->push_work);
799+
return;
800+
}
801+
792802
/* should we wake readers? */
793803
if (entropy_bits >= random_read_wakeup_bits &&
794804
wq_has_sleeper(&random_read_wait)) {
@@ -1936,8 +1946,8 @@ _random_read(int nonblock, char __user *buf, size_t nbytes)
19361946
return -EAGAIN;
19371947

19381948
wait_event_interruptible(random_read_wait,
1939-
ENTROPY_BITS(&input_pool) >=
1940-
random_read_wakeup_bits);
1949+
blocking_pool.initialized &&
1950+
(ENTROPY_BITS(&input_pool) >= random_read_wakeup_bits));
19411951
if (signal_pending(current))
19421952
return -ERESTARTSYS;
19431953
}

0 commit comments

Comments
 (0)