Received: by 2002:a25:e7d8:0:0:0:0:0 with SMTP id e207csp887242ybh; Wed, 11 Mar 2020 12:52:48 -0700 (PDT) X-Google-Smtp-Source: ADFU+vs9plIJCRRDCE5DL0GVpte0XVKVtVEf+timEoZEtA5csY2vCE2GoCrCHtOzNU5rne2Dbvuq X-Received: by 2002:aca:5757:: with SMTP id l84mr264900oib.56.1583956368806; Wed, 11 Mar 2020 12:52:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1583956368; cv=none; d=google.com; s=arc-20160816; b=BKvR1ohr6kSgPNybN5YVA/hx+mmGZVS5/Un63aDSwVLwHaKxfYAcFqchl/DjWxun0N svKp3NZ7lblenPR0cdH4lyokDBPsRyV7KsJfE+J/XXiGiVgqHzFB4qeYaqBOeSDKODKe MC+gklImWNUQ0vXsTr6MeHzsGa2oBpB+7qm4W2jikPWm6U4laMy6dHxb0+sycEhn9dpq 5LIIxWpoRsQWgd0O2TXW1SD2pxu4EhIadN+UGSPmcy5LWOgiOVhPoQe6paKBovUb3E6h 6ZnGzWcMaO3dU+mhv8fFk5+fXuku6Iy6iFUhffpXipMW25sDgMjSvisyvo+fo4N0Nz4m UHBQ== 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=npAawqjzB7hF5YO8932C8QLrjbvxVRATTjp7YTuqvHg=; b=jrOdlNWZLdczURQ/N2p/Q809Py/2oz4Wgwoe2+RP7Q6At/HRD02/nfPO/epYgo6IaK zAt5gkRedVaAzQso+NSMxjpQKAeY87vvjMVMosKc06ps8MD5HaSLyX7x7t2ira/R2rZh 3YaYCjBYeE+aDE0x+rjcDtV7RXaiK4qSjKfkIAoAG5zes7G146tiS46L0mpfXL6d37lu HijEAx38CVturLGLPeNKdOyZ2wk8eganWS22l+EJqJiszzWKhz8E71Njq3xNL42vi1uz +QSQWuaZXmgpP4U5d1u6e0uMptFThYllrwLVX8jGSwm7YszYnqELCyUmTitJLSdzd2ct 2nxA== 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 w21si1587181otj.321.2020.03.11.12.52.36; Wed, 11 Mar 2020 12:52:48 -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 S2387419AbgCKTvR (ORCPT + 99 others); Wed, 11 Mar 2020 15:51:17 -0400 Received: from out01.mta.xmission.com ([166.70.13.231]:48866 "EHLO out01.mta.xmission.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731030AbgCKTvQ (ORCPT ); Wed, 11 Mar 2020 15:51:16 -0400 Received: from in01.mta.xmission.com ([166.70.13.51]) by out01.mta.xmission.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jC7Nn-0003gw-M1; Wed, 11 Mar 2020 13:51:11 -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 1jC7Nm-0007Ul-Q4; Wed, 11 Mar 2020 13:51:11 -0600 From: ebiederm@xmission.com (Eric W. Biederman) To: Kees Cook Cc: Bernd Edlinger , Christian Brauner , Jann Horn , 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 , James Morris , 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-api\@vger.kernel.org" References: <87r1y12yc7.fsf@x220.int.ebiederm.org> <87k13t2xpd.fsf@x220.int.ebiederm.org> <87d09l2x5n.fsf@x220.int.ebiederm.org> <871rq12vxu.fsf@x220.int.ebiederm.org> <877dzt1fnf.fsf@x220.int.ebiederm.org> <875zfcxlwy.fsf@x220.int.ebiederm.org> <202003111203.738487D@keescook> Date: Wed, 11 Mar 2020 14:48:50 -0500 In-Reply-To: <202003111203.738487D@keescook> (Kees Cook's message of "Wed, 11 Mar 2020 12:08:08 -0700") Message-ID: <87pndin04d.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=1jC7Nm-0007Ul-Q4;;;mid=<87pndin04d.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+d5+rrjcsoE4xtiynlnq3fJUCLMY6zpyU= 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 sa05.xmission.com X-Spam-Level: ** X-Spam-Status: No, score=2.0 required=8.0 tests=ALL_TRUSTED,BAYES_50, DCC_CHECK_NEGATIVE,T_TM2_M_HEADER_IN_MSG,T_TooManySym_01,XMNoVowels, 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.5000] * 0.7 XMSubLong Long Subject * 1.5 XMNoVowels Alpha-numberic number with no vowels * 0.0 T_TM2_M_HEADER_IN_MSG BODY: No description available. * -0.0 DCC_CHECK_NEGATIVE Not listed in DCC * [sa05 1397; Body=1 Fuz1=1 Fuz2=1] * 0.0 T_TooManySym_01 4+ unique symbols in subject X-Spam-DCC: XMission; sa05 1397; Body=1 Fuz1=1 Fuz2=1 X-Spam-Combo: **;Kees Cook X-Spam-Relay-Country: X-Spam-Timing: total 421 ms - load_scoreonly_sql: 0.03 (0.0%), signal_user_changed: 3.4 (0.8%), b_tie_ro: 2.2 (0.5%), parse: 1.74 (0.4%), extract_message_metadata: 24 (5.6%), get_uri_detail_list: 2.6 (0.6%), tests_pri_-1000: 39 (9.3%), tests_pri_-950: 1.53 (0.4%), tests_pri_-900: 1.26 (0.3%), tests_pri_-90: 34 (8.1%), check_bayes: 33 (7.7%), b_tokenize: 14 (3.4%), b_tok_get_all: 9 (2.1%), b_comp_prob: 2.8 (0.7%), b_tok_touch_all: 4.1 (1.0%), b_finish: 0.70 (0.2%), tests_pri_0: 288 (68.3%), check_dkim_signature: 0.84 (0.2%), check_dkim_adsp: 2.1 (0.5%), poll_dns_idle: 0.35 (0.1%), tests_pri_10: 4.2 (1.0%), tests_pri_500: 19 (4.6%), rewrite_mail: 0.00 (0.0%) Subject: Re: [PATCH 3/4] proc: io_accounting: Use new infrastructure to fix deadlocks in execve 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 Kees Cook writes: > On Tue, Mar 10, 2020 at 06:45:47PM +0100, Bernd Edlinger wrote: >> This changes do_io_accounting to use the new exec_update_mutex >> instead of cred_guard_mutex. >> >> This fixes possible deadlocks when the trace is accessing >> /proc/$pid/io for instance. >> >> This should be safe, as the credentials are only used for reading. > > I'd like to see the rationale described better here for why it should be > safe. I'm still not seeing why this is safe here, as we might check > ptrace_may_access() with one cred and then iterate io accounting with a > different credential... > > What am I missing? The rational for non-regression is that exec_update_mutex covers all of the same tsk->cred changes as cred_guard_mutex. Therefore we are not any worse off, and we avoid the deadlock. As for safety. Jann's argument that the only interesting credential change is in exec applies. All other credential changes that have any effect on permission checks make the new cred non-dumpable (excepions apply see the code). So I think this is a non-regressing change. A safe change. I don't think either version of this code is fully correct. Eric >> Signed-off-by: Bernd Edlinger >> --- >> fs/proc/base.c | 4 ++-- >> 1 file changed, 2 insertions(+), 2 deletions(-) >> >> diff --git a/fs/proc/base.c b/fs/proc/base.c >> index 4fdfe4f..529d0c6 100644 >> --- a/fs/proc/base.c >> +++ b/fs/proc/base.c >> @@ -2770,7 +2770,7 @@ static int do_io_accounting(struct task_struct *task, struct seq_file *m, int wh >> unsigned long flags; >> int result; >> >> - result = mutex_lock_killable(&task->signal->cred_guard_mutex); >> + result = mutex_lock_killable(&task->signal->exec_update_mutex); >> if (result) >> return result; >> >> @@ -2806,7 +2806,7 @@ static int do_io_accounting(struct task_struct *task, struct seq_file *m, int wh >> result = 0; >> >> out_unlock: >> - mutex_unlock(&task->signal->cred_guard_mutex); >> + mutex_unlock(&task->signal->exec_update_mutex); >> return result; >> } >> >> -- >> 1.9.1