Skip to content

Commit 97830f3

Browse files
Carlos Llamasgregkh
authored andcommitted
binder: signal epoll threads of self-work
In (e)poll mode, threads often depend on I/O events to determine when data is ready for consumption. Within binder, a thread may initiate a command via BINDER_WRITE_READ without a read buffer and then make use of epoll_wait() or similar to consume any responses afterwards. It is then crucial that epoll threads are signaled via wakeup when they queue their own work. Otherwise, they risk waiting indefinitely for an event leaving their work unhandled. What is worse, subsequent commands won't trigger a wakeup either as the thread has pending work. Fixes: 457b9a6 ("Staging: android: add binder driver") Cc: Arve Hjønnevåg <arve@android.com> Cc: Martijn Coenen <maco@android.com> Cc: Alice Ryhl <aliceryhl@google.com> Cc: Steven Moreland <smoreland@google.com> Cc: stable@vger.kernel.org # v4.19+ Signed-off-by: Carlos Llamas <cmllamas@google.com> Link: https://lore.kernel.org/r/20240131215347.1808751-1-cmllamas@google.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent ac9762a commit 97830f3

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

drivers/android/binder.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -478,6 +478,16 @@ binder_enqueue_thread_work_ilocked(struct binder_thread *thread,
478478
{
479479
WARN_ON(!list_empty(&thread->waiting_thread_node));
480480
binder_enqueue_work_ilocked(work, &thread->todo);
481+
482+
/* (e)poll-based threads require an explicit wakeup signal when
483+
* queuing their own work; they rely on these events to consume
484+
* messages without I/O block. Without it, threads risk waiting
485+
* indefinitely without handling the work.
486+
*/
487+
if (thread->looper & BINDER_LOOPER_STATE_POLL &&
488+
thread->pid == current->pid && !thread->process_todo)
489+
wake_up_interruptible_sync(&thread->wait);
490+
481491
thread->process_todo = true;
482492
}
483493

0 commit comments

Comments
 (0)