aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTheodore Ts'o <tytso@mit.edu>2013-03-04 11:59:12 -0500
committerTARKZiM <tom8476oo@gmail.com>2022-08-25 20:05:39 +0800
commit9e779e1e2861f523633e53c2faa2ceb58426d9e9 (patch)
tree6900de7afa5d0f7b6a42a0391f50ca568a8b5dc3
parent9220c20fb11d1e6cf889a708fa47afbda50eab0f (diff)
random: fix locking dependency with the tasklist_lock
Commit 6133705494bb introduced a circular lock dependency because posix_cpu_timers_exit() is called by release_task(), which is holding a writer lock on tasklist_lock, and this can cause a deadlock since kill_fasync() gets called with nonblocking_pool.lock taken. There's no reason why kill_fasync() needs to be taken while the random pool is locked, so move it out to fix this locking dependency. Signed-off-by: "Theodore Ts'o" <tytso@mit.edu> Reported-by: Russ Dill <Russ.Dill@gmail.com> Cc: stable@kernel.org
-rw-r--r--drivers/char/random.c12
1 files changed, 8 insertions, 4 deletions
diff --git a/drivers/char/random.c b/drivers/char/random.c
index 12083d8c8ab..7fd08ea3467 100644
--- a/drivers/char/random.c
+++ b/drivers/char/random.c
@@ -871,6 +871,7 @@ static size_t account(struct entropy_store *r, size_t nbytes, int min,
int reserved)
{
unsigned long flags;
+ int wakeup_write = 0;
/* Hold lock while accounting */
spin_lock_irqsave(&r->lock, flags);
@@ -900,10 +901,8 @@ retry:
goto retry;
}
- if (entropy_count < random_write_wakeup_thresh) {
- wake_up_interruptible(&random_write_wait);
- kill_fasync(&fasync, SIGIO, POLL_OUT);
- }
+ if (entropy_count < random_write_wakeup_thresh)
+ wakeup_write = 1;
}
DEBUG_ENT("debiting %zu entropy credits from %s%s\n",
@@ -911,6 +910,11 @@ retry:
spin_unlock_irqrestore(&r->lock, flags);
+ if (wakeup_write) {
+ wake_up_interruptible(&random_write_wait);
+ kill_fasync(&fasync, SIGIO, POLL_OUT);
+ }
+
return nbytes;
}