public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Pavel Emelyanov <xemul@openvz.org>
To: Oleg Nesterov <oleg@tv-sign.ru>,
	Andrew Morton <akpm@linux-foundation.org>
Cc: "Eric W. Biederman" <ebiederm@xmission.com>,
	Pavel Emelyanov <xemul@openvz.org>,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] do_task_stat: don't use task_pid_nr_ns() lockless
Date: Mon, 19 Nov 2007 12:31:59 +0300	[thread overview]
Message-ID: <4741580F.7070301@openvz.org> (raw)
In-Reply-To: <20071117183109.GA2605@tv-sign.ru>

Oleg Nesterov wrote:
> Without rcu/tasklist/siglock lock task_pid_nr_ns() may read the freed memory,
> move the callsite under ->siglock.
> 
> Sadly, we can report pid == 0 if the task was detached.
>
> Signed-off-by: Oleg Nesterov <oleg@tv-sign.ru>

Acked-by: Pavel Emelyanov <xemul@openvz.org>

> --- 24/fs/proc/array.c~dtst	2007-11-09 12:57:30.000000000 +0300
> +++ 24/fs/proc/array.c	2007-11-17 21:26:55.000000000 +0300
> @@ -392,7 +392,7 @@ static int do_task_stat(struct task_stru
>  	sigset_t sigign, sigcatch;
>  	char state;
>  	int res;
> -	pid_t ppid = 0, pgid = -1, sid = -1;
> +	pid_t pid = 0, ppid = 0, pgid = -1, sid = -1;
>  	int num_threads = 0;
>  	struct mm_struct *mm;
>  	unsigned long long start_time;
> @@ -403,9 +403,6 @@ static int do_task_stat(struct task_stru
>  	unsigned long rsslim = 0;
>  	char tcomm[sizeof(task->comm)];
>  	unsigned long flags;
> -	struct pid_namespace *ns;
> -
> -	ns = current->nsproxy->pid_ns;
>  
>  	state = *get_task_state(task);
>  	vsize = eip = esp = 0;
> @@ -425,6 +422,7 @@ static int do_task_stat(struct task_stru
>  
>  	rcu_read_lock();
>  	if (lock_task_sighand(task, &flags)) {
> +		struct pid_namespace *ns = current->nsproxy->pid_ns;
>  		struct signal_struct *sig = task->signal;
>  
>  		if (sig->tty) {
> @@ -461,6 +459,7 @@ static int do_task_stat(struct task_stru
>  			gtime = cputime_add(gtime, sig->gtime);
>  		}
>  
> +		pid = task_pid_nr_ns(task, ns);
>  		sid = task_session_nr_ns(task, ns);
>  		pgid = task_pgrp_nr_ns(task, ns);
>  		ppid = task_ppid_nr_ns(task, ns);
> @@ -495,7 +494,7 @@ static int do_task_stat(struct task_stru
>  	res = sprintf(buffer, "%d (%s) %c %d %d %d %d %d %u %lu \
>  %lu %lu %lu %lu %lu %ld %ld %ld %ld %d 0 %llu %lu %ld %lu %lu %lu %lu %lu \
>  %lu %lu %lu %lu %lu %lu %lu %lu %d %d %u %u %llu %lu %ld\n",
> -		task_pid_nr_ns(task, ns),
> +		pid,
>  		tcomm,
>  		state,
>  		ppid,
> 
> 


  parent reply	other threads:[~2007-11-19  9:32 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-11-17 18:31 [PATCH] do_task_stat: don't use task_pid_nr_ns() lockless Oleg Nesterov
2007-11-17 20:11 ` Eric W. Biederman
2007-11-19  9:30   ` Pavel Emelyanov
2007-11-19 18:04     ` Eric W. Biederman
2007-11-19  9:31 ` Pavel Emelyanov [this message]
2007-11-19 21:59 ` [PATCH 0/4] proc: Cleanup status files Eric W. Biederman
2007-11-19 22:04   ` [PATCH 1/4] proc: Implement proc_single_file_operations Eric W. Biederman
2007-11-19 22:06     ` [PATCH 2/4] proc: Rewrite do_task_stat to correctly handle pid namespaces Eric W. Biederman
2007-11-19 22:10       ` [PATCH 3/4] proc: seqfile convert proc_pid_status to properly " Eric W. Biederman
2007-11-19 22:13         ` [PATCH] proc: seqfile convert proc_pid_statm Eric W. Biederman
2007-11-20 10:34   ` [PATCH 0/4] proc: Cleanup status files Pavel Emelyanov
2007-11-19 22:30 ` [PATCH] proc: Proper pidns handling for /proc/self Eric W. Biederman

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4741580F.7070301@openvz.org \
    --to=xemul@openvz.org \
    --cc=akpm@linux-foundation.org \
    --cc=ebiederm@xmission.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=oleg@tv-sign.ru \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox