Skip to content

Commit a370003

Browse files
Todd Kjosgregkh
authored andcommitted
binder: fix possible UAF when freeing buffer
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> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent b710848 commit a370003

1 file changed

Lines changed: 14 additions & 2 deletions

File tree

‎drivers/android/binder.c‎

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1941,8 +1941,18 @@ static void binder_free_txn_fixups(struct binder_transaction *t)
19411941

19421942
static void binder_free_transaction(struct binder_transaction *t)
19431943
{
1944-
if (t->buffer)
1945-
t->buffer->transaction = NULL;
1944+
struct binder_proc *target_proc = t->to_proc;
1945+
1946+
if (target_proc) {
1947+
binder_inner_proc_lock(target_proc);
1948+
if (t->buffer)
1949+
t->buffer->transaction = NULL;
1950+
binder_inner_proc_unlock(target_proc);
1951+
}
1952+
/*
1953+
* If the transaction has no target_proc, then
1954+
* t->buffer->transaction has already been cleared.
1955+
*/
19461956
binder_free_txn_fixups(t);
19471957
kfree(t);
19481958
binder_stats_deleted(BINDER_STAT_TRANSACTION);
@@ -3551,10 +3561,12 @@ static void binder_transaction(struct binder_proc *proc,
35513561
static void
35523562
binder_free_buf(struct binder_proc *proc, struct binder_buffer *buffer)
35533563
{
3564+
binder_inner_proc_lock(proc);
35543565
if (buffer->transaction) {
35553566
buffer->transaction->buffer = NULL;
35563567
buffer->transaction = NULL;
35573568
}
3569+
binder_inner_proc_unlock(proc);
35583570
if (buffer->async_transaction && buffer->target_node) {
35593571
struct binder_node *buf_node;
35603572
struct binder_work *w;

0 commit comments

Comments
 (0)