* [PATCH 1/3] wait_task_stopped: don't use task_pid_nr_ns() lockless
@ 2007-11-16 17:24 Oleg Nesterov
2007-11-16 19:54 ` Roland McGrath
2007-11-19 9:28 ` Pavel Emelyanov
0 siblings, 2 replies; 3+ messages in thread
From: Oleg Nesterov @ 2007-11-16 17:24 UTC (permalink / raw)
To: Andrew Morton
Cc: Alexey Dobriyan, Kees Cook, Linus Torvalds, Pavel Emelyanov,
Roland McGrath, Scott James Remnant, linux-kernel
wait_task_stopped(WNOWAIT) does task_pid_nr_ns() without tasklist/rcu lock,
we can read an already freed memory. Use the cached pid_t value.
Signed-off-by: Oleg Nesterov <oleg@tv-sign.ru>
--- 24/kernel/exit.c~1_PID 2007-11-16 18:12:44.000000000 +0300
+++ 24/kernel/exit.c 2007-11-16 18:13:54.000000000 +0300
@@ -1357,7 +1357,7 @@ static int wait_task_stopped(struct task
int __user *stat_addr, struct rusage __user *ru)
{
int retval, exit_code;
- struct pid_namespace *ns;
+ pid_t pid;
if (!p->exit_code)
return 0;
@@ -1376,12 +1376,11 @@ static int wait_task_stopped(struct task
* keep holding onto the tasklist_lock while we call getrusage and
* possibly take page faults for user memory.
*/
- ns = current->nsproxy->pid_ns;
+ pid = task_pid_nr_ns(p, current->nsproxy->pid_ns);
get_task_struct(p);
read_unlock(&tasklist_lock);
if (unlikely(noreap)) {
- pid_t pid = task_pid_nr_ns(p, ns);
uid_t uid = p->uid;
int why = (p->ptrace & PT_PTRACED) ? CLD_TRAPPED : CLD_STOPPED;
@@ -1451,11 +1450,11 @@ bail_ref:
if (!retval && infop)
retval = put_user(exit_code, &infop->si_status);
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)
retval = put_user(p->uid, &infop->si_uid);
if (!retval)
- retval = task_pid_nr_ns(p, ns);
+ retval = pid;
put_task_struct(p);
BUG_ON(!retval);
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH 1/3] wait_task_stopped: don't use task_pid_nr_ns() lockless
2007-11-16 17:24 [PATCH 1/3] wait_task_stopped: don't use task_pid_nr_ns() lockless Oleg Nesterov
@ 2007-11-16 19:54 ` Roland McGrath
2007-11-19 9:28 ` Pavel Emelyanov
1 sibling, 0 replies; 3+ messages in thread
From: Roland McGrath @ 2007-11-16 19:54 UTC (permalink / raw)
To: Oleg Nesterov
Cc: Andrew Morton, Alexey Dobriyan, Kees Cook, Linus Torvalds,
Pavel Emelyanov, Scott James Remnant, linux-kernel
Looks good to me.
Thanks,
Roland
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH 1/3] wait_task_stopped: don't use task_pid_nr_ns() lockless
2007-11-16 17:24 [PATCH 1/3] wait_task_stopped: don't use task_pid_nr_ns() lockless Oleg Nesterov
2007-11-16 19:54 ` Roland McGrath
@ 2007-11-19 9:28 ` Pavel Emelyanov
1 sibling, 0 replies; 3+ messages in thread
From: Pavel Emelyanov @ 2007-11-19 9:28 UTC (permalink / raw)
To: Oleg Nesterov, Andrew Morton
Cc: Alexey Dobriyan, Kees Cook, Linus Torvalds, Pavel Emelyanov,
Roland McGrath, Scott James Remnant, linux-kernel
Oleg Nesterov wrote:
> wait_task_stopped(WNOWAIT) does task_pid_nr_ns() without tasklist/rcu lock,
> we can read an already freed memory. Use the cached pid_t value.
Indeed. Thanks!
> Signed-off-by: Oleg Nesterov <oleg@tv-sign.ru>
Acked-by: Pavel Emelyanov <xemul@openvz.org>
> --- 24/kernel/exit.c~1_PID 2007-11-16 18:12:44.000000000 +0300
> +++ 24/kernel/exit.c 2007-11-16 18:13:54.000000000 +0300
> @@ -1357,7 +1357,7 @@ static int wait_task_stopped(struct task
> int __user *stat_addr, struct rusage __user *ru)
> {
> int retval, exit_code;
> - struct pid_namespace *ns;
> + pid_t pid;
>
> if (!p->exit_code)
> return 0;
> @@ -1376,12 +1376,11 @@ static int wait_task_stopped(struct task
> * keep holding onto the tasklist_lock while we call getrusage and
> * possibly take page faults for user memory.
> */
> - ns = current->nsproxy->pid_ns;
> + pid = task_pid_nr_ns(p, current->nsproxy->pid_ns);
> get_task_struct(p);
> read_unlock(&tasklist_lock);
>
> if (unlikely(noreap)) {
> - pid_t pid = task_pid_nr_ns(p, ns);
> uid_t uid = p->uid;
> int why = (p->ptrace & PT_PTRACED) ? CLD_TRAPPED : CLD_STOPPED;
>
> @@ -1451,11 +1450,11 @@ bail_ref:
> if (!retval && infop)
> retval = put_user(exit_code, &infop->si_status);
> 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)
> retval = put_user(p->uid, &infop->si_uid);
> if (!retval)
> - retval = task_pid_nr_ns(p, ns);
> + retval = pid;
> put_task_struct(p);
>
> BUG_ON(!retval);
>
>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2007-11-19 9:30 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-11-16 17:24 [PATCH 1/3] wait_task_stopped: don't use task_pid_nr_ns() lockless Oleg Nesterov
2007-11-16 19:54 ` Roland McGrath
2007-11-19 9:28 ` Pavel Emelyanov
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox