Skip to contentSkip to conversation

ANDROID: binder: synchronize_rcu() when using POLLFREE.

PATCH In review Martijn Coenen 1 participant 2 messages Feb 16, 2018 Android drivers

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ANDROID: binder: synchronize_rcu() when using POLLFREE.

To prevent races with ep_remove_waitqueue() removing the waitqueue at the same time.

---
 drivers/android/binder.c | 9 +++++++++
 1 file changed, 9 insertions(+)
drivers/android/binder.c +9 -0
index 15e3d3c2260d..359220f87e1d 100644
@@ -4376,6 +4376,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);
Signature · 6 lines
2.16.1.291.g4437f3f132-goog

_______________________________________________
devel mailing list
[email protected]
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel
#1 lore raw

Greg,

This is for 4.14 LTS and 4.16.

Thanks,
Martijn

Quoted 30 lines · Martijn Coenen

To prevent races with ep_remove_waitqueue() removing the waitqueue at the same time.

---
 drivers/android/binder.c | 9 +++++++++
 1 file changed, 9 insertions(+)
drivers/android/binder.c +9 -1
index 15e3d3c2260d..359220f87e1d 100644
@@ -4376,6 +4376,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);
--
Quoted 2 lines

2.16.1.291.g4437f3f132-goog

_______________________________________________
devel mailing list
[email protected]
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel