All of lore.kernel.org
 help / color / mirror / Atom feed
From: Kirill Korotaev <dev@sw.ru>
To: Oleg Nesterov <oleg@tv-sign.ru>
Cc: Andrew Morton <akpm@osdl.org>, Dave Hansen <haveblue@us.ibm.com>,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] sys_getppid oopses on debug kernel (v2)
Date: Wed, 09 Aug 2006 16:08:27 +0400	[thread overview]
Message-ID: <44D9D03B.6060907@sw.ru> (raw)
In-Reply-To: <20060809143816.GA142@oleg>

>>Although I'm not sure it's needed for this problem. A getppid() which does
>>
>>asmlinkage long sys_getppid(void)
>>{
>>	int pid;
>>
>>	read_lock(&tasklist_lock);
>>	pid = current->group_leader->real_parent->tgid;
>>	read_unlock(&tasklist_lock);
>>
>>	return pid;
>>}
>>
>>seems like a fine implementation to me ;)
> 
> 
> Why do we need to use ->group_leader? All threads should have the same
> ->real_parent.
I'm not sure this is true for old LinuxThreads...

> Why do we need tasklist_lock? I think rcu_read_lock() is enough.
> 
> In other words, do you see any problems with this code
> 
> 	smlinkage long sys_getppid(void)
> 	{
> 		int pid;
> 
> 		rcu_read_lock();
> 		pid = rcu_dereference(current->real_parent)->tgid;
> 		rcu_read_unlock();
> 
> 		return pid;
> 	}
> 
> ? Yes, we may read a stale value for ->real_parent, but the memory
> can't be freed while we are under rcu_read_lock(). And in this case
> the returned value is ok because the task could be reparented just
> after return anyway.
Your patch doesn't cure the problem.
rcu_read_lock just disables preemtion and rcu_dereference
introduces memory barrier. _None_ of this _prevents_
another CPU from freeing old real_parent in parallel with your dereference.

You can minimize the probability very much by making local_irq_disable()/enable()
around the code in question, but still it won't be a real fix (at least due to NMIs).

Kirill


  reply	other threads:[~2006-08-09 12:06 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-08-09 14:38 [PATCH] sys_getppid oopses on debug kernel (v2) Oleg Nesterov
2006-08-09 12:08 ` Kirill Korotaev [this message]
2006-08-09 16:54   ` Oleg Nesterov
2006-08-09 13:02     ` Kirill Korotaev
2006-08-09 18:24       ` [PATCH] sys_getppid-oopses-on-debug-kernel-v2-simplify Oleg Nesterov
  -- strict thread matches above, loose matches on Subject: below --
2006-08-08 15:50 [PATCH] sys_getppid oopses on debug kernel (v2) Kirill Korotaev
2006-08-08 16:09 ` Dave Hansen

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=44D9D03B.6060907@sw.ru \
    --to=dev@sw.ru \
    --cc=akpm@osdl.org \
    --cc=haveblue@us.ibm.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 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.