Skip to content

Commit

Permalink
BACKPORT: binder: prevent UAF read in print_binder_transaction_log_en…
Browse files Browse the repository at this point in the history
…try()

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.

Bug: 254441685
Reported-by: Jann Horn <jannh@google.com>
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 <christian.brauner@ubuntu.com>
Reviewed-by: Joel Fernandes (Google) <joel@joelfernandes.org>
Acked-by: Todd Kjos <tkjos@google.com>
Reviewed-by: Hridya Valsaraju <hridya@google.com>
Link: https://lore.kernel.org/r/20191008130159.10161-1-christian.brauner@ubuntu.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
(cherry picked from commit 51d8a7e)
Signed-off-by: Lee Jones <joneslee@google.com>
Change-Id: I23cf2cb9df9506950d0785eb479ccbdfcf6f4e41
  • Loading branch information
Christian Brauner authored and lag-google committed Feb 1, 2023
1 parent 9d8945c commit 544b157
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
4 changes: 3 additions & 1 deletion drivers/android/binder.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,15 @@
#include <linux/sched/signal.h>
#include <linux/sched/mm.h>
#include <linux/seq_file.h>
#include <linux/string.h>
#include <linux/uaccess.h>
#include <linux/pid_namespace.h>
#include <linux/security.h>
#include <linux/spinlock.h>
#include <linux/ratelimit.h>

#include <uapi/linux/android/binder.h>
#include <uapi/linux/android/binderfs.h>
#include <uapi/linux/sched/types.h>

#include <asm/cacheflush.h>
Expand Down Expand Up @@ -2969,7 +2971,7 @@ static void binder_transaction(struct binder_proc *proc,
e->target_handle = tr->target.handle;
e->data_size = tr->data_size;
e->offsets_size = tr->offsets_size;
e->context_name = proc->context->name;
strscpy(e->context_name, proc->context->name, BINDERFS_MAX_NAME);

if (reply) {
binder_inner_proc_lock(proc);
Expand Down
2 changes: 1 addition & 1 deletion drivers/android/binder_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ struct binder_transaction_log_entry {
int return_error_line;
uint32_t return_error;
uint32_t return_error_param;
const char *context_name;
char context_name[BINDERFS_MAX_NAME + 1];
};

struct binder_transaction_log {
Expand Down

0 comments on commit 544b157

Please sign in to comment.