Skip to content

Commit

Permalink
closures: fix a race on wakeup from closure_sync
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Kent Overstreet authored and Jens Axboe committed Sep 3, 2019
1 parent d66c992 commit a22a960
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions drivers/md/bcache/closure.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit a22a960

Please sign in to comment.