From: ebiederm@xmission.com (Eric W. Biederman)
To: Oleg Nesterov <oleg@tv-sign.ru>
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, 05 Sep 2006 05:36:55 -0600 [thread overview]
Message-ID: <m1r6yq35pk.fsf@ebiederm.dsl.xmission.com> (raw)
In-Reply-To: <20060905101050.GA128@oleg> (Oleg Nesterov's message of "Tue, 5 Sep 2006 14:10:50 +0400")
Oleg Nesterov <oleg@tv-sign.ru> writes:
> 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.
I see the problem, and your test will certainly alleviate the symptom.
You are making the test has this process ever been a thread group leader.
I guess alleviating the symptom is all that is necessary there.
Grumble. I hate that entire pid transfer case, too bad glibc cares.
If I could in the fix for this I would like to add a clean concept
that we are testing for wrapped in a helper function. Otherwise
even with a big fat comment this will be easy to break next time
someone refactors the code.
>> + 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.
It is at least not worse, so it is probably worth doing.
Eric
next prev parent reply other threads:[~2006-09-05 11:37 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
2006-09-05 11:36 ` Eric W. Biederman [this message]
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=m1r6yq35pk.fsf@ebiederm.dsl.xmission.com \
--to=ebiederm@xmission.com \
--cc=acahalan@gmail.com \
--cc=ak@suse.de \
--cc=akpm@osdl.org \
--cc=jdelvare@suse.de \
--cc=kamezawa.hiroyu@jp.fujitsu.com \
--cc=linux-kernel@vger.kernel.org \
--cc=oleg@tv-sign.ru \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®