Received: by 2002:a25:c205:0:0:0:0:0 with SMTP id s5csp1499571ybf; Sun, 1 Mar 2020 10:57:33 -0800 (PST) X-Google-Smtp-Source: APXvYqzKPxqil3bJvZShslmrRMZkncAoJgWtfM0Iz8p2A678Wv4MWGbilpYloM/7n2AX11ZUu8CG X-Received: by 2002:a9d:3f5:: with SMTP id f108mr10867856otf.103.1583089053829; Sun, 01 Mar 2020 10:57:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1583089053; cv=none; d=google.com; s=arc-20160816; b=U/TX/cbrAU86sJg03qlnSuSBaZlQ80pe7M1WYBjVAOqdPZRLg0VORfCDSXc3Gis1zJ KZQtpSdtJwIEfrN3TS+mPMox1IxPqyWm1FYLxPF1bGFlbBGe0ruT6LhG8JaCMilMqsYY G2MnJSqxnvl3iPlxVvLh544nu70tLyi7RLJ1NP+o4FNi1Vxy7M3Ymu4b+cqL/0H8vTjR UyEIVBCq6erzOpLbuU4uX5S53eyWvk0KF86XbyXow0hSWbZQMpFbue+Q/WSbV7JDPAnN 1HdNtFex+46fHyJg2lLF/AvELj4/QLIcj8VieKdxC2+JBNIba0rb90QaxpALwkAfE3IE /FbA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date; bh=XdKzdCfC7t1vkEoeaDms4mpuREj0a1ZAhZWE71FORZ4=; b=h03YSf9/EQRR2LKlf1jS2pLzqfvCmGBOJtT0u37UHjqosEw0cvTJEa8/Y9eyNmt1rV QRH/EbMtVZKplUJkGuOPUFaKgj9HjKPhCAvmMIrONniSmGajjg7t2DMyKjs2NRKE3n+q NJCks0oaefF2KsfQCUehDP2oPfP3jvzbX2WXlmy9hAOPSZfz9gqX+II123RNdbETyp0p Qg7KgGE8nEXhdB/WklnHh27hoTJLCB+ENmR6d31+GBQmxzma6epHBGswqHoWbI7itW2x bDFz/s+JKLm+lCQE61rwIHeBoD5dT2qTdQAiD2AG/4caGCvs+B//Tyw2n+Djl6ZUu/JJ ur/Q== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c189si4515852oig.74.2020.03.01.10.57.21; Sun, 01 Mar 2020 10:57:33 -0800 (PST) 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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726579AbgCASxY (ORCPT + 99 others); Sun, 1 Mar 2020 13:53:24 -0500 Received: from youngberry.canonical.com ([91.189.89.112]:57692 "EHLO youngberry.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726359AbgCASxY (ORCPT ); Sun, 1 Mar 2020 13:53:24 -0500 Received: from ip5f5bf7ec.dynamic.kabel-deutschland.de ([95.91.247.236] helo=wittgenstein) by youngberry.canonical.com with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1j8Thm-0000Kp-An; Sun, 01 Mar 2020 18:52:46 +0000 Date: Sun, 1 Mar 2020 19:52:44 +0100 From: Christian Brauner To: Jann Horn Cc: Bernd Edlinger , Jonathan Corbet , Alexander Viro , Andrew Morton , Alexey Dobriyan , "Eric W. Biederman" , 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 , Kees Cook , 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" Subject: Re: [PATCH] exec: Fix a deadlock in ptrace Message-ID: <20200301185244.zkofjus6xtgkx4s3@wittgenstein> References: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, Mar 01, 2020 at 07:21:03PM +0100, Jann Horn wrote: > On Sun, Mar 1, 2020 at 12:27 PM Bernd Edlinger > wrote: > > The proposed solution is to have a second mutex that is > > used in mm_access, so it is allowed to continue while the > > dying threads are not yet terminated. > > Just for context: When I proposed something similar back in 2016, > https://lore.kernel.org/linux-fsdevel/20161102181806.GB1112@redhat.com/ > was the resulting discussion thread. At least back then, I looked > through the various existing users of cred_guard_mutex, and the only > places that couldn't be converted to the new second mutex were > PTRACE_ATTACH and SECCOMP_FILTER_FLAG_TSYNC. > > > The ideal solution would IMO be something like this: Decide what the > new task's credentials should be *before* reaching de_thread(), > install them into a second cred* on the task (together with the new > dumpability), drop the cred_guard_mutex, and let ptrace_may_access() > check against both. After that, some further restructuring might even Hm, so essentially a private ptrace_access_cred member in task_struct? That would presumably also involve altering various LSM hooks to look at ptrace_access_cred. (Minor side-note, de_thread() takes a struct task_struct argument but only ever is passed current.) > allow the cred_guard_mutex to not be held across all of the VFS > operations that happen early on in execve, which may block > indefinitely. But that would be pretty complicated, so I think your > proposed solution makes sense for now, given that nobody has managed > to implement anything better in the last few years. Reading through the old threads and how often this issue came up, I tend to agree.