Skip to content

Commit 32e9f56

Browse files
toddkjosgregkh
authored andcommitted
binder: don't detect sender/target during buffer cleanup
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 <[email protected]> Acked-by: Christian Brauner <[email protected]> Signed-off-by: Todd Kjos <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent be24dd4 commit 32e9f56

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

drivers/android/binder.c

+7-7
Original file line numberDiff line numberDiff line change
@@ -1870,7 +1870,7 @@ static void binder_transaction_buffer_release(struct binder_proc *proc,
18701870
binder_dec_node(buffer->target_node, 1, 0);
18711871

18721872
off_start_offset = ALIGN(buffer->data_size, sizeof(void *));
1873-
off_end_offset = is_failure ? failed_at :
1873+
off_end_offset = is_failure && failed_at ? failed_at :
18741874
off_start_offset + buffer->offsets_size;
18751875
for (buffer_offset = off_start_offset; buffer_offset < off_end_offset;
18761876
buffer_offset += sizeof(binder_size_t)) {
@@ -1956,9 +1956,8 @@ static void binder_transaction_buffer_release(struct binder_proc *proc,
19561956
binder_size_t fd_buf_size;
19571957
binder_size_t num_valid;
19581958

1959-
if (proc->tsk != current->group_leader) {
1959+
if (is_failure) {
19601960
/*
1961-
* Nothing to do if running in sender context
19621961
* The fd fixups have not been applied so no
19631962
* fds need to be closed.
19641963
*/
@@ -3185,6 +3184,7 @@ static void binder_transaction(struct binder_proc *proc,
31853184
* binder_free_buf() - free the specified buffer
31863185
* @proc: binder proc that owns buffer
31873186
* @buffer: buffer to be freed
3187+
* @is_failure: failed to send transaction
31883188
*
31893189
* If buffer for an async transaction, enqueue the next async
31903190
* transaction from the node.
@@ -3194,7 +3194,7 @@ static void binder_transaction(struct binder_proc *proc,
31943194
static void
31953195
binder_free_buf(struct binder_proc *proc,
31963196
struct binder_thread *thread,
3197-
struct binder_buffer *buffer)
3197+
struct binder_buffer *buffer, bool is_failure)
31983198
{
31993199
binder_inner_proc_lock(proc);
32003200
if (buffer->transaction) {
@@ -3222,7 +3222,7 @@ binder_free_buf(struct binder_proc *proc,
32223222
binder_node_inner_unlock(buf_node);
32233223
}
32243224
trace_binder_transaction_buffer_release(buffer);
3225-
binder_transaction_buffer_release(proc, thread, buffer, 0, false);
3225+
binder_transaction_buffer_release(proc, thread, buffer, 0, is_failure);
32263226
binder_alloc_free_buf(&proc->alloc, buffer);
32273227
}
32283228

@@ -3424,7 +3424,7 @@ static int binder_thread_write(struct binder_proc *proc,
34243424
proc->pid, thread->pid, (u64)data_ptr,
34253425
buffer->debug_id,
34263426
buffer->transaction ? "active" : "finished");
3427-
binder_free_buf(proc, thread, buffer);
3427+
binder_free_buf(proc, thread, buffer, false);
34283428
break;
34293429
}
34303430

@@ -4117,7 +4117,7 @@ static int binder_thread_read(struct binder_proc *proc,
41174117
buffer->transaction = NULL;
41184118
binder_cleanup_transaction(t, "fd fixups failed",
41194119
BR_FAILED_REPLY);
4120-
binder_free_buf(proc, thread, buffer);
4120+
binder_free_buf(proc, thread, buffer, true);
41214121
binder_debug(BINDER_DEBUG_FAILED_TRANSACTION,
41224122
"%d:%d %stransaction %d fd fixups failed %d/%d, line %d\n",
41234123
proc->pid, thread->pid,

0 commit comments

Comments
 (0)