public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: ebiederm@xmission.com (Eric W. Biederman)
To: Oleg Nesterov <oleg@tv-sign.ru>
Cc: Andrew Morton <akpm@osdl.org>, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] introduce get_task_pid() to fix unsafe get_pid()
Date: Sun, 10 Sep 2006 21:58:25 -0600	[thread overview]
Message-ID: <m1venvawbi.fsf@ebiederm.dsl.xmission.com> (raw)
In-Reply-To: <20060911022535.GA7095@oleg> (Oleg Nesterov's message of "Mon, 11 Sep 2006 06:25:35 +0400")

Oleg Nesterov <oleg@tv-sign.ru> writes:

> (COMPILE TESTED, needs an ack from Eric)
>
> proc_pid_make_inode:
>
> 	ei->pid = get_pid(task_pid(task));
>
> I think this is not safe. get_pid() can be preempted after checking
> "pid != NULL". Then the task exits, does detach_pid(), and RCU frees
> the pid.

Ugh.  I had forgotten that the pid of a task gets freed even if you
hold a reference to the task struct.  So the preemption case looks possible.

Your technique to handle this problem looks fine.

As for the functions can we build them in all 4 varieties.
struct pid *get_task_pid(struct task *);
struct pid *get_task_tgid(struct task *);
struct pid *get_task_pgrp(struct task *);
struct pid *get_task_session(struct task *);

Functions without a flag are less error prone to use, and clearer to read.

Either that or we can just drop in some rcu_read_lock() rcu_read_unlock()
into the call sites.

Eric

  reply	other threads:[~2006-09-11  3:59 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-09-11  2:25 [PATCH] introduce get_task_pid() to fix unsafe get_pid() Oleg Nesterov
2006-09-11  3:58 ` Eric W. Biederman [this message]
2006-09-11  4:37   ` Oleg Nesterov
2006-09-11  4:59     ` 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=m1venvawbi.fsf@ebiederm.dsl.xmission.com \
    --to=ebiederm@xmission.com \
    --cc=akpm@osdl.org \
    --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