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 EAD41C10DCE for ; Tue, 10 Mar 2020 21:21:58 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id CA5E5205F4 for ; Tue, 10 Mar 2020 21:21:58 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="pOgk4Qkw" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727085AbgCJVV5 (ORCPT ); Tue, 10 Mar 2020 17:21:57 -0400 Received: from mail-oi1-f194.google.com ([209.85.167.194]:33499 "EHLO mail-oi1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726268AbgCJVV5 (ORCPT ); Tue, 10 Mar 2020 17:21:57 -0400 Received: by mail-oi1-f194.google.com with SMTP id r7so2322655oij.0 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=ujz++LoEuwo5jT+q2WUeDjuJKHsO+8D90z33Y16EMQfMYx2fZkYhDmgZO1KKuwYufu ReGk1SDWUQwK8R34xulsplbs8DAirLI0QIaopqBNNM40PkV6d9X+loKa649o5jbnfWVO GO2Mymm1MSCRn57nsJP8aA3EftlcEEsfF0DXEQAn5lbkXbnObGmyFDxKPT2ptApUHAg4 Pi4NE3YlGWk86M8L0RjV2GF0Q1zqS8eL/oPTkzlvQ1GUr1EAMSs+kZ+WQqTWcGGD1cV1 RNpbpH0McRrhVaHysk/zJHpQMGQjwkvdgGZIdM05cRPHRMcx6HaBHP+FYGBd2hQoTs3a AlHA== X-Gm-Message-State: ANhLgQ3pb44vWa5wEm9IyZ0UgXpkJAgoOYDFjd5ysbqWLoT+5EPs0Lug QSFAe6MkAXjdnm+SRVLy0OUClkM81cOsZ+sTyuDcSQ== 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" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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.