Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp674900ybb; Wed, 25 Mar 2020 07:31:56 -0700 (PDT) X-Google-Smtp-Source: ADFU+vtGpnUXlKjutQy96IzB3eEYryKTyApnnlNEIUtnIKAzYOYas0WGivwQcy7hceqNcY0LZQbD X-Received: by 2002:a4a:674f:: with SMTP id j15mr1450992oof.41.1585146716003; Wed, 25 Mar 2020 07:31:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1585146715; cv=none; d=google.com; s=arc-20160816; b=jEsrrqO183jscJWA4Pj1bweMkWYVrLnGf3ZDwR307175RdUE+gBP3YX/XfW4IUYmbd LGGxjDktuvtAjoJpfOZMUeUDa1KIxCZM4sRvhTm7/mV5K6lFN4RSe9xEowwJVBZblNRo XKmadO+WNLojnbVUxdxAoKS3ACy8NOqnJSUORG7uWsHfW2AAHkKImjarLuvesgANgi/u H2zYSRgMvxv1mK3oqFOSBEaU3O1O7R4lA6EjghuIKoyQxo2RKHjoNC2oOIZOKsKvvGcS gUQbgSlYaI70r4ab4ekDWTH7wYaQr/xH90X2WU2EP5KONEgrJ2w8Ei4veGelJd5cxN0v s+Lw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:subject:mime-version:user-agent :message-id:in-reply-to:date:references:cc:to:from; bh=4MLND0929rbxMj0lUwbkJz0gCuO0GDhpGL5IrWzkhvA=; b=XZkQ2GfPd237Ikb76r4a77O/H0HFOoYdMKGUlfoDrjWYyBfY1QVcPqYxLMzBsnI9Bh 3Sih7xJzxJSK4KcQwa0ZUx5f67XkYBsJcTj3xqHNXHJk1heEX5Iaomiam6Wy8WdF/WkS 0qQQXIEjSaM4OTVspfSP+NAp3GQfmtiblBqFGxdRR47puJ3vx+c6Mzl15mwbe16RgePT 4uPzgwq5lsUZbD5qZ3RLV6NqQN2xbv5qUi3RMTpcaqqZ9bn5JW5XC9FGoOsKibqjqmPd G/ptiDkH6YDsWBF2yC2VbXFj2sZXe6rJEA5DdYKwO0v71CJbzaKyoiJ10CpOacbRSfmN PHNA== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=xmission.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e7si4252035otr.95.2020.03.25.07.31.41; Wed, 25 Mar 2020 07:31:55 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=xmission.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727768AbgCYOaI (ORCPT + 99 others); Wed, 25 Mar 2020 10:30:08 -0400 Received: from out03.mta.xmission.com ([166.70.13.233]:58982 "EHLO out03.mta.xmission.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727538AbgCYOaI (ORCPT ); Wed, 25 Mar 2020 10:30:08 -0400 Received: from in01.mta.xmission.com ([166.70.13.51]) by out03.mta.xmission.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jH72b-0002ea-CW; Wed, 25 Mar 2020 08:29:57 -0600 Received: from ip68-227-160-95.om.om.cox.net ([68.227.160.95] helo=x220.xmission.com) by in01.mta.xmission.com with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.87) (envelope-from ) id 1jH72Z-0002AT-33; Wed, 25 Mar 2020 08:29:56 -0600 From: ebiederm@xmission.com (Eric W. Biederman) To: Bernd Edlinger Cc: "gregkh\@linuxfoundation.org" , Kirill Tkhai , Christian Brauner , Kees Cook , "jannh\@google.com" , Jonathan Corbet , Alexander Viro , Andrew Morton , "adobriyan\@gmail.com" , Thomas Gleixner , Oleg Nesterov , Frederic Weisbecker , "avagin\@gmail.com" , Ingo Molnar , "Peter Zijlstra \(Intel\)" , "duyuyang\@gmail.com" , David Hildenbrand , Sebastian Andrzej Siewior , Anshuman Khandual , David Howells , James Morris , Shakeel Butt , Jason Gunthorpe , "christian\@kellner.me" , 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" References: <077b63b7-6f5e-aa8e-bf96-a586b481cc46@hotmail.de> Date: Wed, 25 Mar 2020 09:27:18 -0500 In-Reply-To: (Bernd Edlinger's message of "Sat, 21 Mar 2020 02:46:39 +0000") Message-ID: <87a7448q7t.fsf@x220.int.ebiederm.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.1 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-XM-SPF: eid=1jH72Z-0002AT-33;;;mid=<87a7448q7t.fsf@x220.int.ebiederm.org>;;;hst=in01.mta.xmission.com;;;ip=68.227.160.95;;;frm=ebiederm@xmission.com;;;spf=neutral X-XM-AID: U2FsdGVkX1//grV9RcExZss0OZxt5aCJ/pLvokQjxgE= X-SA-Exim-Connect-IP: 68.227.160.95 X-SA-Exim-Mail-From: ebiederm@xmission.com X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on sa08.xmission.com X-Spam-Level: X-Spam-Status: No, score=0.5 required=8.0 tests=ALL_TRUSTED,BAYES_50, DCC_CHECK_NEGATIVE,T_TM2_M_HEADER_IN_MSG,T_TooManySym_01, T_TooManySym_02,XMSubLong autolearn=disabled version=3.4.2 X-Spam-Report: * -1.0 ALL_TRUSTED Passed through trusted hosts only via SMTP * 0.8 BAYES_50 BODY: Bayes spam probability is 40 to 60% * [score: 0.4772] * 0.7 XMSubLong Long Subject * 0.0 T_TM2_M_HEADER_IN_MSG BODY: No description available. * -0.0 DCC_CHECK_NEGATIVE Not listed in DCC * [sa08 1397; Body=1 Fuz1=1 Fuz2=1] * 0.0 T_TooManySym_01 4+ unique symbols in subject * 0.0 T_TooManySym_02 5+ unique symbols in subject X-Spam-DCC: XMission; sa08 1397; Body=1 Fuz1=1 Fuz2=1 X-Spam-Combo: ;Bernd Edlinger X-Spam-Relay-Country: X-Spam-Timing: total 556 ms - load_scoreonly_sql: 0.04 (0.0%), signal_user_changed: 12 (2.2%), b_tie_ro: 10 (1.8%), parse: 1.50 (0.3%), extract_message_metadata: 14 (2.5%), get_uri_detail_list: 2.3 (0.4%), tests_pri_-1000: 14 (2.6%), tests_pri_-950: 1.33 (0.2%), tests_pri_-900: 1.19 (0.2%), tests_pri_-90: 231 (41.5%), check_bayes: 226 (40.7%), b_tokenize: 12 (2.1%), b_tok_get_all: 51 (9.3%), b_comp_prob: 2.7 (0.5%), b_tok_touch_all: 154 (27.8%), b_finish: 1.54 (0.3%), tests_pri_0: 268 (48.3%), check_dkim_signature: 0.80 (0.1%), check_dkim_adsp: 2.7 (0.5%), poll_dns_idle: 0.74 (0.1%), tests_pri_10: 2.3 (0.4%), tests_pri_500: 7 (1.2%), rewrite_mail: 0.00 (0.0%) Subject: Re: [PATCH v6 15/16] exec: Fix dead-lock in de_thread with ptrace_attach X-Spam-Flag: No X-SA-Exim-Version: 4.2.1 (built Thu, 05 May 2016 13:38:54 -0600) X-SA-Exim-Scanned: Yes (on in01.mta.xmission.com) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Bernd Edlinger writes: > This removes the last users of cred_guard_mutex > and replaces it with a new mutex exec_guard_mutex, > and a boolean unsafe_execve_in_progress. > > This addresses the case when at least one of the > sibling threads is traced, and therefore the trace > process may dead-lock in ptrace_attach, but de_thread > will need to wait for the tracer to continue execution. > > The solution is to detect this situation and make > ptrace_attach and similar functions return -EAGAIN, > but only in a situation where a dead-lock is imminent. > > This means this is an API change, but only when the > process is traced while execve happens in a > multi-threaded application. > > See tools/testing/selftests/ptrace/vmaccess.c > for a test case that gets fixed by this change. Hmm. The logic with unsafe_execve_in_progress is interesting. I think I see what you are aiming for. So far as you have hit what you are aiming for I think this is a safe change as the only cases that will change are the cases that would deadlock today. At a minimum the code is subtle and I don't see big fat warning comments that subtle code needs to keep people from using it wrong. Further while the change below to proc_pid_attr_write looks like it is being treated the same as ptrace_attach. When in fact proc_pid_attr_write needs the no_new_privs and ptrace_attach protection the same as exec. As the updated cred won't be used in an ongoing exec, exec does not need protection from proc_pid_attr_write, other than deadlock protection. Having the relevant lock be per task_struct lock would probably be a better way to avoid deadlock with a concurrent proc_pid_attr_write. So I am going to pass on these last two patches for now, and apply the rest and get them into linux-next. Eric > diff --git a/fs/proc/base.c b/fs/proc/base.c > index 6b13fc4..a428536 100644 > --- a/fs/proc/base.c > +++ b/fs/proc/base.c > @@ -2680,14 +2680,17 @@ static ssize_t proc_pid_attr_write(struct file * file, const char __user * buf, > } > > /* Guard against adverse ptrace interaction */ > - rv = mutex_lock_interruptible(¤t->signal->cred_guard_mutex); > + rv = mutex_lock_interruptible(¤t->signal->exec_guard_mutex); > if (rv < 0) > goto out_free; > > - rv = security_setprocattr(PROC_I(inode)->op.lsm, > - file->f_path.dentry->d_name.name, page, > - count); > - mutex_unlock(¤t->signal->cred_guard_mutex); > + if (unlikely(current->signal->unsafe_execve_in_progress)) > + rv = -EAGAIN; > + else > + rv = security_setprocattr(PROC_I(inode)->op.lsm, > + file->f_path.dentry->d_name.name, > + page, count); > + mutex_unlock(¤t->signal->exec_guard_mutex); > out_free: > kfree(page); > out: