Received: by 2002:a25:c205:0:0:0:0:0 with SMTP id s5csp2516465ybf; Mon, 2 Mar 2020 10:10:34 -0800 (PST) X-Google-Smtp-Source: ADFU+vv4LhcOUxxGnuxnqII/CN+za3mKtko1BJM4e3jAnwvuO5rnfHbFB+8lU9ASuAOnPQMcHaMr X-Received: by 2002:a9d:63d6:: with SMTP id e22mr331679otl.185.1583172634265; Mon, 02 Mar 2020 10:10:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1583172634; cv=none; d=google.com; s=arc-20160816; b=0TB3p7h5S7Ym0019aYyc+wyOdfLUQ4115nUdFov9/3E6Nz0772ZF+KpzvpVYi8DCSZ gYXOK7UnEVh8I/eZ97xF21VHFs8u/7ENVzZoOk8SaF7RBqBta1to8KhNgp45UvkBuLxj nqFVlI8mLSISmjwhCmOUOxsAaWC3PWP2JezhtBNuK0hCni+tCJ+ICQ8Q1FV/0C49rdDm EwuZks7Lshzo5DD8TulR6b+zPvO5i+4WeaQVQISgLjsBq/A9BBpZ+QIkKWtwFUsOZa50 uCDx3SZNEPqJMdx9SmtobEdVDh0OcE2Ehb3yLPbTe3PtDiHayAYwozIK9tiTxnXJUu7G oHNw== 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=PzpHTT1CytF1CxOEOyrFfNGNhtkDEaDUtrYOH2iFLfA=; b=QdXQa5Qta72LkKBlQ+a4XiQRoxxn9WnMUBVqQLpETc21QOC+6fViAomwedL6a7b/nl qQ59fD+3bgwvi9me63Kh8PGYil3x944bqR8iVWBbnlTWjmjQlBIIdl7o/6Jv0t/AZeJz D3XSme57K85DvKcPo8kpiiAw04lUJFWHO5DR8aH4MbpGwph1JPKyzQy5R5CKAPimeINW PyoalrE0ZyX9qan1ZKUbT9grS3PhGfFDbf6JwLFd6cHBjZp8Z1QpOCUiH1wpDlahVhWk 9Gr8PFGndcrlQNVVOagApYqUpS7u22PWdw4tC6avXqTW3IWrPhoSS1YCK7c2Cj3jSdlY U+Lw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=UqoUm420; 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 w142si6602201oia.132.2020.03.02.10.10.22; Mon, 02 Mar 2020 10:10:34 -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=UqoUm420; 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 S1727695AbgCBSI5 (ORCPT + 99 others); Mon, 2 Mar 2020 13:08:57 -0500 Received: from mail-oi1-f196.google.com ([209.85.167.196]:44787 "EHLO mail-oi1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727470AbgCBSI5 (ORCPT ); Mon, 2 Mar 2020 13:08:57 -0500 Received: by mail-oi1-f196.google.com with SMTP id d62so103101oia.11 for ; Mon, 02 Mar 2020 10:08:56 -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=PzpHTT1CytF1CxOEOyrFfNGNhtkDEaDUtrYOH2iFLfA=; b=UqoUm420YQqph3lafHzahQC9V4PdPL/4Qyv6M+TEFjDDlhJUhALb/SAIvAmoSGffyg a+snzgE9CJkyJGW23tqeS/3KQPZf8xJ7BanaVOsbMgKmsVis3fA3OOYQ4v4jTJ1AGhBx K9uQcOSkDeBAtHH7P5nmgTAOojjqNLiO2lPI2fA3RN3wz4dmhavt79Zq4NlnBzpJ+OiA y/TbZNOouXWb/oNa3vM1C3IKrlLfcmIRapwpat4xfLEuvxXctHbiwYexiaQCCtswST76 0aZ+VZ+Y0oTlg6eIsuwolOfq1+Y8oOzdLvBO6TZUDoqbSO/q1tj2btepq92gHR5lOUfD s1FQ== 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=PzpHTT1CytF1CxOEOyrFfNGNhtkDEaDUtrYOH2iFLfA=; b=DAjWgYEfb08TdMhulMh0UK0KaRmOeMA3HGiKctS2d+vdhLPkTWEARh/dCRBqQf57RM RJme3pFdM1g+SK/1ng2IrlJkFWpEvTrhgmpnUFjdIwq0vVESo04ndEZoprU1bxwVFz6F RkfovzbQ388cPQbbTlwokNHstr2fn7VpsWAkGJKkW0saT385bQhzuyNJ6BBg4qhNQ7gy b7TF4ZGyfeyK3duCbiJX/W9Zl4f4MPNS0e+w/RzSIlIr4KlTMdamt38UoOU0Q70VeNEZ EDMuu/XWgSKbxSBXKQGHkBsn3j3E2CWyKskhQtvXUbS37Gqt+b4hX4lbBZZDfcy7WBfE LFiw== X-Gm-Message-State: ANhLgQ2jv0+VsML6a+sXre41aN17nC3A9U/421OM6Z6q1Utk4x0d8rYZ GFSUZgBMbQG9UU2jcz/HpHtm22Qbv02p/r5NeIDr+w== X-Received: by 2002:aca:538e:: with SMTP id h136mr242942oib.39.1583172536153; Mon, 02 Mar 2020 10:08:56 -0800 (PST) MIME-Version: 1.0 References: <20200301185244.zkofjus6xtgkx4s3@wittgenstein> <87a74zmfc9.fsf@x220.int.ebiederm.org> <87k142lpfz.fsf@x220.int.ebiederm.org> <875zfmloir.fsf@x220.int.ebiederm.org> <5e5d45a3.1c69fb81.f99ac.0806@mx.google.com> In-Reply-To: <5e5d45a3.1c69fb81.f99ac.0806@mx.google.com> From: Jann Horn Date: Mon, 2 Mar 2020 19:08:29 +0100 Message-ID: Subject: Re: [PATCHv2] exec: Fix a deadlock in ptrace To: Christian Brauner Cc: Bernd Edlinger , "Eric W. Biederman" , James Morris , 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 , 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" , "stable@vger.kernel.org" , linux-security-module 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 Mon, Mar 2, 2020 at 6:43 PM wrote: > On March 2, 2020 6:37:27 PM GMT+01:00, Jann Horn wrote: > >On Mon, Mar 2, 2020 at 6:01 PM Bernd Edlinger > > wrote: > >> On 3/2/20 5:43 PM, Jann Horn wrote: > >> > On Mon, Mar 2, 2020 at 5:19 PM Eric W. Biederman > > wrote: [...] > >> >> I am 99% convinced that the fix is to move cred_guard_mutex down. > >> > > >> > "move cred_guard_mutex down" as in "take it once we've already set > >up > >> > the new process, past the point of no return"? > >> > > >> >> Then right after we take cred_guard_mutex do: > >> >> if (ptraced) { > >> >> use_original_creds(); > >> >> } > >> >> > >> >> And call it a day. > >> >> > >> >> The details suck but I am 99% certain that would solve everyones > >> >> problems, and not be too bad to audit either. > >> > > >> > Ah, hmm, that sounds like it'll work fine at least when no LSMs are > >involved. > >> > > >> > SELinux normally doesn't do the execution-degrading thing, it just > >> > blocks the execution completely - see their > >selinux_bprm_set_creds() > >> > hook. So I think they'd still need to set some state on the task > >that > >> > says "we're currently in the middle of an execution where the > >target > >> > task will run in context X", and then check against that in the > >> > ptrace_may_access hook. Or I suppose they could just kill the task > >> > near the end of execve, although that'd be kinda ugly. > >> > > >> > >> We have current->in_execve for that, right? > >> I think when the cred_guard_mutex is taken only in the critical > >section, > >> then PTRACE_ATTACH could take the guard_mutex, and look at > >current->in_execve, > >> and just return -EAGAIN in that case, right, everybody happy :) > > > >It's probably going to mean that things like strace will just randomly > >fail to attach to processes if they happen to be in the middle of > >execve... but I guess that works? > > That sounds like an acceptable outcome. > We can at least risk it and if we regress > revert or come up with the more complex > solution suggested in another mail here? Yeah, sounds reasonable, I guess.