Skip to content

Commit 51d8a7e

Browse files
Christian Braunergregkh
authored andcommitted
binder: prevent UAF read in print_binder_transaction_log_entry()
When a binder transaction is initiated on a binder device coming from a binderfs instance, a pointer to the name of the binder device is stashed in the binder_transaction_log_entry's context_name member. Later on it is used to print the name in print_binder_transaction_log_entry(). By the time print_binder_transaction_log_entry() accesses context_name binderfs_evict_inode() might have already freed the associated memory thereby causing a UAF. Do the simple thing and prevent this by copying the name of the binder device instead of stashing a pointer to it. Reported-by: Jann Horn <[email protected]> Fixes: 03e2e07 ("binder: Make transaction_log available in binderfs") Link: https://lore.kernel.org/r/CAG48ez14Q0-F8LqsvcNbyR2o6gPW8SHXsm4u5jmD9MpsteM2Tw@mail.gmail.com Signed-off-by: Christian Brauner <[email protected]> Reviewed-by: Joel Fernandes (Google) <[email protected]> Acked-by: Todd Kjos <[email protected]> Reviewed-by: Hridya Valsaraju <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent fc739a0 commit 51d8a7e

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

drivers/android/binder.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
#include <linux/sched/signal.h>
5858
#include <linux/sched/mm.h>
5959
#include <linux/seq_file.h>
60+
#include <linux/string.h>
6061
#include <linux/uaccess.h>
6162
#include <linux/pid_namespace.h>
6263
#include <linux/security.h>
@@ -66,6 +67,7 @@
6667
#include <linux/task_work.h>
6768

6869
#include <uapi/linux/android/binder.h>
70+
#include <uapi/linux/android/binderfs.h>
6971

7072
#include <asm/cacheflush.h>
7173

@@ -2876,7 +2878,7 @@ static void binder_transaction(struct binder_proc *proc,
28762878
e->target_handle = tr->target.handle;
28772879
e->data_size = tr->data_size;
28782880
e->offsets_size = tr->offsets_size;
2879-
e->context_name = proc->context->name;
2881+
strscpy(e->context_name, proc->context->name, BINDERFS_MAX_NAME);
28802882

28812883
if (reply) {
28822884
binder_inner_proc_lock(proc);

drivers/android/binder_internal.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ struct binder_transaction_log_entry {
130130
int return_error_line;
131131
uint32_t return_error;
132132
uint32_t return_error_param;
133-
const char *context_name;
133+
char context_name[BINDERFS_MAX_NAME + 1];
134134
};
135135

136136
struct binder_transaction_log {

0 commit comments

Comments
 (0)