All of lore.kernel.org
 help / color / mirror / Atom feed
From: Oleg Nesterov <oleg@tv-sign.ru>
To: "Eric W. Biederman" <ebiederm@xmission.com>
Cc: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>,
	linux-kernel@vger.kernel.org, akpm@osdl.org, ak@suse.de,
	jdelvare@suse.de, Albert Cahalan <acahalan@gmail.com>,
	Paul Jackson <pj@sgi.com>
Subject: Re: [PATCH] proc: readdir race fix
Date: Tue, 5 Sep 2006 14:10:50 +0400	[thread overview]
Message-ID: <20060905101050.GA128@oleg> (raw)
In-Reply-To: <m14pvn3tam.fsf_-_@ebiederm.dsl.xmission.com>

On 09/04, Eric W. Biederman wrote:
> 
> -static struct task_struct *next_tgid(struct task_struct *start)
> -{
> -	struct task_struct *pos;
> +	task = NULL;
>  	rcu_read_lock();
> -	pos = start;
> -	if (pid_alive(start))
> -		pos = next_task(start);
> -	if (pid_alive(pos) && (pos != &init_task)) {
> -		get_task_struct(pos);
> -		goto done;
> +retry:
> +	pid = find_next_pid(tgid);
> +	if (pid) {
> +		tgid = pid->nr + 1;
> +		task = pid_task(pid, PIDTYPE_PID);
> +		if (!task || !thread_group_leader(task))
                              ^^^^^^^^^^^^^^^^^^^
There is a window while de_thread() switches leadership, so next_tgid()
may skip a task doing exec. What do you think about

                             // needs a comment
		if (!task || task->pid != task->tgid)
			goto retry;

instead? Currently first_tgid() has the same (very minor) problem.

> +			goto retry;
> +		get_task_struct(task);
>  	}
> -	pos = NULL;
> -done:
>  	rcu_read_unlock();
> -	put_task_struct(start);
> -	return pos;
> +	return task;
> +
>  }

Emply line before '}'

> +struct pid *find_next_pid(int nr)
> +{
> +	struct pid *next;
> +
> +	next = find_pid(nr);
> +	while (!next) {
> +		nr = next_pidmap(nr);
> +		if (nr <= 0)
> +			break;
> +		next = find_pid(nr);
> +	}
> +	return next;
> +}

This is strange that we are doing find_pid() before and at the end of loop,
I'd suggest this code:

	struct pid *find_next_pid(int nr)
	{
		struct pid *pid;

		do {
			pid = find_pid(nr);
			if (pid != NULL)
				break;
			nr = next_pidmap(nr);
		} while (nr > 0);

		return pid;
	}

Imho, a bit easier to read.

Oleg.


  parent reply	other threads:[~2006-09-05 10:10 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-08-25  9:29 [RFC][PATCH] ps command race fix take 4 [4/4] proc root open/release/llseek KAMEZAWA Hiroyuki
2006-09-04 23:13 ` [PATCH] proc: readdir race fix Eric W. Biederman
2006-09-05  1:30   ` KAMEZAWA Hiroyuki
2006-09-05  2:30     ` Eric W. Biederman
2006-09-05  2:41     ` KAMEZAWA Hiroyuki
2006-09-05  2:26   ` KAMEZAWA Hiroyuki
2006-09-05  2:54     ` Eric W. Biederman
2006-09-05  3:07     ` Eric W. Biederman
2006-09-05  5:39       ` KAMEZAWA Hiroyuki
2006-09-05 10:10       ` Oleg Nesterov [this message]
2006-09-05 11:36         ` Eric W. Biederman
2006-09-05 14:52         ` [PATCH] proc: readdir race fix (take 3) Eric W. Biederman
2006-09-06  9:01           ` Jean Delvare
2006-09-06 21:12             ` Jean Delvare
2006-09-06 22:25               ` Oleg Nesterov
2006-09-06 22:38                 ` [PATCH] proc-readdir-race-fix-take-3-fix-3 Oleg Nesterov
2006-09-06 22:59                   ` Eric W. Biederman
2006-09-08  6:38                   ` Eric W. Biederman
2006-09-06 22:43               ` [PATCH] proc: readdir race fix (take 3) Eric W. Biederman
2006-09-07  8:31                 ` Jean Delvare
2006-09-07 13:57                   ` Eric W. Biederman
2006-09-07 18:07                     ` Jean Delvare
2006-09-07 18:40                       ` Eric W. Biederman
2006-09-05  5:26   ` [PATCH] proc: readdir race fix KAMEZAWA Hiroyuki
2006-09-05  5:41     ` KAMEZAWA Hiroyuki

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=20060905101050.GA128@oleg \
    --to=oleg@tv-sign.ru \
    --cc=acahalan@gmail.com \
    --cc=ak@suse.de \
    --cc=akpm@osdl.org \
    --cc=ebiederm@xmission.com \
    --cc=jdelvare@suse.de \
    --cc=kamezawa.hiroyu@jp.fujitsu.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pj@sgi.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.