From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753692AbbBRRMJ (ORCPT ); Wed, 18 Feb 2015 12:12:09 -0500 Received: from terminus.zytor.com ([198.137.202.10]:39225 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753648AbbBRRMB (ORCPT ); Wed, 18 Feb 2015 12:12:01 -0500 Date: Wed, 18 Feb 2015 09:11:20 -0800 From: tip-bot for Oleg Nesterov Message-ID: Cc: oleg@redhat.com, hpa@zytor.com, mguzik@redhat.com, linux-kernel@vger.kernel.org, mingo@kernel.org, peterz@infradead.org, catalin.marinas@arm.com, tglx@linutronix.de, jmarchan@redhat.com, dave@stgolabs.net, darren@dvhart.com, lwoodman@redhat.com, torvalds@linux-foundation.org Reply-To: dave@stgolabs.net, tglx@linutronix.de, jmarchan@redhat.com, torvalds@linux-foundation.org, darren@dvhart.com, lwoodman@redhat.com, mingo@kernel.org, linux-kernel@vger.kernel.org, mguzik@redhat.com, hpa@zytor.com, oleg@redhat.com, catalin.marinas@arm.com, peterz@infradead.org In-Reply-To: <20150202140536.GA26406@redhat.com> References: <20150202140536.GA26406@redhat.com> To: linux-tip-commits@vger.kernel.org Subject: [tip:locking/core] locking/futex: Check PF_KTHREAD rather than !p->mm to filter out kthreads Git-Commit-ID: a21294644623ee41034db60e93aaebed4db0e57b X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit-ID: a21294644623ee41034db60e93aaebed4db0e57b Gitweb: http://git.kernel.org/tip/a21294644623ee41034db60e93aaebed4db0e57b Author: Oleg Nesterov AuthorDate: Mon, 2 Feb 2015 15:05:36 +0100 Committer: Ingo Molnar CommitDate: Wed, 18 Feb 2015 16:57:09 +0100 locking/futex: Check PF_KTHREAD rather than !p->mm to filter out kthreads attach_to_pi_owner() checks p->mm to prevent attaching to kthreads and this looks doubly wrong: 1. It should actually check PF_KTHREAD, kthread can do use_mm(). 2. If this task is not kthread and it is actually the lock owner we can wrongly return -EPERM instead of -ESRCH or retry-if-EAGAIN. And note that this wrong EPERM is the likely case unless the exiting task is (auto)reaped quickly, we check ->mm before PF_EXITING. Signed-off-by: Oleg Nesterov Signed-off-by: Peter Zijlstra (Intel) Cc: Catalin Marinas Cc: Darren Hart Cc: Davidlohr Bueso Cc: Jerome Marchand Cc: Larry Woodman Cc: Linus Torvalds Cc: Mateusz Guzik Link: http://lkml.kernel.org/r/20150202140536.GA26406@redhat.com Signed-off-by: Ingo Molnar --- kernel/futex.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kernel/futex.c b/kernel/futex.c index 4eeb63d..1f6d646 100644 --- a/kernel/futex.c +++ b/kernel/futex.c @@ -900,7 +900,7 @@ static int attach_to_pi_owner(u32 uval, union futex_key *key, if (!p) return -ESRCH; - if (!p->mm) { + if (unlikely(p->flags & PF_KTHREAD)) { put_task_struct(p); return -EPERM; }