Received: by 2002:a25:c205:0:0:0:0:0 with SMTP id s5csp1477355ybf; Sun, 1 Mar 2020 10:23:04 -0800 (PST) X-Google-Smtp-Source: ADFU+vuaTiOQx0RtxpbE+rHJ4GeA9O1alCEn1kG0cEE1yOVFv/EmQeKj66O5DQ9k/ZdiiHn5ZxM0 X-Received: by 2002:aca:fc11:: with SMTP id a17mr3006740oii.123.1583086984280; Sun, 01 Mar 2020 10:23:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1583086984; cv=none; d=google.com; s=arc-20160816; b=yIv7slJGco8CyqrIQKQVyXcmPS2DRNUSvKejPTYEl/GuJibRA7wswVXlwlFpzVS4qd jHii3ZuFewh7gnBOL2WI3YyAnFjbXVMMDrDmWIk7gq9b8h33Du2ke88n0qtTT/TNfBW/ QihkfU6CyuyLzHA4/h1eSRPLutBS/wAQPKvvFlVo8zEEG5qxpILFeYLzN3CNlKEDCmop rXHEgmHxaHGt5oXOl2ZATCLu88RFB6CS5h8iFVhaaRz13iYb9O5dVllXu8/AA8Eki8tN WmGqr74iIMhPfEzMIIIV/Py7GAzWO4ly9Zk9I1jCn1LMZ0z68Kq5VyFGyHOLABVUbobx YMLQ== 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=vl+p/47GQAMvlM1on1gMGR7KlW+3+hbOHuckhCOrwj8=; b=KFx4O/AXT8pAi4eHSfH5EMxUW1M0ot57Ipmvbtpzljl9mERy/3Npqf6U8niLsaBtcp Q5+6Cw5LkjQ8sR9mkcUwGI7uC6vkDwxm81yRylD86GMyxf5RPzN5Mfh0PYy0krYAP1ui WoDHQc/tzzW0yVR9ZUXKLAE7lY71AeqNIZnDqRzDAdfdVm1HkAyMC9EgEkF7IA/SLPTD bgtHrfur1xGcK9MfIlMmzCELFlDbvPiXVcUIVNGBL7xU4lp6ozVT4vETCA9kPwmmuBJF fsDHXej/YQ0o9SijnDZkVKGKX22gjyKUJzKDK5/gxoc0ZdfkVIqQ3cAJ0kgHHkvyAL9N Xq8A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b="bX0rE7/K"; 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 z23si4918742oti.34.2020.03.01.10.22.52; Sun, 01 Mar 2020 10:23:04 -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; dkim=pass header.i=@google.com header.s=20161025 header.b="bX0rE7/K"; 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 S1726146AbgCASVb (ORCPT + 99 others); Sun, 1 Mar 2020 13:21:31 -0500 Received: from mail-ot1-f66.google.com ([209.85.210.66]:39210 "EHLO mail-ot1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726359AbgCASVa (ORCPT ); Sun, 1 Mar 2020 13:21:30 -0500 Received: by mail-ot1-f66.google.com with SMTP id x97so7487135ota.6 for ; Sun, 01 Mar 2020 10:21:30 -0800 (PST) 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=vl+p/47GQAMvlM1on1gMGR7KlW+3+hbOHuckhCOrwj8=; b=bX0rE7/Kbt+xy/GSs67GMlp7VaEG4nm8/Urc8KQQABYyaPFqpHwWxlJXGJfWtklvZc K4GWxp0lyiEPXaEiIICPIVAdueUja2k/3XpMJW5cpWctmz2HKNCQ7rdD51729m6QPyem +85M/LvlHc5U93Uv0pE0P56swR582muuOw8IotQrUp8TAFpkt+Xs6+kdDJp0TO/40xM4 7Oh2sappSmX8it1XfO+o7tYZ5PY70aijZzD2RvZLBlILFMGxEqZf4SK3BZJskUxfcsjB Q0mDqlgPfTEVyaumTAB4RSMPcMhonT4qZ1aUpFQuHM0WHk+Y03k/cX9oR825i7llamx1 8T1A== 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=vl+p/47GQAMvlM1on1gMGR7KlW+3+hbOHuckhCOrwj8=; b=rfhc27/Z/n6LXAk+sT7Txuhe9NXIKvcRzoJeJ7CE2regdAGBxTJJlA2P/gcEYH5maw HLSqqAXsibzMlhjdCMfoMtbPW9kVv1eXQeOMQ1oQ8Cyu+mcJbPQwwZa2mnUJPcOurLN2 svZn3ux9wtFc1/kPQEcQ4HVyjd7u3ei2kVVIL94LPUYPXjFlWqC0iVRoXWpApJT0mlIZ 6H3dD7LsJRsMkluE0nvqwsunur+BNe+Oe5jkyAW0c9z6PfNLUKge3JiA51Pk7qOWtGSI PRte5YeImuU/mRjcCZjMMpyVnkAVucLLs6BOML8IJXXkmduxeZ/MBdgBjTspwxRkJ5wi RoOw== X-Gm-Message-State: APjAAAWoTtLN9OaslgTLUezjD2BpCT/AqkwaKF2tyzsLn0G0WLxibSOq bhNY82zxSO+M4u16aDgRB9kWfHY7OlLp+YbQL32gPg== X-Received: by 2002:a9d:5e8b:: with SMTP id f11mr10758287otl.110.1583086889943; Sun, 01 Mar 2020 10:21:29 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: Jann Horn Date: Sun, 1 Mar 2020 19:21:03 +0100 Message-ID: Subject: Re: [PATCH] exec: Fix a deadlock in ptrace To: Bernd Edlinger Cc: 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 , Christian Brauner , 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" 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 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 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.