Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 6c65c2d2 authored by Todd Kjos's avatar Todd Kjos Committed by shaohanlin
Browse files

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: default avatarTodd Kjos <tkjos@google.com>
parent 904bba25
Loading
Loading
Loading
Loading
+14 −2
Original line number Diff line number Diff line
@@ -2116,8 +2116,18 @@ static struct binder_thread *binder_get_txn_from_and_acq_inner(

static void binder_free_transaction(struct binder_transaction *t)
{
	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);
}
@@ -3656,10 +3666,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;