stable.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 4.14,4.19] binder: fix possible UAF when freeing buffer
@ 2019-07-29 22:16 Todd Kjos
  2019-07-31  9:47 ` Greg KH
  0 siblings, 1 reply; 2+ messages in thread
From: Todd Kjos @ 2019-07-29 22:16 UTC (permalink / raw)
  To: tkjos, gregkh, arve, maco, stable; +Cc: joel, kernel-team, Todd Kjos

From: Todd Kjos <tkjos@android.com>

commit a370003cc301d4361bae20c9ef615f89bf8d1e8a upstream

There is a race between the binder driver cleaning
up a completed transaction via binder_free_transaction()
and a user calling binder_ioctl(BC_FREE_BUFFER) to
release a buffer. It doesn't matter which is first but
they need to be protected against running concurrently
which can result in a UAF.

Signed-off-by: Todd Kjos <tkjos@google.com>
Cc: stable <stable@vger.kernel.org> # 4.14 4.19
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
 drivers/android/binder.c | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)

diff --git a/drivers/android/binder.c b/drivers/android/binder.c
index 5d67f5fec6c1b..2decb1a5a8e2f 100644
--- a/drivers/android/binder.c
+++ b/drivers/android/binder.c
@@ -1960,8 +1960,18 @@ static struct binder_thread *binder_get_txn_from_and_acq_inner(
 
 static void binder_free_transaction(struct binder_transaction *t)
 {
-	if (t->buffer)
-		t->buffer->transaction = NULL;
+	struct binder_proc *target_proc = t->to_proc;
+
+	if (target_proc) {
+		binder_inner_proc_lock(target_proc);
+		if (t->buffer)
+			t->buffer->transaction = NULL;
+		binder_inner_proc_unlock(target_proc);
+	}
+	/*
+	 * If the transaction has no target_proc, then
+	 * t->buffer->transaction has already been cleared.
+	 */
 	kfree(t);
 	binder_stats_deleted(BINDER_STAT_TRANSACTION);
 }
@@ -3484,10 +3494,12 @@ static int binder_thread_write(struct binder_proc *proc,
 				     buffer->debug_id,
 				     buffer->transaction ? "active" : "finished");
 
+			binder_inner_proc_lock(proc);
 			if (buffer->transaction) {
 				buffer->transaction->buffer = NULL;
 				buffer->transaction = NULL;
 			}
+			binder_inner_proc_unlock(proc);
 			if (buffer->async_transaction && buffer->target_node) {
 				struct binder_node *buf_node;
 				struct binder_work *w;
-- 
2.22.0.709.g102302147b-goog


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH 4.14,4.19] binder: fix possible UAF when freeing buffer
  2019-07-29 22:16 [PATCH 4.14,4.19] binder: fix possible UAF when freeing buffer Todd Kjos
@ 2019-07-31  9:47 ` Greg KH
  0 siblings, 0 replies; 2+ messages in thread
From: Greg KH @ 2019-07-31  9:47 UTC (permalink / raw)
  To: Todd Kjos; +Cc: tkjos, arve, maco, stable, joel, kernel-team

On Mon, Jul 29, 2019 at 03:16:06PM -0700, Todd Kjos wrote:
> From: Todd Kjos <tkjos@android.com>
> 
> commit a370003cc301d4361bae20c9ef615f89bf8d1e8a upstream
> 
> There is a race between the binder driver cleaning
> up a completed transaction via binder_free_transaction()
> and a user calling binder_ioctl(BC_FREE_BUFFER) to
> release a buffer. It doesn't matter which is first but
> they need to be protected against running concurrently
> which can result in a UAF.
> 
> Signed-off-by: Todd Kjos <tkjos@google.com>
> Cc: stable <stable@vger.kernel.org> # 4.14 4.19
> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> ---
>  drivers/android/binder.c | 16 ++++++++++++++--
>  1 file changed, 14 insertions(+), 2 deletions(-)

Thanks for the backport, now queued up.

greg k-h

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2019-07-31  9:48 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-07-29 22:16 [PATCH 4.14,4.19] binder: fix possible UAF when freeing buffer Todd Kjos
2019-07-31  9:47 ` Greg KH

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).