Received: by 2002:a25:c205:0:0:0:0:0 with SMTP id s5csp2424501ybf; Mon, 2 Mar 2020 08:21:18 -0800 (PST) X-Google-Smtp-Source: APXvYqzcQ+xceph5yJ3VaON2QvIABk4U+y2Q8IXkgtJwZ4QOiVO7BWN23BvDIRYAQ96dop45nn9k X-Received: by 2002:a9d:53c2:: with SMTP id i2mr12934072oth.43.1583166078520; Mon, 02 Mar 2020 08:21:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1583166078; cv=none; d=google.com; s=arc-20160816; b=DvaYZMob89r4EyMgH3YJ8JWWW9J9ikayfuBivGuxSxJ/xFFVjKDAbH7lM06OUbZP3s vqD7+XisJv97kbgk0J30aAUB93br53OLxT39shDWJTvWsVwk8xn4YSs0NVFkLXWUyrkf xxMn6rhcc9W7hiK61S0gfjsGwnLkgxjF2Pz7T2Kqo/MdyQ8j+bIxvBr4TnTRmMd0vMIn cyFB+5p6w+IwGuQWezJWTV/GV+JPjMz6E56tulY4Yt8tX9lnfnkHbF3XLLsbgpMvPP8U D37LiRwI8KatmoAf4UMBucv+EUfjovdjl712pzuXnerdzxzdJXi77lBrUyWW5C25KUCs KJng== 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=7iNdDe0AC5bhERp8UzIFMZpyRGr4kCsAMabRYxCcS9A=; b=ROowi76imMayGoaEOgbdv+eGR2ewLS/WpasSre6n/6wMcfBq98foms5ntgXacen9mY fOi673dRygGCicAdJyYFQzQR1zUFZ7QeWLar05bNpZLC/ADpA82iwJmwROrl6PfGmkZ6 Bgp/yU1fvsXxvNIkqYGc/UaklHdnonqUYs8QnfzoCGXW1HHlBhOzTFhFH94DhhqgMr7q hIqq3TCwUP0POuts9o4syxFJaXrPHKC1WjJ72TjrnyCIRrCmGH54wU23jFR+2RyU+AXj m2e4RvVAQIcksahZWZUW88gU87ja+S6v8fRvsiO52EkiZjWgdrVrYQFkbjp4qRw6dv5L Z2EA== 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 l5si6624664otn.35.2020.03.02.08.21.06; Mon, 02 Mar 2020 08:21:18 -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; 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 S1727202AbgCBQTq (ORCPT + 99 others); Mon, 2 Mar 2020 11:19:46 -0500 Received: from out02.mta.xmission.com ([166.70.13.232]:33604 "EHLO out02.mta.xmission.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726621AbgCBQTq (ORCPT ); Mon, 2 Mar 2020 11:19:46 -0500 Received: from in02.mta.xmission.com ([166.70.13.52]) by out02.mta.xmission.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1j8nnD-0001jz-MG; Mon, 02 Mar 2020 09:19:43 -0700 Received: from ip68-227-160-95.om.om.cox.net ([68.227.160.95] helo=x220.xmission.com) by in02.mta.xmission.com with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.87) (envelope-from ) id 1j8nnC-0000UA-Vb; Mon, 02 Mar 2020 09:19:43 -0700 From: ebiederm@xmission.com (Eric W. Biederman) To: Bernd Edlinger Cc: Jann Horn , Christian Brauner , 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 , 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" References: <20200301185244.zkofjus6xtgkx4s3@wittgenstein> <87a74zmfc9.fsf@x220.int.ebiederm.org> <87k142lpfz.fsf@x220.int.ebiederm.org> Date: Mon, 02 Mar 2020 10:17:32 -0600 In-Reply-To: (Bernd Edlinger's message of "Mon, 2 Mar 2020 16:02:46 +0000") Message-ID: <875zfmloir.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=1j8nnC-0000UA-Vb;;;mid=<875zfmloir.fsf@x220.int.ebiederm.org>;;;hst=in02.mta.xmission.com;;;ip=68.227.160.95;;;frm=ebiederm@xmission.com;;;spf=neutral X-XM-AID: U2FsdGVkX1/rDgyLYZJLEvddAZC2RnTuV8ERN149vpA= 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.2 required=8.0 tests=ALL_TRUSTED,BAYES_50, DCC_CHECK_NEGATIVE,T_TM2_M_HEADER_IN_MSG 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.4839] * 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] 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 306 ms - load_scoreonly_sql: 0.05 (0.0%), signal_user_changed: 3.9 (1.3%), b_tie_ro: 2.7 (0.9%), parse: 1.68 (0.5%), extract_message_metadata: 15 (5.1%), get_uri_detail_list: 1.98 (0.6%), tests_pri_-1000: 16 (5.4%), tests_pri_-950: 1.46 (0.5%), tests_pri_-900: 1.26 (0.4%), tests_pri_-90: 33 (10.9%), check_bayes: 32 (10.3%), b_tokenize: 10 (3.4%), b_tok_get_all: 10 (3.3%), b_comp_prob: 2.8 (0.9%), b_tok_touch_all: 4.3 (1.4%), b_finish: 0.85 (0.3%), tests_pri_0: 220 (72.0%), check_dkim_signature: 0.49 (0.2%), check_dkim_adsp: 2.5 (0.8%), poll_dns_idle: 0.63 (0.2%), tests_pri_10: 2.0 (0.7%), tests_pri_500: 6 (2.1%), rewrite_mail: 0.00 (0.0%) Subject: Re: [PATCHv2] exec: Fix a deadlock in ptrace 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 in02.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: > On 3/2/20 4:57 PM, Eric W. Biederman wrote: >> Bernd Edlinger writes: >> >>> >>> I tried this with s/EACCESS/EACCES/. >>> >>> The test case in this patch is not fixed, but strace does not freeze, >>> at least with my setup where it did freeze repeatable. >> >> Thanks, That is what I was aiming at. >> >> So we have one method we can pursue to fix this in practice. >> >>> That is >>> obviously because it bypasses the cred_guard_mutex. But all other >>> process that access this file still freeze, and cannot be >>> interrupted except with kill -9. >>> >>> However that smells like a denial of service, that this >>> simple test case which can be executed by guest, creates a /proc/$pid/mem >>> that freezes any process, even root, when it looks at it. >>> I mean: "ln -s README /proc/$pid/mem" would be a nice bomb. >> >> Yes. Your the test case in your patch a variant of the original >> problem. >> >> >> I have been staring at this trying to understand the fundamentals of the >> original deeper problem. >> >> The current scope of cred_guard_mutex in exec is because being ptraced >> causes suid exec to act differently. So we need to know early if we are >> ptraced. >> > > It has a second use, that it prevents two threads entering execve, > which would probably result in disaster. Exec can fail with an error code up until de_thread. de_thread causes exec to fail with the error code -EAGAIN for the second thread to get into de_thread. So no. The cred_guard_mutex is not needed for that case at all. >> If that case did not exist we could reduce the scope of the >> cred_guard_mutex in exec to where your patch puts the cred_change_mutex. >> >> I am starting to think reworking how we deal with ptrace and exec is the >> way to solve this problem. I am 99% convinced that the fix is to move cred_guard_mutex down. 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. Eric