binder: fix use-after-free in binder_transaction()
authorTodd Kjos <tkjos@android.com>
Fri, 29 Sep 2017 22:39:49 +0000 (15:39 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 4 Oct 2017 09:25:10 +0000 (11:25 +0200)
commit512cf465ee01eb23936a9e6ed0b6414eccb00853
treeacd6475a037326bd58015094502d79b42165c436
parent192b2d78722ffea188e5ec6ae5d55010dce05a4b
binder: fix use-after-free in binder_transaction()

User-space normally keeps the node alive when creating a transaction
since it has a reference to the target. The local strong ref keeps it
alive if the sending process dies before the target process processes
the transaction. If the source process is malicious or has a reference
counting bug, this can fail.

In this case, when we attempt to decrement the node in the failure
path, the node has already been freed.

This is fixed by taking a tmpref on the node while constructing
the transaction. To avoid re-acquiring the node lock and inner
proc lock to increment the proc's tmpref, a helper is used that
does the ref increments on both the node and proc.

Signed-off-by: Todd Kjos <tkjos@google.com>
Cc: stable <stable@vger.kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/android/binder.c