Commit 0e3b977a authored by Todd Kjos's avatar Todd Kjos Committed by Greg Kroah-Hartman

binder: fix possible UAF when freeing buffer

commit a370003c 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: default avatarTodd Kjos <tkjos@google.com>
Cc: stable <stable@vger.kernel.org>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 91a7616a
...@@ -1950,8 +1950,18 @@ static void binder_free_txn_fixups(struct binder_transaction *t) ...@@ -1950,8 +1950,18 @@ static void binder_free_txn_fixups(struct binder_transaction *t)
static void binder_free_transaction(struct binder_transaction *t) static void binder_free_transaction(struct binder_transaction *t)
{ {
if (t->buffer) struct binder_proc *target_proc = t->to_proc;
t->buffer->transaction = NULL;
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.
*/
binder_free_txn_fixups(t); binder_free_txn_fixups(t);
kfree(t); kfree(t);
binder_stats_deleted(BINDER_STAT_TRANSACTION); binder_stats_deleted(BINDER_STAT_TRANSACTION);
...@@ -3550,10 +3560,12 @@ static void binder_transaction(struct binder_proc *proc, ...@@ -3550,10 +3560,12 @@ static void binder_transaction(struct binder_proc *proc,
static void static void
binder_free_buf(struct binder_proc *proc, struct binder_buffer *buffer) binder_free_buf(struct binder_proc *proc, struct binder_buffer *buffer)
{ {
binder_inner_proc_lock(proc);
if (buffer->transaction) { if (buffer->transaction) {
buffer->transaction->buffer = NULL; buffer->transaction->buffer = NULL;
buffer->transaction = NULL; buffer->transaction = NULL;
} }
binder_inner_proc_unlock(proc);
if (buffer->async_transaction && buffer->target_node) { if (buffer->async_transaction && buffer->target_node) {
struct binder_node *buf_node; struct binder_node *buf_node;
struct binder_work *w; struct binder_work *w;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment