Skip to content

Commit 29bc22a

Browse files
toddkjospcmoore
authored andcommitted
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: [email protected] # 4.4+ Fixes: 457b9a6 ("Staging: android: add binder driver") Signed-off-by: Todd Kjos <[email protected]> Suggested-by: Stephen Smalley <[email protected]> Suggested-by: Jann Horn <[email protected]> Acked-by: Casey Schaufler <[email protected]> Signed-off-by: Paul Moore <[email protected]>
1 parent 86dd9fd commit 29bc22a

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

drivers/android/binder.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2702,7 +2702,7 @@ static void binder_transaction(struct binder_proc *proc,
27022702
t->from = thread;
27032703
else
27042704
t->from = NULL;
2705-
t->sender_euid = task_euid(proc->tsk);
2705+
t->sender_euid = proc->cred->euid;
27062706
t->to_proc = target_proc;
27072707
t->to_thread = target_thread;
27082708
t->code = tr->code;
@@ -4343,6 +4343,7 @@ static void binder_free_proc(struct binder_proc *proc)
43434343
}
43444344
binder_alloc_deferred_release(&proc->alloc);
43454345
put_task_struct(proc->tsk);
4346+
put_cred(proc->cred);
43464347
binder_stats_deleted(BINDER_STAT_PROC);
43474348
kfree(proc);
43484349
}
@@ -5021,6 +5022,7 @@ static int binder_open(struct inode *nodp, struct file *filp)
50215022
spin_lock_init(&proc->outer_lock);
50225023
get_task_struct(current->group_leader);
50235024
proc->tsk = current->group_leader;
5025+
proc->cred = get_cred(filp->f_cred);
50245026
INIT_LIST_HEAD(&proc->todo);
50255027
init_waitqueue_head(&proc->freeze_wait);
50265028
proc->default_priority = task_nice(current);

drivers/android/binder_internal.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,9 @@ struct binder_ref {
364364
* (invariant after initialized)
365365
* @tsk task_struct for group_leader of process
366366
* (invariant after initialized)
367+
* @cred struct cred associated with the `struct file`
368+
* in binder_open()
369+
* (invariant after initialized)
367370
* @deferred_work_node: element for binder_deferred_list
368371
* (protected by binder_deferred_lock)
369372
* @deferred_work: bitmap of deferred work to perform
@@ -424,6 +427,7 @@ struct binder_proc {
424427
struct list_head waiting_threads;
425428
int pid;
426429
struct task_struct *tsk;
430+
const struct cred *cred;
427431
struct hlist_node deferred_work_node;
428432
int deferred_work;
429433
int outstanding_txns;

0 commit comments

Comments
 (0)