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,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 97EBAC3F2CD for ; Sun, 1 Mar 2020 18:21:32 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 5DCA724692 for ; Sun, 1 Mar 2020 18:21:32 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="bX0rE7/K" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5DCA724692 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 0F3C66B0006; Sun, 1 Mar 2020 13:21:32 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 0A33C6B0007; Sun, 1 Mar 2020 13:21:32 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id ED3F96B0008; Sun, 1 Mar 2020 13:21:31 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0100.hostedemail.com [216.40.44.100]) by kanga.kvack.org (Postfix) with ESMTP id D09AC6B0006 for ; Sun, 1 Mar 2020 13:21:31 -0500 (EST) Received: from smtpin10.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 783268245571 for ; Sun, 1 Mar 2020 18:21:31 +0000 (UTC) X-FDA: 76547611182.10.teeth05_81ad2bc2cb623 X-HE-Tag: teeth05_81ad2bc2cb623 X-Filterd-Recvd-Size: 5154 Received: from mail-ot1-f67.google.com (mail-ot1-f67.google.com [209.85.210.67]) by imf27.hostedemail.com (Postfix) with ESMTP for ; Sun, 1 Mar 2020 18:21:30 +0000 (UTC) Received: by mail-ot1-f67.google.com with SMTP id v19so7478033ote.8 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=PB+IsJMyzkCY0KBzh0nfDpACoCjHa7bgb+SwJoYNNvtpqsX5047XmjXcUIboNBaMZI 8tSzLnFJpkYTgHSYk+kB1Yx6IHJ/AN7QaGLQMhOiALXze/F/OqBcDiizQ8Qp+1ushmVs odv7nT65icA0/D7KB/meHn1yD87mwr8U01RvbrBGvz6XJNWJ24RNpIGEyH1/I8LYVDSL 44K74PqWv2D7CtVmLyitJ7N149qGVbQjA3rQWUx+zr6WAqImJz+e4s3cEBIc9xyuJrnZ vKOSvn70KkwnkCdQGFngdZgeLH86QJW9gWsjQEROMHL67Z6BaSB2gdVBVZmfnq2zZTnr WNvw== X-Gm-Message-State: APjAAAXNA4mU/8DHzK5T/8ohzXM/VlHzx2Yj14oBBvuNKw9tN/10JQnV lo/OeZcdOvF5xeS0fKuEtw6rPm4kDLSb6hVh0uWFOg== X-Google-Smtp-Source: APXvYqw6D45LqFPVIa5UnAzmqeAgyvkzqYARvALZry1klV1ny8N/BcDkUfrvPSLaIdAoHd8oI1tIwV03Dfkn7rQ5H54= 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" 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 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.