Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

binder: use euid from cred instead of using task

Save the 'struct cred' associated with a binder process
at initial open to avoid potential race conditions
when converting to an euid.

Set a transaction's sender_euid from the 'struct cred'
saved at binder_open() instead of looking up the euid
from the binder proc's 'struct task'. This ensures
the euid is associated with the security context that
of the task that opened binder.

Cc: stable@vger.kernel.org # 4.4+
Fixes: 457b9a6f09f0 ("Staging: android: add binder driver")
Signed-off-by: Todd Kjos <tkjos@google.com>
Suggested-by: Stephen Smalley <stephen.smalley.work@gmail.com>
Suggested-by: Jann Horn <jannh@google.com>
Acked-by: Casey Schaufler <casey@schaufler-ca.com>
Signed-off-by: Paul Moore <paul@paul-moore.com>

authored by

Todd Kjos and committed by
Paul Moore
29bc22ac 86dd9fd5

+7 -1
+3 -1
drivers/android/binder.c
··· 2702 2702 t->from = thread; 2703 2703 else 2704 2704 t->from = NULL; 2705 - t->sender_euid = task_euid(proc->tsk); 2705 + t->sender_euid = proc->cred->euid; 2706 2706 t->to_proc = target_proc; 2707 2707 t->to_thread = target_thread; 2708 2708 t->code = tr->code; ··· 4343 4343 } 4344 4344 binder_alloc_deferred_release(&proc->alloc); 4345 4345 put_task_struct(proc->tsk); 4346 + put_cred(proc->cred); 4346 4347 binder_stats_deleted(BINDER_STAT_PROC); 4347 4348 kfree(proc); 4348 4349 } ··· 5022 5021 spin_lock_init(&proc->outer_lock); 5023 5022 get_task_struct(current->group_leader); 5024 5023 proc->tsk = current->group_leader; 5024 + proc->cred = get_cred(filp->f_cred); 5025 5025 INIT_LIST_HEAD(&proc->todo); 5026 5026 init_waitqueue_head(&proc->freeze_wait); 5027 5027 proc->default_priority = task_nice(current);
+4
drivers/android/binder_internal.h
··· 364 364 * (invariant after initialized) 365 365 * @tsk task_struct for group_leader of process 366 366 * (invariant after initialized) 367 + * @cred struct cred associated with the `struct file` 368 + * in binder_open() 369 + * (invariant after initialized) 367 370 * @deferred_work_node: element for binder_deferred_list 368 371 * (protected by binder_deferred_lock) 369 372 * @deferred_work: bitmap of deferred work to perform ··· 427 424 struct list_head waiting_threads; 428 425 int pid; 429 426 struct task_struct *tsk; 427 + const struct cred *cred; 430 428 struct hlist_node deferred_work_node; 431 429 int deferred_work; 432 430 int outstanding_txns;