binder: fix possible UAF when freeing buffer
PATCH 1/1 binder: fix possible UAF when freeing buffer
From: Todd Kjos <[email protected]>
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.
--- drivers/android/binder.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-)
drivers/android/binder.c +14 -2
@@ -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;
Signature · 1 line
2.22.0.709.g102302147b-goog
Greg KH
maintainerQuoted 11 lines · Todd Kjos
From: Todd Kjos <[email protected]>
commit
a370003cc301d4361bae20c9ef615f89bf8d1e8aupstreamThere is a race between the binder driver cleaning up a completed transaction via
binder_free_transaction()and a user callingbinder_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.
Quoted 6 lines
Signed-off-by Todd Kjos <[email protected]>Cc stable <[email protected]> # 4.14 4.19Signed-off-by Greg Kroah-Hartman <[email protected]>--- drivers/android/binder.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-)
Thanks for the backport, now queued up.
greg k-h