Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp2070680ybb; Thu, 9 Apr 2020 14:37:35 -0700 (PDT) X-Google-Smtp-Source: APiQypL6zdJzw3YoQ5KsMgpmlXYlxecIfYu1nE/mpvGm5t2A8hggq14CgJeyj2rxCtCd1wig35Zi X-Received: by 2002:a37:e312:: with SMTP id y18mr979457qki.243.1586468255179; Thu, 09 Apr 2020 14:37:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1586468255; cv=none; d=google.com; s=arc-20160816; b=0vQS95NG3IC4zHTzlxiGf+mq3uZ2YK+dG02zFf32oxwLXTYt63EilKPNCUZvD7WXXb +gMBNwddCQw6YTV/VqiP5DsaYvD3mrH0iJKFduj5zRv5HdqEYbdq8WyOrYdFD7jySSf/ C+IajwmDZjUClA6uR5ePQLtmHVpJUrSBfbUS8ggAsV2eamFVqTuN2LDrJ8rU2A0mzxPE zh5Y1iE1Dd0WU3s6Gp0TvXNuZsywZrpOLQGsAFWidbwu1zQgYd26f/imJLmsOwama6zM vsmegcNoSkJh2Xp0dI51hYctD0J3el5SPdCbCQCAQnH/HoqWtLsjZEcSAE3uafITY7OA kLNQ== 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=xM4Y8HTOzOpgj4opcaHUZghC2mvGwMArlY4N/gk5nFg=; b=HcpPZwaZRykd3tSLaQshI4MgXoM+iY6uSs9PnPPfLrixhE1kuKaqXqvQQRZhTYBYA7 BVaKmYbVSaQxaEThH6taA7qtYh1zccLEPC9gp/HFL13fCV5tbK+7Jsc4ZoMOkIyEcRfZ +KeF0cZC4NLNMODR3FQMWJfBbIen6uhNOjj1tsMkVhd64j11lvvG29e+T9lKqtYQLVoJ /aoa4//pe46UochPl78YdvD7qR2pJe5u1Qb4eqUdIWvIZgaH847he/KV+R6SSDcDRK7j kznXX8jLfi3kcJEOyT3n6gfY+C+UKVdPpO4natj1TqyF+K8PsRZr4N7uvcZab35ZUHEw uztg== 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 x127si175082qke.107.2020.04.09.14.37.20; Thu, 09 Apr 2020 14:37:35 -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 S1726722AbgDIUhU (ORCPT + 99 others); Thu, 9 Apr 2020 16:37:20 -0400 Received: from out02.mta.xmission.com ([166.70.13.232]:43562 "EHLO out02.mta.xmission.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726623AbgDIUhT (ORCPT ); Thu, 9 Apr 2020 16:37:19 -0400 Received: from in01.mta.xmission.com ([166.70.13.51]) by out02.mta.xmission.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jMdvL-0000zI-2f; Thu, 09 Apr 2020 14:37:19 -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 1jMdvJ-0000eF-Ex; Thu, 09 Apr 2020 14:37:18 -0600 From: ebiederm@xmission.com (Eric W. Biederman) To: Linus Torvalds Cc: Waiman Long , Ingo Molnar , Will Deacon , Bernd Edlinger , Linux Kernel Mailing List , Alexey Gladkov , Oleg Nesterov References: <87blobnq02.fsf@x220.int.ebiederm.org> <87lfnda3w3.fsf@x220.int.ebiederm.org> <87blo45keg.fsf@x220.int.ebiederm.org> <87v9maxb5q.fsf@x220.int.ebiederm.org> <87y2r4so3i.fsf@x220.int.ebiederm.org> <87wo6or3pg.fsf@x220.int.ebiederm.org> Date: Thu, 09 Apr 2020 15:34:26 -0500 In-Reply-To: (Linus Torvalds's message of "Thu, 9 Apr 2020 10:36:07 -0700") Message-ID: <871rowpfe5.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=1jMdvJ-0000eF-Ex;;;mid=<871rowpfe5.fsf@x220.int.ebiederm.org>;;;hst=in01.mta.xmission.com;;;ip=68.227.160.95;;;frm=ebiederm@xmission.com;;;spf=neutral X-XM-AID: U2FsdGVkX19CX5i1Ts7PoEZRURbKkjhzAXkFSUrt6Gk= 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 sa07.xmission.com X-Spam-Level: ** X-Spam-Status: No, score=2.1 required=8.0 tests=ALL_TRUSTED,BAYES_50, DCC_CHECK_NEGATIVE,T_TM2_M_HEADER_IN_MSG,T_TooManySym_01, XMSubMetaSxObfu_03,XMSubMetaSx_00 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.4990] * 0.0 T_TM2_M_HEADER_IN_MSG BODY: No description available. * -0.0 DCC_CHECK_NEGATIVE Not listed in DCC * [sa07 1397; Body=1 Fuz1=1 Fuz2=1] * 1.0 XMSubMetaSx_00 1+ Sexy Words * 1.2 XMSubMetaSxObfu_03 Obfuscated Sexy Noun-People * 0.0 T_TooManySym_01 4+ unique symbols in subject X-Spam-DCC: XMission; sa07 1397; Body=1 Fuz1=1 Fuz2=1 X-Spam-Combo: **;Linus Torvalds X-Spam-Relay-Country: X-Spam-Timing: total 788 ms - load_scoreonly_sql: 0.05 (0.0%), signal_user_changed: 9 (1.2%), b_tie_ro: 8 (1.0%), parse: 1.05 (0.1%), extract_message_metadata: 15 (1.9%), get_uri_detail_list: 1.82 (0.2%), tests_pri_-1000: 23 (3.0%), tests_pri_-950: 1.24 (0.2%), tests_pri_-900: 0.98 (0.1%), tests_pri_-90: 67 (8.5%), check_bayes: 65 (8.3%), b_tokenize: 7 (0.9%), b_tok_get_all: 8 (1.0%), b_comp_prob: 2.3 (0.3%), b_tok_touch_all: 44 (5.6%), b_finish: 0.91 (0.1%), tests_pri_0: 658 (83.5%), check_dkim_signature: 0.86 (0.1%), check_dkim_adsp: 2.8 (0.4%), poll_dns_idle: 0.74 (0.1%), tests_pri_10: 2.3 (0.3%), tests_pri_500: 7 (0.9%), rewrite_mail: 0.00 (0.0%) Subject: Re: [GIT PULL] Please pull proc and exec work for 5.7-rc1 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 Linus Torvalds writes: > On Thu, Apr 9, 2020 at 10:06 AM Eric W. Biederman wrote: >> >> a) We must stop in PTRACE_EVENT_EXIT during exec or userspace *breaks*. >> >> Those are the defined semantics and I believe it is something >> as common as strace that depends on them. > > Don't be silly. > > Of course we must stop IF THE TRACER IS ACTUALLY TRACING US. > > But that's simply not the case. The deadlock case is where the tracer > is going through an execve, and the tracing thread is being killed. Linus please don't be daft. I will agree that if one thread in a process ptracess another thread in the same process, and the tracing thread calls execve we have a problem. A different problem but one worth addressing. The deadlock case I am talking about. The deadlock case that trivially exists in real code is: A single threaded process (the tracer) ptrace attaches to every thread of a multi-threaded process (the tracee). If one of these attaches succeeds, and another thread of the tracee processes calls execve before the tracer attachs to it, then the tracer blocks in ptrace_attach waitiing for the traccee's exeve to succeed while the tracee blocks in de_thread waiting for it's other threads to exit. The threads of the tracee attempt to exit but one or more of them are in PTRACE_EVENT_EXIT waiting for the tracer to let them continue. The tracer of course is stalled waiting for the exec to succeed. Let me see if I can draw a picture. Tracer TraceeThreadA TraceeThreadB ptrace_attach(TraceeThreadA) execve acquires cred_guard_mutex ptrace_attach(TraceeThreadB) Blocks on cred_guard_mutex de_thread waits for other threads to exit Receives SIGKILL do_exit() PTRACE_EVENT_EXIT Waits for tracer So we have a loop. TraceeThreadB is waiting for TraceeThreadA to reach exit_noitfy. TraceeThreadA is waiting for the tracer to allow it to continue. The Tracer is waiting for TraceeThreadB to finish it's call to exec. Since they are all waiting for each other that loop is a deadlock. All it takes is a tracer that uses PTRACE_EVENT_EXIT. Does that make the deadlock that I see clear? In your proposed lock revision you were talking about ptrace_attach taking your new the lock for write so I don't see your proposed lock being any different in this scenario from cred_guard_mutex. Perhaps I missed something? I know Oleg's test case was a little more involved but that was to guarantee the timing perhaps that introduced confusion. Eric