Skip to content

Commit 07d1db1

Browse files
toddkjosgregkh
authored andcommitted
binder: don't detect sender/target during buffer cleanup
commit 32e9f56 upstream. When freeing txn buffers, binder_transaction_buffer_release() attempts to detect whether the current context is the target by comparing current->group_leader to proc->tsk. This is an unreliable test. Instead explicitly pass an 'is_failure' boolean. Detecting the sender was being used as a way to tell if the transaction failed to be sent. When cleaning up after failing to send a transaction, there is no need to close the fds associated with a BINDER_TYPE_FDA object. Now 'is_failure' can be used to accurately detect this case. Fixes: 44d8047 ("binder: use standard functions to allocate fds") Cc: stable <stable@vger.kernel.org> Acked-by: Christian Brauner <christian.brauner@ubuntu.com> Signed-off-by: Todd Kjos <tkjos@google.com> Link: https://lore.kernel.org/r/20211015233811.3532235-1-tkjos@google.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 42681b9 commit 07d1db1

1 file changed

Lines changed: 7 additions & 7 deletions

File tree

‎drivers/android/binder.c‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2254,7 +2254,7 @@ static void binder_transaction_buffer_release(struct binder_proc *proc,
22542254
binder_dec_node(buffer->target_node, 1, 0);
22552255

22562256
off_start_offset = ALIGN(buffer->data_size, sizeof(void *));
2257-
off_end_offset = is_failure ? failed_at :
2257+
off_end_offset = is_failure && failed_at ? failed_at :
22582258
off_start_offset + buffer->offsets_size;
22592259
for (buffer_offset = off_start_offset; buffer_offset < off_end_offset;
22602260
buffer_offset += sizeof(binder_size_t)) {
@@ -2340,9 +2340,8 @@ static void binder_transaction_buffer_release(struct binder_proc *proc,
23402340
binder_size_t fd_buf_size;
23412341
binder_size_t num_valid;
23422342

2343-
if (proc->tsk != current->group_leader) {
2343+
if (is_failure) {
23442344
/*
2345-
* Nothing to do if running in sender context
23462345
* The fd fixups have not been applied so no
23472346
* fds need to be closed.
23482347
*/
@@ -3544,6 +3543,7 @@ static void binder_transaction(struct binder_proc *proc,
35443543
* binder_free_buf() - free the specified buffer
35453544
* @proc: binder proc that owns buffer
35463545
* @buffer: buffer to be freed
3546+
* @is_failure: failed to send transaction
35473547
*
35483548
* If buffer for an async transaction, enqueue the next async
35493549
* transaction from the node.
@@ -3553,7 +3553,7 @@ static void binder_transaction(struct binder_proc *proc,
35533553
static void
35543554
binder_free_buf(struct binder_proc *proc,
35553555
struct binder_thread *thread,
3556-
struct binder_buffer *buffer)
3556+
struct binder_buffer *buffer, bool is_failure)
35573557
{
35583558
binder_inner_proc_lock(proc);
35593559
if (buffer->transaction) {
@@ -3581,7 +3581,7 @@ binder_free_buf(struct binder_proc *proc,
35813581
binder_node_inner_unlock(buf_node);
35823582
}
35833583
trace_binder_transaction_buffer_release(buffer);
3584-
binder_transaction_buffer_release(proc, thread, buffer, 0, false);
3584+
binder_transaction_buffer_release(proc, thread, buffer, 0, is_failure);
35853585
binder_alloc_free_buf(&proc->alloc, buffer);
35863586
}
35873587

@@ -3782,7 +3782,7 @@ static int binder_thread_write(struct binder_proc *proc,
37823782
proc->pid, thread->pid, (u64)data_ptr,
37833783
buffer->debug_id,
37843784
buffer->transaction ? "active" : "finished");
3785-
binder_free_buf(proc, thread, buffer);
3785+
binder_free_buf(proc, thread, buffer, false);
37863786
break;
37873787
}
37883788

@@ -4470,7 +4470,7 @@ static int binder_thread_read(struct binder_proc *proc,
44704470
buffer->transaction = NULL;
44714471
binder_cleanup_transaction(t, "fd fixups failed",
44724472
BR_FAILED_REPLY);
4473-
binder_free_buf(proc, thread, buffer);
4473+
binder_free_buf(proc, thread, buffer, true);
44744474
binder_debug(BINDER_DEBUG_FAILED_TRANSACTION,
44754475
"%d:%d %stransaction %d fd fixups failed %d/%d, line %d\n",
44764476
proc->pid, thread->pid,

0 commit comments

Comments
 (0)