public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: "Paul E. McKenney" <paulmck@linux.vnet.ibm.com>
To: "Eric W. Biederman" <ebiederm@xmission.com>
Cc: Sasha Levin <sasha.levin@oracle.com>,
	Eric Dumazet <eric.dumazet@gmail.com>,
	Li Zefan <lizefan@huawei.com>, CAI Qian <caiqian@redhat.com>,
	linux-kernel <linux-kernel@vger.kernel.org>,
	Containers <containers@lists.linux-foundation.org>
Subject: Re: 3.9-rc1 NULL pointer crash at find_pid_ns
Date: Thu, 7 Mar 2013 10:15:49 -0800	[thread overview]
Message-ID: <20130307181549.GW3268@linux.vnet.ibm.com> (raw)
In-Reply-To: <87boavrspd.fsf@xmission.com>

On Thu, Mar 07, 2013 at 10:05:34AM -0800, Eric W. Biederman wrote:
> Sasha Levin <sasha.levin@oracle.com> writes:
> 
> > On 03/07/2013 12:46 PM, Eric Dumazet wrote:
> >> On Thu, 2013-03-07 at 12:36 -0500, Sasha Levin wrote:
> >> 
> >>> Looks like the hlist change is probably the issue, though it specifically
> >>> uses:
> >>>
> >>> 	#define hlist_entry_safe(ptr, type, member) \
> >>>         	(ptr) ? hlist_entry(ptr, type, member) : NULL
> >>>
> >>> I'm still looking at the code in question and it's assembly, but I can't
> >>> figure out what's going wrong. I was also trying to see what's so special
> >>> about this loop in find_pid_ns as opposed to the rest of the kernel code
> >>> that uses hlist_for_each_entry_rcu() but couldn't find out why.
> >>>
> >>> Is it somehow possible that if we rcu_dereference_raw() the same thing twice
> >>> inside the same rcu_read_lock() section we'll get different results? That's
> >>> really the only reason for this crash that comes to mind at the moment, very
> >>> unlikely - but that's all I have right now.
> >>>
> >> 
> >> Yep
> >> 
> >> #define hlist_entry_safe(ptr, type, member) \
> >> 	(ptr) ? hlist_entry(ptr, type, member) : NULL
> >> 
> >> Is not safe, as ptr can be evaluated twice, and thats not good at all...
> >
> > ptr is being evaluated twice, but in this case this is an
> > rcu_dereference_raw() value within the same rcu_read_lock() section.
> >
> > Is it still problematic?
> 
> Definitely.
> 
> Head in this instance the expression: &pid_hash[pid_hashfn(nr, ns)]
> 
> And the crash clearly shows that when hilst_entry is being evaluated the
> HEAD is NULL.
> 
> Perhaps this shows up in proc because the hash chains are short and
> frequently NULL?

So it should be possible to do something like the following:

#define hlist_entry_safe(ptr, type, member) \
	({ typeof(ptr) ____ptr = ACCESS_ONCE(ptr); \
	   ____ptr ? hlist_entry(____ptr, type, member) : NULL; \
	})

Does that help?

							Thanx, Paul


      parent reply	other threads:[~2013-03-07 18:17 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-03-07  9:37 3.9-rc1 NULL pointer crash at find_pid_ns CAI Qian
2013-03-07  9:42 ` Li Zefan
2013-03-07  9:59   ` Eric W. Biederman
2013-03-07 17:36     ` Sasha Levin
2013-03-07 17:46       ` Eric Dumazet
2013-03-07 17:50         ` Sasha Levin
2013-03-07 18:04           ` Paul E. McKenney
2013-03-07 18:05           ` Eric W. Biederman
2013-03-07 18:14             ` Sasha Levin
2013-03-07 18:18               ` Eric Dumazet
2013-03-07 18:21               ` Eric W. Biederman
2013-03-07 18:27                 ` Sasha Levin
2013-03-07 18:29               ` Paul E. McKenney
2013-03-09  8:01                 ` Li Zefan
2013-03-09 15:51                   ` Paul E. McKenney
2013-03-14 20:00                     ` Dave Jones
2013-03-14 21:00                       ` Paul E. McKenney
2013-03-07 18:15             ` Paul E. McKenney [this message]

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=20130307181549.GW3268@linux.vnet.ibm.com \
    --to=paulmck@linux.vnet.ibm.com \
    --cc=caiqian@redhat.com \
    --cc=containers@lists.linux-foundation.org \
    --cc=ebiederm@xmission.com \
    --cc=eric.dumazet@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lizefan@huawei.com \
    --cc=sasha.levin@oracle.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