diff options
author | Kent Overstreet <kent.overstreet@gmail.com> | 2019-09-03 09:25:45 -0400 |
---|---|---|
committer | Jens Axboe <axboe@kernel.dk> | 2019-09-03 10:08:31 -0400 |
commit | a22a9602b88fabf10847f238ff81fde5f906fef7 (patch) | |
tree | cdda0a4f2abcfaf8627fec61a16de34e19a2223b /drivers/md | |
parent | d66c9920c0cf984cf99cab5036fd5f3a1b7fba46 (diff) |
closures: fix a race on wakeup from closure_sync
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>
Diffstat (limited to 'drivers/md')
-rw-r--r-- | drivers/md/bcache/closure.c | 10 |
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 { | |||
105 | 105 | ||
106 | static void closure_sync_fn(struct closure *cl) | 106 | static void closure_sync_fn(struct closure *cl) |
107 | { | 107 | { |
108 | cl->s->done = 1; | 108 | struct closure_syncer *s = cl->s; |
109 | wake_up_process(cl->s->task); | 109 | struct task_struct *p; |
110 | |||
111 | rcu_read_lock(); | ||
112 | p = READ_ONCE(s->task); | ||
113 | s->done = 1; | ||
114 | wake_up_process(p); | ||
115 | rcu_read_unlock(); | ||
110 | } | 116 | } |
111 | 117 | ||
112 | void __sched __closure_sync(struct closure *cl) | 118 | void __sched __closure_sync(struct closure *cl) |