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-next>] [day] [month] [year] [list]
Message-Id: <20190128182636.18420-1-mathieu.desnoyers@efficios.com>
Date:   Mon, 28 Jan 2019 13:26:36 -0500
From:   Mathieu Desnoyers <mathieu.desnoyers@...icios.com>
To:     Ingo Molnar <mingo@...nel.org>,
        Peter Zijlstra <peterz@...radead.org>
Cc:     linux-kernel@...r.kernel.org, linux-api@...r.kernel.org,
        Mathieu Desnoyers <mathieu.desnoyers@...icios.com>,
        Jann Horn <jannh@...gle.com>,
        Thomas Gleixner <tglx@...utronix.de>,
        Andrea Parri <parri.andrea@...il.com>,
        Andrew Hunter <ahh@...gle.com>,
        Andy Lutomirski <luto@...nel.org>,
        Avi Kivity <avi@...lladb.com>,
        Benjamin Herrenschmidt <benh@...nel.crashing.org>,
        Boqun Feng <boqun.feng@...il.com>,
        Dave Watson <davejwatson@...com>, David Sehr <sehr@...gle.com>,
        Greg Hackmann <ghackmann@...gle.com>,
        "H . Peter Anvin" <hpa@...or.com>,
        Linus Torvalds <torvalds@...ux-foundation.org>,
        Maged Michael <maged.michael@...il.com>,
        Michael Ellerman <mpe@...erman.id.au>,
        "Paul E . McKenney" <paulmck@...ux.vnet.ibm.com>,
        Paul Mackerras <paulus@...ba.org>,
        Russell King <linux@...linux.org.uk>,
        Will Deacon <will.deacon@....com>, stable@...r.kernel.org
Subject: [RFC PATCH] Fix: membarrier: racy access to p->mm in membarrier_global_expedited()

Jann Horn identified a racy access to p->mm in the global expedited
command of the membarrier system call.

The suggested fix is to hold the task_lock() around the accesses to
p->mm and to the mm_struct membarrier_state field to guarantee the
existence of the mm_struct.

Link: https://lore.kernel.org/lkml/CAG48ez2G8ctF8dHS42TF37pThfr3y0RNOOYTmxvACm4u8Yu3cw@mail.gmail.com
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@...icios.com>
CC: Jann Horn <jannh@...gle.com>
CC: Thomas Gleixner <tglx@...utronix.de>
CC: Peter Zijlstra (Intel) <peterz@...radead.org>
CC: Ingo Molnar <mingo@...nel.org>
CC: Andrea Parri <parri.andrea@...il.com>
CC: Andrew Hunter <ahh@...gle.com>
CC: Andy Lutomirski <luto@...nel.org>
CC: Avi Kivity <avi@...lladb.com>
CC: Benjamin Herrenschmidt <benh@...nel.crashing.org>
CC: Boqun Feng <boqun.feng@...il.com>
CC: Dave Watson <davejwatson@...com>
CC: David Sehr <sehr@...gle.com>
CC: Greg Hackmann <ghackmann@...gle.com>
CC: H. Peter Anvin <hpa@...or.com>
CC: Linus Torvalds <torvalds@...ux-foundation.org>
CC: Maged Michael <maged.michael@...il.com>
CC: Michael Ellerman <mpe@...erman.id.au>
CC: Paul E. McKenney <paulmck@...ux.vnet.ibm.com>
CC: Paul Mackerras <paulus@...ba.org>
CC: Russell King <linux@...linux.org.uk>
CC: Will Deacon <will.deacon@....com>
CC: stable@...r.kernel.org # v4.16+
CC: linux-api@...r.kernel.org
---
 kernel/sched/membarrier.c | 27 +++++++++++++++++++++------
 1 file changed, 21 insertions(+), 6 deletions(-)

diff --git a/kernel/sched/membarrier.c b/kernel/sched/membarrier.c
index 76e0eaf4654e..305fdcc4c5f7 100644
--- a/kernel/sched/membarrier.c
+++ b/kernel/sched/membarrier.c
@@ -81,12 +81,27 @@ static int membarrier_global_expedited(void)
 
 		rcu_read_lock();
 		p = task_rcu_dereference(&cpu_rq(cpu)->curr);
-		if (p && p->mm && (atomic_read(&p->mm->membarrier_state) &
-				   MEMBARRIER_STATE_GLOBAL_EXPEDITED)) {
-			if (!fallback)
-				__cpumask_set_cpu(cpu, tmpmask);
-			else
-				smp_call_function_single(cpu, ipi_mb, NULL, 1);
+		/*
+		 * Skip this CPU if the runqueue's current task is NULL or if
+		 * it is a kernel thread.
+		 */
+		if (p && READ_ONCE(p->mm)) {
+			bool mm_match;
+
+			/*
+			 * Read p->mm and access membarrier_state while holding
+			 * the task lock to ensure existence of mm.
+			 */
+			task_lock(p);
+			mm_match = p->mm && (atomic_read(&p->mm->membarrier_state) &
+					     MEMBARRIER_STATE_GLOBAL_EXPEDITED);
+			task_unlock(p);
+			if (mm_match) {
+				if (!fallback)
+					__cpumask_set_cpu(cpu, tmpmask);
+				else
+					smp_call_function_single(cpu, ipi_mb, NULL, 1);
+			}
 		}
 		rcu_read_unlock();
 	}
-- 
2.17.1

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ