Received: by 2002:a25:e7d8:0:0:0:0:0 with SMTP id e207csp1085940ybh; Tue, 10 Mar 2020 14:22:35 -0700 (PDT) X-Google-Smtp-Source: ADFU+vtDK07yC67GurKFx+CsVMXMLPZkZiH7kOF61HKp77rUibtC5crUv0480ZG4QtEars4GeEHJ X-Received: by 2002:a9d:22e9:: with SMTP id y96mr3253773ota.217.1583875355338; Tue, 10 Mar 2020 14:22:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1583875355; cv=none; d=google.com; s=arc-20160816; b=k/GWSTLyzShsu9+d3Hb0PXBgzO/dcEpum62dNzsj1aS33d7/ThG7XvRRyTgSaOCW2J SmRleXoYx//8E3WjeGsXKTElDEvuPWQcvWvra8iBQjFW/RQZ89uyjMwXIcjsJopiqcyM uFjS+8tXg7kkqo8gxsOzU4A+sZqB3AfqjZFSS+tcUmjcU09zOYDcz3kYxRAZjyltPdIS UMXAyFLSTIpbuV4LulJNqLkowf1/ijCH76HI68KoGaoFcAx+OLU9gNzvaaQWTlcAG0S6 frYypt2Mq0T+THOJNa4m1mM/BFmv5TAInxmgVWgZNeDGuNb840CM3TuY7zN3h+HlkOjP tASA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=oY6WFiAwH2rmOxKrZEesTv/eerBgzcIy7in/R7N6oGw=; b=NWWyM/LJmFhsS5dhZ+zBeP8aSbaaLsC/vhz5XSNeMWtuclSqpPepCscB017JGwaJbG O93NaTWL+8feVAMjyiRpqtL9HQrZzzKjv2TFfCW0G/sht/oWeZX44Z951z5lpl3WUeJz ruws700nWXZN12MfGsxa8RwZ+K2DgOZCTNSgyNPSJL/smIFILH2OXQ5fAtaT7/n8t6cf p34iyGT6DKZ2oayaC3rPs40ilcJ+Nfs8iQzbzybvoJBwlD7IyDfSugx3wbE0niLzX/8E IHdwrZRuIGDvLbO0/EjAXwIUZNIxH7MQ1bNOTV2zu6VKLaM8E7LZ/ainqLifDxK41r8Q 1CcQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=pOgk4Qkw; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b14si6391oie.88.2020.03.10.14.22.23; Tue, 10 Mar 2020 14:22:35 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=pOgk4Qkw; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726729AbgCJVV5 (ORCPT + 99 others); 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-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.