[PATCH 4.9 038/145] binder: check for binder_thread allocation failure in binder_poll()

From: Greg Kroah-Hartman
Date: Fri Feb 23 2018 - 13:43:56 EST


4.9-stable review patch. If anyone has any objections, please let me know.

------------------

From: Eric Biggers <ebiggers@xxxxxxxxxx>

commit f88982679f54f75daa5b8eff3da72508f1e7422f upstream.

If the kzalloc() in binder_get_thread() fails, binder_poll()
dereferences the resulting NULL pointer.

Fix it by returning POLLERR if the memory allocation failed.

This bug was found by syzkaller using fault injection.

Reported-by: syzbot <syzkaller@xxxxxxxxxxxxxxxx>
Fixes: 457b9a6f09f0 ("Staging: android: add binder driver")
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Eric Biggers <ebiggers@xxxxxxxxxx>
Signed-off-by: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx>

---
drivers/android/binder.c | 2 ++
1 file changed, 2 insertions(+)

--- a/drivers/android/binder.c
+++ b/drivers/android/binder.c
@@ -2628,6 +2628,8 @@ static unsigned int binder_poll(struct f
binder_lock(__func__);

thread = binder_get_thread(proc);
+ if (!thread)
+ return POLLERR;

wait_for_proc_work = thread->transaction_stack == NULL &&
list_empty(&thread->todo) && thread->return_error == BR_OK;