wait_task_continued/zombie: don't use task_pid_nr_ns() lockless
Surprise, the other two wait_task_*() functions also abuse the task_pid_nr_ns() function, and may cause read-after-free or report nr == 0 in wait_task_continued(). wait_task_zombie() doesn't have this problem, but it is still better to cache pid_t rather than call task_pid_nr_ns() three times on the saved pid_namespace. Signed-off-by: Oleg Nesterov <oleg@tv-sign.ru> Cc: Roland McGrath <roland@redhat.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
This commit is contained in:
parent
f2cc3eb133
commit
3a515e4a62
@ -1189,12 +1189,9 @@ static int wait_task_zombie(struct task_struct *p, int noreap,
|
|||||||
{
|
{
|
||||||
unsigned long state;
|
unsigned long state;
|
||||||
int retval, status, traced;
|
int retval, status, traced;
|
||||||
struct pid_namespace *ns;
|
pid_t pid = task_pid_nr_ns(p, current->nsproxy->pid_ns);
|
||||||
|
|
||||||
ns = current->nsproxy->pid_ns;
|
|
||||||
|
|
||||||
if (unlikely(noreap)) {
|
if (unlikely(noreap)) {
|
||||||
pid_t pid = task_pid_nr_ns(p, ns);
|
|
||||||
uid_t uid = p->uid;
|
uid_t uid = p->uid;
|
||||||
int exit_code = p->exit_code;
|
int exit_code = p->exit_code;
|
||||||
int why, status;
|
int why, status;
|
||||||
@ -1313,11 +1310,11 @@ static int wait_task_zombie(struct task_struct *p, int noreap,
|
|||||||
retval = put_user(status, &infop->si_status);
|
retval = put_user(status, &infop->si_status);
|
||||||
}
|
}
|
||||||
if (!retval && infop)
|
if (!retval && infop)
|
||||||
retval = put_user(task_pid_nr_ns(p, ns), &infop->si_pid);
|
retval = put_user(pid, &infop->si_pid);
|
||||||
if (!retval && infop)
|
if (!retval && infop)
|
||||||
retval = put_user(p->uid, &infop->si_uid);
|
retval = put_user(p->uid, &infop->si_uid);
|
||||||
if (!retval)
|
if (!retval)
|
||||||
retval = task_pid_nr_ns(p, ns);
|
retval = pid;
|
||||||
|
|
||||||
if (traced) {
|
if (traced) {
|
||||||
write_lock_irq(&tasklist_lock);
|
write_lock_irq(&tasklist_lock);
|
||||||
@ -1436,7 +1433,6 @@ static int wait_task_continued(struct task_struct *p, int noreap,
|
|||||||
int retval;
|
int retval;
|
||||||
pid_t pid;
|
pid_t pid;
|
||||||
uid_t uid;
|
uid_t uid;
|
||||||
struct pid_namespace *ns;
|
|
||||||
|
|
||||||
if (!(p->signal->flags & SIGNAL_STOP_CONTINUED))
|
if (!(p->signal->flags & SIGNAL_STOP_CONTINUED))
|
||||||
return 0;
|
return 0;
|
||||||
@ -1451,8 +1447,7 @@ static int wait_task_continued(struct task_struct *p, int noreap,
|
|||||||
p->signal->flags &= ~SIGNAL_STOP_CONTINUED;
|
p->signal->flags &= ~SIGNAL_STOP_CONTINUED;
|
||||||
spin_unlock_irq(&p->sighand->siglock);
|
spin_unlock_irq(&p->sighand->siglock);
|
||||||
|
|
||||||
ns = current->nsproxy->pid_ns;
|
pid = task_pid_nr_ns(p, current->nsproxy->pid_ns);
|
||||||
pid = task_pid_nr_ns(p, ns);
|
|
||||||
uid = p->uid;
|
uid = p->uid;
|
||||||
get_task_struct(p);
|
get_task_struct(p);
|
||||||
read_unlock(&tasklist_lock);
|
read_unlock(&tasklist_lock);
|
||||||
@ -1463,7 +1458,7 @@ static int wait_task_continued(struct task_struct *p, int noreap,
|
|||||||
if (!retval && stat_addr)
|
if (!retval && stat_addr)
|
||||||
retval = put_user(0xffff, stat_addr);
|
retval = put_user(0xffff, stat_addr);
|
||||||
if (!retval)
|
if (!retval)
|
||||||
retval = task_pid_nr_ns(p, ns);
|
retval = pid;
|
||||||
} else {
|
} else {
|
||||||
retval = wait_noreap_copyout(p, pid, uid,
|
retval = wait_noreap_copyout(p, pid, uid,
|
||||||
CLD_CONTINUED, SIGCONT,
|
CLD_CONTINUED, SIGCONT,
|
||||||
|
Loading…
Reference in New Issue
Block a user