From: Martijn Coenen Date: Fri, 16 Feb 2018 08:47:15 +0000 (+0100) Subject: UPSTREAM: ANDROID: binder: synchronize_rcu() when using POLLFREE. X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=c0bf025b856adc38e5cabfcd37736e126f7bb593;p=GitHub%2FLineageOS%2Fandroid_kernel_samsung_universal7580.git UPSTREAM: ANDROID: binder: synchronize_rcu() when using POLLFREE. To prevent races with ep_remove_waitqueue() removing the waitqueue at the same time. Reported-by: syzbot+a2a3c4909716e271487e@syzkaller.appspotmail.com Signed-off-by: Martijn Coenen Cc: stable # 4.14+ Signed-off-by: Greg Kroah-Hartman (cherry picked from commit 5eeb2ca02a2f6084fc57ae5c244a38baab07033a) Change-Id: Ia0089448079c78d0ab0b57303faf838e9e5ee797 --- diff --git a/drivers/android/binder.c b/drivers/android/binder.c index f4aaae464c4..f3f5d7a08f3 100644 --- a/drivers/android/binder.c +++ b/drivers/android/binder.c @@ -4543,6 +4543,15 @@ static int binder_thread_release(struct binder_proc *proc, binder_inner_proc_unlock(thread->proc); + /* + * This is needed to avoid races between wake_up_poll() above and + * and ep_remove_waitqueue() called for other reasons (eg the epoll file + * descriptor being closed); ep_remove_waitqueue() holds an RCU read + * lock, so we can be sure it's done after calling synchronize_rcu(). + */ + if (thread->looper & BINDER_LOOPER_STATE_POLL) + synchronize_rcu(); + if (send_reply) binder_send_failed_reply(send_reply, BR_DEAD_REPLY); binder_release_work(proc, &thread->todo);