summaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorKent Overstreet <kent.overstreet@gmail.com>2019-09-03 21:25:45 +0800
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2019-10-05 15:12:02 +0200
commiteb35e355da6868522d4b0c17c2cba6e4c3b6f7c6 (patch)
tree8986e7b11c5a4ee935654053d5d435ed800e0f95 /drivers
parent7f8a4608585def33ece1c5ad3952f93ca6348717 (diff)
downloadlinux-stable-eb35e355da6868522d4b0c17c2cba6e4c3b6f7c6.tar.gz
linux-stable-eb35e355da6868522d4b0c17c2cba6e4c3b6f7c6.tar.bz2
linux-stable-eb35e355da6868522d4b0c17c2cba6e4c3b6f7c6.zip
closures: fix a race on wakeup from closure_sync
[ Upstream commit a22a9602b88fabf10847f238ff81fde5f906fef7 ] The race was when a thread using closure_sync() notices cl->s->done == 1 before the thread calling closure_put() calls wake_up_process(). Then, it's possible for that thread to return and exit just before wake_up_process() is called - so we're trying to wake up a process that no longer exists. rcu_read_lock() is sufficient to protect against this, as there's an rcu barrier somewhere in the process teardown path. Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com> Acked-by: Coly Li <colyli@suse.de> Signed-off-by: Jens Axboe <axboe@kernel.dk> Signed-off-by: Sasha Levin <sashal@kernel.org>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/md/bcache/closure.c10
1 files changed, 8 insertions, 2 deletions
diff --git a/drivers/md/bcache/closure.c b/drivers/md/bcache/closure.c
index 73f5319295bc..c12cd809ab19 100644
--- a/drivers/md/bcache/closure.c
+++ b/drivers/md/bcache/closure.c
@@ -105,8 +105,14 @@ struct closure_syncer {
static void closure_sync_fn(struct closure *cl)
{
- cl->s->done = 1;
- wake_up_process(cl->s->task);
+ struct closure_syncer *s = cl->s;
+ struct task_struct *p;
+
+ rcu_read_lock();
+ p = READ_ONCE(s->task);
+ s->done = 1;
+ wake_up_process(p);
+ rcu_read_unlock();
}
void __sched __closure_sync(struct closure *cl)