From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1758539AbaELUpl (ORCPT ); Mon, 12 May 2014 16:45:41 -0400 Received: from www.linutronix.de ([62.245.132.108]:56771 "EHLO Galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1758485AbaELUpk (ORCPT ); Mon, 12 May 2014 16:45:40 -0400 Message-Id: <20140512201701.194824402@linutronix.de> User-Agent: quilt/0.60-1 Date: Mon, 12 May 2014 20:45:35 -0000 From: Thomas Gleixner To: LKML Cc: Dave Jones , Linus Torvalds , Peter Zijlstra , Darren Hart , Davidlohr Bueso , Ingo Molnar , Steven Rostedt , Clark Williams , Paul McKenney , Lai Jiangshan , Roland McGrath , Carlos ODonell , Jakub Jelinek , Michael Kerrisk , Sebastian Andrzej Siewior Subject: [patch 3/3] futex: Prevent attaching to kernel threads References: <20140512190438.314125476@linutronix.de> Content-Disposition: inline; filename=futex-prevent-attaching-futex-to-kernel-threads.patch X-Linutronix-Spam-Score: -1.0 X-Linutronix-Spam-Level: - X-Linutronix-Spam-Status: No , -1.0 points, 5.0 required, ALL_TRUSTED=-1,SHORTCIRCUIT=-0.0001 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org We happily allow userspace to declare a random kernel thread to be the owner of a user space PI futex. Found while analysing the fallout of Dave Jones syscall fuzzer. Signed-off-by: Thomas Gleixner Cc: stable@vger.kernel.org --- kernel/futex.c | 7 +++++++ 1 file changed, 7 insertions(+) Index: linux-2.6/kernel/futex.c =================================================================== --- linux-2.6.orig/kernel/futex.c +++ linux-2.6/kernel/futex.c @@ -682,6 +682,8 @@ static struct task_struct * futex_find_g p = find_task_by_vpid(pid); if (p) get_task_struct(p); + else + p = NULL; rcu_read_unlock(); @@ -814,6 +816,11 @@ lookup_pi_state(u32 uval, struct futex_h if (!p) return -ESRCH; + if (!p->mm) { + put_task_struct(p); + return -EPERM; + } + /* * We need to look at the task state flags to figure out, * whether the task is exiting. To protect against the do_exit