CRED: Use RCU to access another task's creds and to release a task's own creds
Use RCU to access another task's creds and to release a task's own creds. This means that it will be possible for the credentials of a task to be replaced without another task (a) requiring a full lock to read them, and (b) seeing deallocated memory. Signed-off-by: David Howells <dhowells@redhat.com> Acked-by: James Morris <jmorris@namei.org> Acked-by: Serge Hallyn <serue@us.ibm.com> Signed-off-by: James Morris <jmorris@namei.org>
This commit is contained in:
committed by
James Morris
parent
86a264abe5
commit
c69e8d9c01
@ -160,7 +160,10 @@ void release_task(struct task_struct * p)
|
||||
int zap_leader;
|
||||
repeat:
|
||||
tracehook_prepare_release_task(p);
|
||||
atomic_dec(&p->cred->user->processes);
|
||||
/* don't need to get the RCU readlock here - the process is dead and
|
||||
* can't be modifying its own credentials */
|
||||
atomic_dec(&__task_cred(p)->user->processes);
|
||||
|
||||
proc_flush_task(p);
|
||||
write_lock_irq(&tasklist_lock);
|
||||
tracehook_finish_release_task(p);
|
||||
@ -1267,12 +1270,12 @@ static int wait_task_zombie(struct task_struct *p, int options,
|
||||
unsigned long state;
|
||||
int retval, status, traced;
|
||||
pid_t pid = task_pid_vnr(p);
|
||||
uid_t uid = __task_cred(p)->uid;
|
||||
|
||||
if (!likely(options & WEXITED))
|
||||
return 0;
|
||||
|
||||
if (unlikely(options & WNOWAIT)) {
|
||||
uid_t uid = p->cred->uid;
|
||||
int exit_code = p->exit_code;
|
||||
int why, status;
|
||||
|
||||
@ -1393,7 +1396,7 @@ static int wait_task_zombie(struct task_struct *p, int options,
|
||||
if (!retval && infop)
|
||||
retval = put_user(pid, &infop->si_pid);
|
||||
if (!retval && infop)
|
||||
retval = put_user(p->cred->uid, &infop->si_uid);
|
||||
retval = put_user(uid, &infop->si_uid);
|
||||
if (!retval)
|
||||
retval = pid;
|
||||
|
||||
@ -1458,7 +1461,8 @@ static int wait_task_stopped(int ptrace, struct task_struct *p,
|
||||
if (!unlikely(options & WNOWAIT))
|
||||
p->exit_code = 0;
|
||||
|
||||
uid = p->cred->uid;
|
||||
/* don't need the RCU readlock here as we're holding a spinlock */
|
||||
uid = __task_cred(p)->uid;
|
||||
unlock_sig:
|
||||
spin_unlock_irq(&p->sighand->siglock);
|
||||
if (!exit_code)
|
||||
@ -1532,10 +1536,10 @@ static int wait_task_continued(struct task_struct *p, int options,
|
||||
}
|
||||
if (!unlikely(options & WNOWAIT))
|
||||
p->signal->flags &= ~SIGNAL_STOP_CONTINUED;
|
||||
uid = __task_cred(p)->uid;
|
||||
spin_unlock_irq(&p->sighand->siglock);
|
||||
|
||||
pid = task_pid_vnr(p);
|
||||
uid = p->cred->uid;
|
||||
get_task_struct(p);
|
||||
read_unlock(&tasklist_lock);
|
||||
|
||||
|
Reference in New Issue
Block a user