From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.4 required=3.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_IN_DEF_DKIM_WL autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6C558C18E5B for ; Tue, 10 Mar 2020 21:21:57 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 3EACF205F4 for ; Tue, 10 Mar 2020 21:21:57 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="pOgk4Qkw" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3EACF205F4 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id C7DC16B0003; Tue, 10 Mar 2020 17:21:56 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C2EE86B0006; Tue, 10 Mar 2020 17:21:56 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B43F16B0007; Tue, 10 Mar 2020 17:21:56 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0192.hostedemail.com [216.40.44.192]) by kanga.kvack.org (Postfix) with ESMTP id 9D2796B0003 for ; Tue, 10 Mar 2020 17:21:56 -0400 (EDT) Received: from smtpin08.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 6D6FF8248047 for ; Tue, 10 Mar 2020 21:21:56 +0000 (UTC) X-FDA: 76580725032.08.boat49_2dfe7cbdb3e3a X-HE-Tag: boat49_2dfe7cbdb3e3a X-Filterd-Recvd-Size: 6706 Received: from mail-oi1-f194.google.com (mail-oi1-f194.google.com [209.85.167.194]) by imf16.hostedemail.com (Postfix) with ESMTP for ; Tue, 10 Mar 2020 21:21:55 +0000 (UTC) Received: by mail-oi1-f194.google.com with SMTP id g6so15508234oiy.1 for ; Tue, 10 Mar 2020 14:21:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=oY6WFiAwH2rmOxKrZEesTv/eerBgzcIy7in/R7N6oGw=; b=pOgk4QkwNjE9ZThPducZNz2cmkLnWvaI876S1TRO4iGhWGNwO4xeyozO2pBQZo6EHF JQVEDEVWKycwGwvq+HZjVgaoiUKdDnSZFrZA3DtKiH+v+ulH0tun5BKwOMc+uNb1uJfA SbHMI+ZIkwaVlXaUUt1Ss8T/jVCb93A+dlsuGEixKa/dAv1ixesVDs/rMy4jPxBcEZk0 pXA9JVnE7wzJoz2NxA67UWnOWzmDD1yleEt3IDn4KHJkQIJ6hql2/4wnXR6n2kzDNJ9W /0rF5K2Vrm64ePyg/3wD+fRy6CLlTHlgjrj9W25Drh1Cf20NS0r00PVjesUfgMcX5zgS JOJA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=oY6WFiAwH2rmOxKrZEesTv/eerBgzcIy7in/R7N6oGw=; b=ciCeuoLpMeyOg6bep8zsX4WgEF97gflJGyLU68aPFjenc05eefIPLwrTgXFIFnV/+y C4DitHLd0mAN7YYntXr9kLrHIDYv8Y/LmmULSG4mAs8/TdRwCvqacoygM+IUjDv1dzYs y31Zb/sSPaltRTOAx36ZvdvH/rpOdl0ROcjek5Z7WOu735uh6NmL+ocU1sgrFuraQTO/ S2F3li4dyaw0p+3/iwyyngpsBmvwDbGWs5TXxHna/GUmWHvmn1LZxcndzht1ZAPO6UTG 1Iy0BKdfrKgH1FkXQW3jLNPXC8YB55Ayo33iA8T1oOum9czPJjtpQbScNkNE0QfDlMvm 9vYA== X-Gm-Message-State: ANhLgQ2mzCQfFhSFwHYrkX4YCRHZKD/oF6uq4UhAO8k1x0YZOJbr6rZk u59N4aQucaBolW5o5HgTtpES1tJ7d992Z21g44UTAQ== X-Google-Smtp-Source: ADFU+vse+bXb9qnaCZ0PIM2j5foMfZrUhK8BdULRDK7eOwjFVGLfjwEB0kwKfljmq3ftrHjmGdpyQbeI0qHB6H/6olE= X-Received: by 2002:aca:bac1:: with SMTP id k184mr2238915oif.157.1583875314976; Tue, 10 Mar 2020 14:21:54 -0700 (PDT) MIME-Version: 1.0 References: <87k142lpfz.fsf@x220.int.ebiederm.org> <875zfmloir.fsf@x220.int.ebiederm.org> <87v9nmjulm.fsf@x220.int.ebiederm.org> <202003021531.C77EF10@keescook> <20200303085802.eqn6jbhwxtmz4j2x@wittgenstein> <87v9nlii0b.fsf@x220.int.ebiederm.org> <87a74xi4kz.fsf@x220.int.ebiederm.org> <87r1y8dqqz.fsf@x220.int.ebiederm.org> <87tv32cxmf.fsf_-_@x220.int.ebiederm.org> <87v9ne5y4y.fsf_-_@x220.int.ebiederm.org> <87zhcq4jdj.fsf_-_@x220.int.ebiederm.org> In-Reply-To: <87zhcq4jdj.fsf_-_@x220.int.ebiederm.org> From: Jann Horn Date: Tue, 10 Mar 2020 22:21:28 +0100 Message-ID: Subject: Re: [PATCH v2 5/5] exec: Add a exec_update_mutex to replace cred_guard_mutex To: "Eric W. Biederman" Cc: Bernd Edlinger , Christian Brauner , Kees Cook , Jonathan Corbet , Alexander Viro , Andrew Morton , Alexey Dobriyan , Thomas Gleixner , Oleg Nesterov , Frederic Weisbecker , Andrei Vagin , Ingo Molnar , "Peter Zijlstra (Intel)" , Yuyang Du , David Hildenbrand , Sebastian Andrzej Siewior , Anshuman Khandual , David Howells , James Morris , Greg Kroah-Hartman , Shakeel Butt , Jason Gunthorpe , Christian Kellner , Andrea Arcangeli , Aleksa Sarai , "Dmitry V. Levin" , "linux-doc@vger.kernel.org" , "linux-kernel@vger.kernel.org" , "linux-fsdevel@vger.kernel.org" , "linux-mm@kvack.org" , "stable@vger.kernel.org" , "linux-api@vger.kernel.org" Content-Type: text/plain; charset="UTF-8" X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Sun, Mar 8, 2020 at 10:41 PM Eric W. Biederman wrote: > The cred_guard_mutex is problematic. The cred_guard_mutex is held > over the userspace accesses as the arguments from userspace are read. > The cred_guard_mutex is held of PTRACE_EVENT_EXIT as the the other > threads are killed. The cred_guard_mutex is held over > "put_user(0, tsk->clear_child_tid)" in exit_mm(). > > Any of those can result in deadlock, as the cred_guard_mutex is held > over a possible indefinite userspace waits for userspace. > > Add exec_update_mutex that is only held over exec updating process > with the new contents of exec, so that code that needs not to be > confused by exec changing the mm and the cred in ways that can not > happen during ordinary execution of a process. > > The plan is to switch the users of cred_guard_mutex to > exec_udpate_mutex one by one. This lets us move forward while still > being careful and not introducing any regressions. [...] > @@ -1034,6 +1035,11 @@ static int exec_mmap(struct mm_struct *mm) > return -EINTR; > } > } > + > + ret = mutex_lock_killable(&tsk->signal->exec_update_mutex); > + if (ret) > + return ret; We're already holding the old mmap_sem, and now nest the exec_update_mutex inside it; but then while still holding the exec_update_mutex, we do mmput(), which can e.g. end up in ksm_exit(), which can do down_write(&mm->mmap_sem) from __ksm_exit(). So I think at least lockdep will be unhappy, and I'm not sure whether it's an actual problem or not.