Skip to content

Commit f5cb779

Browse files
Martijn Coenengregkh
authored andcommitted
ANDROID: binder: remove waitqueue when thread exits.
binder_poll() passes the thread->wait waitqueue that can be slept on for work. When a thread that uses epoll explicitly exits using BINDER_THREAD_EXIT, the waitqueue is freed, but it is never removed from the corresponding epoll data structure. When the process subsequently exits, the epoll cleanup code tries to access the waitlist, which results in a use-after-free. Prevent this by using POLLFREE when the thread exits. Signed-off-by: Martijn Coenen <[email protected]> Reported-by: syzbot <[email protected]> Cc: stable <[email protected]> # 4.14 Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 16ae30e commit f5cb779

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

drivers/android/binder.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4365,6 +4365,18 @@ static int binder_thread_release(struct binder_proc *proc,
43654365
if (t)
43664366
spin_lock(&t->lock);
43674367
}
4368+
4369+
/*
4370+
* If this thread used poll, make sure we remove the waitqueue
4371+
* from any epoll data structures holding it with POLLFREE.
4372+
* waitqueue_active() is safe to use here because we're holding
4373+
* the inner lock.
4374+
*/
4375+
if ((thread->looper & BINDER_LOOPER_STATE_POLL) &&
4376+
waitqueue_active(&thread->wait)) {
4377+
wake_up_poll(&thread->wait, POLLHUP | POLLFREE);
4378+
}
4379+
43684380
binder_inner_proc_unlock(thread->proc);
43694381

43704382
if (send_reply)

0 commit comments

Comments
 (0)