Skip to contentSkip to conversation

binder: fix sender fd 0 close and file refcount leak on TF_UPDATE_TXN

PATCH In review Hui Peng 3 participants 4 messages Sep 19 – Sep 23 Android drivers

lore
Share & tools
lore

Hui Peng

author
#0 lore raw

PATCH 1/1 binder: fix sender fd 0 close and file refcount leak on TF_UPDATE_TXN

In binder_proc_transaction(), when a oneway transaction with TF_UPDATE_TXN supersedes an outdated pending transaction (t_outdated), the driver calls binder_release_entire_buffer(proc, NULL, buffer, false) and kfree(t_outdated).

Passing is_failure = false while buffer->transaction has already been set to NULL causes two bugs when t_outdated contained BINDER_TYPE_FDA or BINDER_TYPE_FD objects:

1. For BINDER_TYPE_FDA, binder_translate_fd_array() never wrote recipient file descriptors into the buffer (it only appended struct file * entries to t_outdated->fd_fixups), so the FD array in buffer still contains zeros (or sender-supplied offsets). Because is_failure is false, binder_transaction_buffer_release() executes the !is_failure branch on BINDER_TYPE_FDA and calls binder_deferred_fd_close(fd) (closing fd 0 in current->files, which is the **sender** process!).
2. t_outdated is freed via kfree(t_outdated) without calling binder_free_txn_fixups(t_outdated), permanently leaking every translated struct file reference in t_outdated->fd_fixups.

Pass is_failure = true to binder_release_entire_buffer() and call binder_free_txn_fixups(t_outdated) before freeing t_outdated.

Fixes 9864bb480133 ("Binder: add TF_UPDATE_TXN to replace outdated txn")
Fixes bdc1c5fac982 ("binder: fix UAF caused by faulty buffer cleanup")
Assisted-by LLM
---
 drivers/android/binder.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/android/binder.c +2 -1
index 8f2ef1bd539f..bc8bc9ee43a5 100644
@@ -2930,8 +2930,9 @@ static int binder_proc_transaction(struct binder_transaction *t,
 		t_outdated->buffer = NULL;
 		buffer->transaction = NULL;
 		trace_binder_transaction_update_buffer_release(buffer);
-		binder_release_entire_buffer(proc, NULL, buffer, false);
+		binder_release_entire_buffer(proc, NULL, buffer, true);
 		binder_alloc_free_buf(&proc->alloc, buffer);
+		binder_free_txn_fixups(t_outdated);
 		kfree(t_outdated);
 		binder_stats_deleted(BINDER_STAT_TRANSACTION);
 	}
Signature · 1 line
2.55.0.1082.g2b9226bbc0-goog
maintainer
#1 lore raw
Quoted 21 lines · Hui Peng

In binder_proc_transaction(), when a oneway transaction with TF_UPDATE_TXN supersedes an outdated pending transaction (t_outdated), the driver calls binder_release_entire_buffer(proc, NULL, buffer, false) and kfree(t_outdated).

Passing is_failure = false while buffer->transaction has already been set to NULL causes two bugs when t_outdated contained BINDER_TYPE_FDA or BINDER_TYPE_FD objects:

1. For BINDER_TYPE_FDA, binder_translate_fd_array() never wrote recipient file descriptors into the buffer (it only appended struct file * entries to t_outdated->fd_fixups), so the FD array in buffer still contains zeros (or sender-supplied offsets). Because is_failure is false, binder_transaction_buffer_release() executes the !is_failure branch on BINDER_TYPE_FDA and calls binder_deferred_fd_close(fd) (closing fd 0 in current->files, which is the **sender** process!).
2. t_outdated is freed via kfree(t_outdated) without calling binder_free_txn_fixups(t_outdated), permanently leaking every translated struct file reference in t_outdated->fd_fixups.

Quoted 7 lines

Pass is_failure = true to binder_release_entire_buffer() and call binder_free_txn_fixups(t_outdated) before freeing t_outdated.

Fixes 9864bb480133 ("Binder: add TF_UPDATE_TXN to replace outdated txn")
Fixes bdc1c5fac982 ("binder: fix UAF caused by faulty buffer cleanup")
Assisted-by LLM

Hi,

This is the friendly patch-bot of Greg Kroah-Hartman. You have sent him a patch that has triggered this response. He used to manually respond to these common problems, but in order to save his sanity (he kept writing the same thing over and over, yet to different people), I was created. Hopefully you will not take offence and will fix the problem in your patch and resubmit it so that it can be accepted into the Linux kernel tree.

You are receiving this message because of the following common error(s) as indicated below:

- You sent multiple patches, yet no indication of which ones should be applied in which order. Greg could just guess, but if you are receiving this email, he guessed wrong and the patches didn't apply. Please read the section entitled "The canonical patch format" in the kernel file, Documentation/process/submitting-patches.rst for a description of how to do this so that Greg has a chance to apply these correctly.

- You have marked a patch with a "Fixes:" tag for a commit that is in an older released kernel, yet you do not have a cc: stable line in the signed-off-by area at all, which means that the patch will not be applied to any older kernel releases. To properly fix this, please follow the documented rules in the Documentation/process/stable-kernel-rules.rst file for how to resolve this.

If you wish to discuss this problem further, or you have questions about how to resolve this issue, please feel free to respond to this email and Greg will reply once he has dug out from the pending patches received from other developers.

thanks,

greg k-h's patch email bot

maintainer
#2 lore raw
In reply to Hui Peng
Quoted 21 lines · Hui Peng

In binder_proc_transaction(), when a oneway transaction with TF_UPDATE_TXN supersedes an outdated pending transaction (t_outdated), the driver calls binder_release_entire_buffer(proc, NULL, buffer, false) and kfree(t_outdated).

Passing is_failure = false while buffer->transaction has already been set to NULL causes two bugs when t_outdated contained BINDER_TYPE_FDA or BINDER_TYPE_FD objects:

1. For BINDER_TYPE_FDA, binder_translate_fd_array() never wrote recipient file descriptors into the buffer (it only appended struct file * entries to t_outdated->fd_fixups), so the FD array in buffer still contains zeros (or sender-supplied offsets). Because is_failure is false, binder_transaction_buffer_release() executes the !is_failure branch on BINDER_TYPE_FDA and calls binder_deferred_fd_close(fd) (closing fd 0 in current->files, which is the **sender** process!).
2. t_outdated is freed via kfree(t_outdated) without calling binder_free_txn_fixups(t_outdated), permanently leaking every translated struct file reference in t_outdated->fd_fixups.

Quoted 2 lines

Pass is_failure = true to binder_release_entire_buffer() and call binder_free_txn_fixups(t_outdated) before freeing t_outdated.

Please delete all LLM-generated changelog text and rewrite it in your own words to explain the problem and why this patch is needed (same for your other 6 patches). Also, how were these all tested?

thanks,

greg k-h

maintainer
#3 lore raw
In reply to Hui Peng
Quoted 21 lines · Hui Peng

In binder_proc_transaction(), when a oneway transaction with TF_UPDATE_TXN supersedes an outdated pending transaction (t_outdated), the driver calls binder_release_entire_buffer(proc, NULL, buffer, false) and kfree(t_outdated).

Passing is_failure = false while buffer->transaction has already been set to NULL causes two bugs when t_outdated contained BINDER_TYPE_FDA or BINDER_TYPE_FD objects:

1. For BINDER_TYPE_FDA, binder_translate_fd_array() never wrote recipient file descriptors into the buffer (it only appended struct file * entries to t_outdated->fd_fixups), so the FD array in buffer still contains zeros (or sender-supplied offsets). Because is_failure is false, binder_transaction_buffer_release() executes the !is_failure branch on BINDER_TYPE_FDA and calls binder_deferred_fd_close(fd) (closing fd 0 in current->files, which is the **sender** process!).
2. t_outdated is freed via kfree(t_outdated) without calling binder_free_txn_fixups(t_outdated), permanently leaking every translated struct file reference in t_outdated->fd_fixups.

Quoted 7 lines

Pass is_failure = true to binder_release_entire_buffer() and call binder_free_txn_fixups(t_outdated) before freeing t_outdated.

Fixes 9864bb480133 ("Binder: add TF_UPDATE_TXN to replace outdated txn")
Fixes bdc1c5fac982 ("binder: fix UAF caused by faulty buffer cleanup")
Assisted-by LLM

It looks like this has also already been resolved by:
https://lore.kernel.org/all/[email protected]/