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: <20151020165331.GU11639@twins.programming.kicks-ass.net>
Date:	Tue, 20 Oct 2015 18:53:31 +0200
From:	Peter Zijlstra <peterz@...radead.org>
To:	Steven Rostedt <rostedt@...dmis.org>
Cc:	"Paul E. McKenney" <paulmck@...ux.vnet.ibm.com>,
	LKML <linux-kernel@...r.kernel.org>,
	Rusty Russell <rusty@...tcorp.com.au>
Subject: Re: [PATCH] module: Prevent recursion bug caused by module RCU check

On Tue, Oct 20, 2015 at 06:39:52PM +0200, Peter Zijlstra wrote:
> On Tue, Oct 20, 2015 at 12:21:03PM -0400, Steven Rostedt wrote:
> > +++ b/kernel/module.c
> > @@ -284,11 +284,25 @@ static void module_assert_mutex(void)
> >  static void module_assert_mutex_or_preempt(void)
> >  {
> >  #ifdef CONFIG_LOCKDEP
> > +	static int once;
> > +
> >  	if (unlikely(!debug_locks))
> >  		return;
> >  
> > -	WARN_ON(!rcu_read_lock_sched_held() &&
> > -		!lockdep_is_held(&module_mutex));
> > +	/*
> > +	 * Would be nice to use WARN_ON_ONCE(), but the warning
> > +	 * that causes a stack trace may call __module_address()
> > +	 * which may call here, and we trigger the warning again,
> > +	 * before the WARN_ON_ONCE() updates its flag.
> > +	 * To prevent the recursion, we need to open code the
> > +	 * once logic.
> > +	 */
> > +	if (!once &&
> > +	    unlikely(!rcu_read_lock_sched_held() &&
> > +		     !lockdep_is_held(&module_mutex))) {
> > +		once++;
> 
> 		once = 1;
> 
> is more 'once' :-) Otherwise its once every 4-odd billion.
> 
> > +		WARN_ON(1);
> > +	}
> >  #endif

Also, would it not be better to fix WARN_ON_ONCE() instead?

---
 include/asm-generic/bug.h | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/include/asm-generic/bug.h b/include/asm-generic/bug.h
index 630dd2372238..c41e698613f3 100644
--- a/include/asm-generic/bug.h
+++ b/include/asm-generic/bug.h
@@ -110,9 +110,11 @@ extern void warn_slowpath_null(const char *file, const int line);
 	static bool __section(.data.unlikely) __warned;		\
 	int __ret_warn_once = !!(condition);			\
 								\
-	if (unlikely(__ret_warn_once))				\
-		if (WARN_ON(!__warned)) 			\
+	if (unlikely(__ret_warn_once)) {			\
+		if (!__warned)					\
 			__warned = true;			\
+		WARN_ON(1);					\
+	}							\
 	unlikely(__ret_warn_once);				\
 })
 
@@ -120,9 +122,11 @@ extern void warn_slowpath_null(const char *file, const int line);
 	static bool __section(.data.unlikely) __warned;		\
 	int __ret_warn_once = !!(condition);			\
 								\
-	if (unlikely(__ret_warn_once))				\
-		if (WARN(!__warned, format)) 			\
+	if (unlikely(__ret_warn_once)) {			\
+		if (!__warned)					\
 			__warned = true;			\
+		WARN(1, format);				\
+	}							\
 	unlikely(__ret_warn_once);				\
 })
 
--
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