lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20130307181549.GW3268@linux.vnet.ibm.com>
Date:	Thu, 7 Mar 2013 10:15:49 -0800
From:	"Paul E. McKenney" <paulmck@...ux.vnet.ibm.com>
To:	"Eric W. Biederman" <ebiederm@...ssion.com>
Cc:	Sasha Levin <sasha.levin@...cle.com>,
	Eric Dumazet <eric.dumazet@...il.com>,
	Li Zefan <lizefan@...wei.com>, CAI Qian <caiqian@...hat.com>,
	linux-kernel <linux-kernel@...r.kernel.org>,
	Containers <containers@...ts.linux-foundation.org>
Subject: Re: 3.9-rc1 NULL pointer crash at find_pid_ns

On Thu, Mar 07, 2013 at 10:05:34AM -0800, Eric W. Biederman wrote:
> Sasha Levin <sasha.levin@...cle.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

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ