binder: fix sender fd 0 close and file refcount leak on TF_UPDATE_TXN
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.
--- drivers/android/binder.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/android/binder.c +2 -1
@@ -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
Greg KH
maintainerQuoted 21 lines · Hui Peng
In
binder_proc_transaction(), when a oneway transaction withTF_UPDATE_TXNsupersedes an outdated pending transaction (t_outdated), the driver callsbinder_release_entire_buffer(proc, NULL, buffer, false)andkfree(t_outdated).Passing
is_failure = falsewhilebuffer->transactionhas already been set toNULLcauses two bugs whent_outdatedcontainedBINDER_TYPE_FDAorBINDER_TYPE_FDobjects:1. For
BINDER_TYPE_FDA,binder_translate_fd_array()never wrote recipient file descriptors into the buffer (it only appendedstruct file *entries tot_outdated->fd_fixups), so the FD array inbufferstill contains zeros (or sender-supplied offsets). Becauseis_failureisfalse,binder_transaction_buffer_release()executes the!is_failurebranch onBINDER_TYPE_FDAand callsbinder_deferred_fd_close(fd)(closingfd 0incurrent->files, which is the **sender** process!).
2.t_outdatedis freed viakfree(t_outdated)without callingbinder_free_txn_fixups(t_outdated), permanently leaking every translatedstruct filereference int_outdated->fd_fixups.
Quoted 7 lines
Pass
is_failure = truetobinder_release_entire_buffer()and callbinder_free_txn_fixups(t_outdated)before freeingt_outdated.Fixes 9864bb480133 ("Binder: add TF_UPDATE_TXN to replace outdated txn")Fixes bdc1c5fac982 ("binder: fix UAF caused by faulty buffer cleanup")Assisted-by LLMSigned-off-by Hui Peng <[email protected]>
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
Greg KH
maintainerQuoted 21 lines · Hui Peng
In
binder_proc_transaction(), when a oneway transaction withTF_UPDATE_TXNsupersedes an outdated pending transaction (t_outdated), the driver callsbinder_release_entire_buffer(proc, NULL, buffer, false)andkfree(t_outdated).Passing
is_failure = falsewhilebuffer->transactionhas already been set toNULLcauses two bugs whent_outdatedcontainedBINDER_TYPE_FDAorBINDER_TYPE_FDobjects:1. For
BINDER_TYPE_FDA,binder_translate_fd_array()never wrote recipient file descriptors into the buffer (it only appendedstruct file *entries tot_outdated->fd_fixups), so the FD array inbufferstill contains zeros (or sender-supplied offsets). Becauseis_failureisfalse,binder_transaction_buffer_release()executes the!is_failurebranch onBINDER_TYPE_FDAand callsbinder_deferred_fd_close(fd)(closingfd 0incurrent->files, which is the **sender** process!).
2.t_outdatedis freed viakfree(t_outdated)without callingbinder_free_txn_fixups(t_outdated), permanently leaking every translatedstruct filereference int_outdated->fd_fixups.
Quoted 2 lines
Pass
is_failure = truetobinder_release_entire_buffer()and callbinder_free_txn_fixups(t_outdated)before freeingt_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
Carlos Llamas
maintainerQuoted 21 lines · Hui Peng
In
binder_proc_transaction(), when a oneway transaction withTF_UPDATE_TXNsupersedes an outdated pending transaction (t_outdated), the driver callsbinder_release_entire_buffer(proc, NULL, buffer, false)andkfree(t_outdated).Passing
is_failure = falsewhilebuffer->transactionhas already been set toNULLcauses two bugs whent_outdatedcontainedBINDER_TYPE_FDAorBINDER_TYPE_FDobjects:1. For
BINDER_TYPE_FDA,binder_translate_fd_array()never wrote recipient file descriptors into the buffer (it only appendedstruct file *entries tot_outdated->fd_fixups), so the FD array inbufferstill contains zeros (or sender-supplied offsets). Becauseis_failureisfalse,binder_transaction_buffer_release()executes the!is_failurebranch onBINDER_TYPE_FDAand callsbinder_deferred_fd_close(fd)(closingfd 0incurrent->files, which is the **sender** process!).
2.t_outdatedis freed viakfree(t_outdated)without callingbinder_free_txn_fixups(t_outdated), permanently leaking every translatedstruct filereference int_outdated->fd_fixups.
Quoted 7 lines
Pass
is_failure = truetobinder_release_entire_buffer()and callbinder_free_txn_fixups(t_outdated)before freeingt_outdated.Fixes 9864bb480133 ("Binder: add TF_UPDATE_TXN to replace outdated txn")Fixes bdc1c5fac982 ("binder: fix UAF caused by faulty buffer cleanup")Assisted-by LLMSigned-off-by Hui Peng <[email protected]>
It looks like this has also already been resolved by:
https://lore.kernel.org/all/[email protected]/