Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933415AbbBBOHQ (ORCPT ); Mon, 2 Feb 2015 09:07:16 -0500 Received: from mx1.redhat.com ([209.132.183.28]:33104 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932206AbbBBOHO (ORCPT ); Mon, 2 Feb 2015 09:07:14 -0500 Date: Mon, 2 Feb 2015 15:05:36 +0100 From: Oleg Nesterov To: Darren Hart , Peter Zijlstra , Thomas Gleixner Cc: Jerome Marchand , Larry Woodman , Mateusz Guzik , linux-kernel@vger.kernel.org Subject: [PATCH 1/1] futex: check PF_KTHREAD rather than !p->mm to filter out kthreads Message-ID: <20150202140536.GA26406@redhat.com> References: <20150202140515.GA26398@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20150202140515.GA26398@redhat.com> User-Agent: Mutt/1.5.18 (2008-05-17) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1156 Lines: 38 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 --- kernel/futex.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/kernel/futex.c b/kernel/futex.c index 63678b5..b101381 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; } -- 1.5.5.1 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/