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: Andrew Morton <akpm@osdl.org>,
	linux-kernel@vger.kernel.org, containers@lists.osdl.org
Subject: Re: [PATCH 5/7] pid: Implement pid_nr
Date: Thu, 17 Aug 2006 01:03:53 +0400	[thread overview]
Message-ID: <20060816210353.GA628@oleg> (raw)
In-Reply-To: <m1lkpo3b8z.fsf@ebiederm.dsl.xmission.com>

On 08/16, Eric W. Biederman wrote:
> Oleg Nesterov <oleg@tv-sign.ru> writes:
> 
> > On 08/15, Eric W. Biederman wrote:
> >>
> >> +static inline pid_t pid_nr(struct pid *pid)
> >> +{
> >> +	pid_t nr = 0;
> >> +	if (pid)
> >> +		nr = pid->nr;
> >> +	return nr;
> >> +}
> >
> > I think this is not safe, you need rcu locks here or the caller should
> > do some locking.
> >
> > Let's look at f_getown() (PATCH 7/7). What if original task which was
> > pointed by ->f_owner.pid has gone, another thread does fcntl(F_SETOWN),
> > and pid_nr() takes a preemtion after 'if (pid)'? In this case 'pid->nr'
> > may follow a freed memory.
> 
> This isn't an rcu reference.  I hold a hard reference count on
> the pid entry.  So this should be safe.

	-static void f_modown(struct file *filp, unsigned long pid,
	+static void f_modown(struct file *filp, struct pid *pid, enum pid_type type,
			      uid_t uid, uid_t euid, int force)
	 {
		write_lock_irq(&filp->f_owner.lock);
		if (force || !filp->f_owner.pid) {
	-               filp->f_owner.pid = pid;
	+               put_pid(filp->f_owner.pid);

This 'put_pid()' can actually free 'struct pid' if the task/group
has already gone away. Another thread doing f_getown() can access
a freed memory, no?

> What is an rcu reference is going from struct pid to the task
> it points to.

Yes, you are right... But I'd say it is going form task to pid :)

Oleg.


  reply	other threads:[~2006-08-16 16:40 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-08-15 18:21 Start using struct pid Eric W. Biederman
2006-08-15 18:23 ` [PATCH 1/7] pid: Implement access helpers for a tacks various process groups Eric W. Biederman
2006-08-15 18:40   ` Dave Hansen
2006-08-15 19:03     ` Eric W. Biederman
2006-08-16  8:04     ` [Containers] " Kirill Korotaev
2006-08-15 18:23 ` [PATCH 2/7] pid: Add do_each_pid_task Eric W. Biederman
2006-08-16  3:10   ` [Containers] " Serge E. Hallyn
2006-08-16  4:28     ` Andrew Morton
2006-08-16  6:15       ` Eric W. Biederman
2006-08-16  6:34     ` Eric W. Biederman
2006-08-16 11:57       ` Serge E. Hallyn
2006-08-16 19:17   ` Oleg Nesterov
2006-08-17 21:16   ` [PATCH -mm] simplify pid iterators Oleg Nesterov
2006-08-15 18:23 ` [PATCH 3/7] pid: Implement signal functions that take a struct pid * Eric W. Biederman
2006-08-15 18:23 ` [PATCH 4/7] pid: Export the symbols needed to use " Eric W. Biederman
2006-08-15 18:23 ` [PATCH 5/7] pid: Implement pid_nr Eric W. Biederman
2006-08-15 18:37   ` Dave Hansen
2006-08-15 19:00     ` Eric W. Biederman
2006-08-15 19:15       ` [Containers] " Dave Hansen
2006-08-16  6:29         ` Eric W. Biederman
2006-08-16 16:27     ` Jan Engelhardt
2006-08-16 17:48       ` Eric W. Biederman
2006-08-16 18:19   ` Oleg Nesterov
2006-08-16 16:18     ` Eric W. Biederman
2006-08-16 21:03       ` Oleg Nesterov [this message]
2006-08-16 17:18         ` Eric W. Biederman
2006-08-15 18:23 ` [PATCH 6/7] vt: Update spawnpid to be a struct pid_t Eric W. Biederman
2006-08-15 18:53   ` Alan Cox
2006-08-15 18:45     ` Eric W. Biederman
2006-08-16  8:04       ` [Containers] " Kirill Korotaev
2006-08-16 14:23         ` Eric W. Biederman
2006-08-15 19:38   ` Ray Lehtiniemi
2006-08-16 19:35   ` Oleg Nesterov
2006-08-16 15:43     ` Andrew Morton
2006-08-16 17:55       ` Eric W. Biederman
2006-08-15 18:23 ` [PATCH 7/7] file: Modify struct fown_struct to use a struct pid Eric W. Biederman
2006-08-16 18:45   ` Oleg Nesterov
2006-08-16 18:48     ` Oleg Nesterov

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=20060816210353.GA628@oleg \
    --to=oleg@tv-sign.ru \
    --cc=akpm@osdl.org \
    --cc=containers@lists.osdl.org \
    --cc=ebiederm@xmission.com \
    --cc=linux-kernel@vger.kernel.org \
    /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.