From patchwork Wed Mar 2 17:34:51 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrea Arcangeli X-Patchwork-Id: 8484291 Return-Path: X-Original-To: patchwork-linux-fsdevel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id EB9F2C0553 for ; Wed, 2 Mar 2016 17:35:15 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 02778202B8 for ; Wed, 2 Mar 2016 17:35:15 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id DC61C2025B for ; Wed, 2 Mar 2016 17:35:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755687AbcCBRey (ORCPT ); Wed, 2 Mar 2016 12:34:54 -0500 Received: from mx1.redhat.com ([209.132.183.28]:41145 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754557AbcCBRex (ORCPT ); Wed, 2 Mar 2016 12:34:53 -0500 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) by mx1.redhat.com (Postfix) with ESMTPS id 46078311E; Wed, 2 Mar 2016 17:34:53 +0000 (UTC) Received: from mail.random (ovpn-116-35.ams2.redhat.com [10.36.116.35]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u22HYpTS020076 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Wed, 2 Mar 2016 12:34:52 -0500 Date: Wed, 2 Mar 2016 18:34:51 +0100 From: Andrea Arcangeli To: Linus Torvalds Cc: Al Viro , Dmitry Vyukov , "linux-fsdevel@vger.kernel.org" , LKML , Pavel Emelyanov , Andrew Morton , syzkaller , Kostya Serebryany , Alexander Potapenko , Sasha Levin Subject: Re: fs: uninterruptible hang in handle_userfault Message-ID: <20160302173451.GB4946@redhat.com> References: <20160301195957.GD17997@ZenIV.linux.org.uk> <20160302004845.GF17997@ZenIV.linux.org.uk> <20160302145521.GO1180@redhat.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.24 (2015-08-30) X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP On Wed, Mar 02, 2016 at 09:03:01AM -0800, Linus Torvalds wrote: > It's not just "exit_futex()" (what is that? I assume you mean That come from a cleanup (appended below but not very well tested) I did initially to consolidate the futex exit code before attempting to relocate its call location. > exit_robust_list()) that triggers the problem, it's also the > > put_user(0, tsk->clear_child_tid); > > in mm_release(). From the stack trace it didn't appear to refault there and it was still stuck in exit_futex, but this could end up in the same problem and your fix already took care of this one as well. > So it's not just about futexes. > > The might be other final user space accesses lurking too that I didn't > even think about. > > Anyway, I committed (a) as the safest version with the least side > effects. If people think some more about this and come up with > solutions how to avoid these kinds of "very late user space accesses" > cleanly, I think that would be great. Agreed. Thanks, Andrea From 03f7e43aab4e4b6f02599f4ffffe4675581f691e Mon Sep 17 00:00:00 2001 From: Andrea Arcangeli Date: Wed, 2 Mar 2016 18:25:50 +0100 Subject: [PATCH 1/1] futex: cleanup #ifdef FUTEX and consolidate futex exit path There's no reason to expose futex internal details to the common exit path. Signed-off-by: Andrea Arcangeli --- include/linux/futex.h | 8 ++------ kernel/fork.c | 16 +--------------- kernel/futex.c | 22 ++++++++++++++++++++-- 3 files changed, 23 insertions(+), 23 deletions(-) -- To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/include/linux/futex.h b/include/linux/futex.h index 6435f46..89da7d6 100644 --- a/include/linux/futex.h +++ b/include/linux/futex.h @@ -53,18 +53,14 @@ union futex_key { #define FUTEX_KEY_INIT (union futex_key) { .both = { .ptr = NULL } } #ifdef CONFIG_FUTEX -extern void exit_robust_list(struct task_struct *curr); -extern void exit_pi_state_list(struct task_struct *curr); +extern void exit_futex(struct task_struct *tsk); #ifdef CONFIG_HAVE_FUTEX_CMPXCHG #define futex_cmpxchg_enabled 1 #else extern int futex_cmpxchg_enabled; #endif #else -static inline void exit_robust_list(struct task_struct *curr) -{ -} -static inline void exit_pi_state_list(struct task_struct *curr) +static inline void exit_futex(struct task_struct *tsk) { } #endif diff --git a/kernel/fork.c b/kernel/fork.c index 2e391c7..81974dd 100644 --- a/kernel/fork.c +++ b/kernel/fork.c @@ -855,21 +855,7 @@ static int wait_for_vfork_done(struct task_struct *child, */ void mm_release(struct task_struct *tsk, struct mm_struct *mm) { - /* Get rid of any futexes when releasing the mm */ -#ifdef CONFIG_FUTEX - if (unlikely(tsk->robust_list)) { - exit_robust_list(tsk); - tsk->robust_list = NULL; - } -#ifdef CONFIG_COMPAT - if (unlikely(tsk->compat_robust_list)) { - compat_exit_robust_list(tsk); - tsk->compat_robust_list = NULL; - } -#endif - if (unlikely(!list_empty(&tsk->pi_state_list))) - exit_pi_state_list(tsk); -#endif + exit_futex(tsk); uprobe_free_utask(tsk); diff --git a/kernel/futex.c b/kernel/futex.c index 5d6ce64..eb2ea48 100644 --- a/kernel/futex.c +++ b/kernel/futex.c @@ -65,6 +65,7 @@ #include #include #include +#include #include @@ -752,7 +753,7 @@ static struct task_struct * futex_find_get_task(pid_t pid) * Kernel cleans up PI-state, but userspace is likely hosed. * (Robust-futex cleanup is separate and might save the day for userspace.) */ -void exit_pi_state_list(struct task_struct *curr) +static void exit_pi_state_list(struct task_struct *curr) { struct list_head *next, *head = &curr->pi_state_list; struct futex_pi_state *pi_state; @@ -2975,7 +2976,7 @@ static inline int fetch_robust_entry(struct robust_list __user **entry, * * We silently return on any sign of list-walking problem. */ -void exit_robust_list(struct task_struct *curr) +static void exit_robust_list(struct task_struct *curr) { struct robust_list_head __user *head = curr->robust_list; struct robust_list __user *entry, *next_entry, *pending; @@ -3038,6 +3039,23 @@ void exit_robust_list(struct task_struct *curr) curr, pip); } +void exit_futex(struct task_struct *tsk) +{ + /* Get rid of any futexes when releasing the mm */ + if (unlikely(tsk->robust_list)) { + exit_robust_list(tsk); + tsk->robust_list = NULL; + } +#ifdef CONFIG_COMPAT + if (unlikely(tsk->compat_robust_list)) { + compat_exit_robust_list(tsk); + tsk->compat_robust_list = NULL; + } +#endif + if (unlikely(!list_empty(&tsk->pi_state_list))) + exit_pi_state_list(tsk); +} + long do_futex(u32 __user *uaddr, int op, u32 val, ktime_t *timeout, u32 __user *uaddr2, u32 val2, u32 val3) {