Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp1687040pxb; Fri, 27 Aug 2021 15:09:23 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwLknICqxEzAe78vWdH+Da1MQUFmbwFsfIXwYewUkijiP/adzTwa6yLPANnFS/VNY70oh/x X-Received: by 2002:a05:6402:cb1:: with SMTP id cn17mr7157800edb.388.1630102163768; Fri, 27 Aug 2021 15:09:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1630102163; cv=none; d=google.com; s=arc-20160816; b=QyawjNnEg5bHBtT2pjsVvDATtSfrjRgUQU5qB+h4ZkvzE9a9dSXWlkxsApEawmBkZ0 BwzioitzLwSIU9eNwhCP9XViQ0HWDtV9OIKsOWf642hR/zYKeV/XdnTtfQTKDYvnQOvi AOzmSQqcpWjO8wlqArRurU4ygTNY4jd9CyRIQoqSe5MrmMji9/PWmhxgXntwpJ6FGJfU j2vs4rf7AixZV48jSPVtNGseSxf2dC5Y5M3bu8ROEA9WQUDjwAuhsWnbSvk2a7Y7oEA+ sOGeAA3WoK08z8nMCYLt3eAyFceR7g7GN9YsWM0vvQ6rl6KOExpWQ2WsFLjD/9hsQH8I g4zw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:subject:mime-version:user-agent:message-id :in-reply-to:date:references:cc:to:from; bh=q5tZadOCuqDMo4P1ZeAxTCeUf7SqVW7UjLn9njAnixc=; b=cDrS0TOeTOsADXJq1+XEghwEEr1RPv+EiovshMNs3Bz8leL74yJaceXZdcjroK/NZ8 4PqiDh9C6G0xka7J4ymcJTlW3NM5b9Z5k1E+oEQ6HJNhgSmoIkWbQ0yy5ztUGG8FwuuH EnQAuF1XVqLB23rf5Zvsmt24Y1hwrsRz4VFDRRhUaBQi+VeNQT20NNuJ1j6DKRAicJ0i 84a+AMSV3/s8v1OmdF/SFJBZ78jt9vUKPCJaDCD4ywlp04Na9HxmHiS97iUlQxLcnAlF hHPhyKbFusmrWznggMLygYbK9gRyucTNz2IvZzfrC56oEWnbuWEVjq+g8ZaP7BVm3Q4M sXPA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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. [23.128.96.18]) by mx.google.com with ESMTP id 2si7500271ejh.749.2021.08.27.15.08.50; Fri, 27 Aug 2021 15:09:23 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S232101AbhH0WH3 (ORCPT + 99 others); Fri, 27 Aug 2021 18:07:29 -0400 Received: from out01.mta.xmission.com ([166.70.13.231]:38236 "EHLO out01.mta.xmission.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231906AbhH0WH3 (ORCPT ); Fri, 27 Aug 2021 18:07:29 -0400 Received: from in02.mta.xmission.com ([166.70.13.52]:40080) by out01.mta.xmission.com with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.93) (envelope-from ) id 1mJjzi-002cBF-Ue; Fri, 27 Aug 2021 16:06:38 -0600 Received: from ip68-227-160-95.om.om.cox.net ([68.227.160.95]:36032 helo=email.xmission.com) by in02.mta.xmission.com with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.93) (envelope-from ) id 1mJjzg-00FMrf-W8; Fri, 27 Aug 2021 16:06:38 -0600 From: ebiederm@xmission.com (Eric W. Biederman) To: Linus Torvalds Cc: Al Viro , Oleg Nesterov , Linux Kernel Mailing List References: <877dgkvsog.fsf@disp2133> Date: Fri, 27 Aug 2021 17:05:57 -0500 In-Reply-To: (Linus Torvalds's message of "Fri, 27 Aug 2021 11:54:57 -0700") Message-ID: <87r1eea6gq.fsf@disp2133> 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=1mJjzg-00FMrf-W8;;;mid=<87r1eea6gq.fsf@disp2133>;;;hst=in02.mta.xmission.com;;;ip=68.227.160.95;;;frm=ebiederm@xmission.com;;;spf=neutral X-XM-AID: U2FsdGVkX18zLpVFkSgbwCuxPI+BbycUB16I3x4a0Xk= 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,TR_Symld_Words,TR_XM_Base64_M1, T_TM2_M_HEADER_IN_MSG,XM_B_SpammyWords 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.4991] * 1.5 TR_Symld_Words too many words that have symbols inside * 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.2 XM_B_SpammyWords One or more commonly used spammy words * 0.5 TR_XM_Base64_M1 Base64 Encoded Content with common spam flags X-Spam-DCC: XMission; sa05 1397; Body=1 Fuz1=1 Fuz2=1 X-Spam-Combo: **;Linus Torvalds X-Spam-Relay-Country: X-Spam-Timing: total 1380 ms - load_scoreonly_sql: 0.07 (0.0%), signal_user_changed: 11 (0.8%), b_tie_ro: 9 (0.7%), parse: 0.84 (0.1%), extract_message_metadata: 13 (1.0%), get_uri_detail_list: 1.82 (0.1%), tests_pri_-1000: 9 (0.7%), tests_pri_-950: 1.10 (0.1%), tests_pri_-900: 0.88 (0.1%), tests_pri_-90: 84 (6.1%), check_bayes: 83 (6.0%), b_tokenize: 7 (0.5%), b_tok_get_all: 8 (0.6%), b_comp_prob: 2.4 (0.2%), b_tok_touch_all: 62 (4.5%), b_finish: 0.88 (0.1%), tests_pri_0: 1241 (89.9%), check_dkim_signature: 0.49 (0.0%), check_dkim_adsp: 2.5 (0.2%), poll_dns_idle: 1.14 (0.1%), tests_pri_10: 4.0 (0.3%), tests_pri_500: 11 (0.8%), rewrite_mail: 0.00 (0.0%) Subject: Re: [PATCH][RFC] fix PTRACE_KILL X-SA-Exim-Version: 4.2.1 (built Sat, 08 Feb 2020 21:53:50 +0000) X-SA-Exim-Scanned: Yes (on in02.mta.xmission.com) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Linus Torvalds writes: > [ Sorry, this got missed by other stuff in my inbox ] > > On Tue, Aug 24, 2021 at 10:12 PM Al Viro wrote: >> >> The change I'd proposed makes PTRACE_KILL deliver SIGKILL regardless of >> the target state; yours is arguably what we should've done from the very >> beginning (what we used to have prior to 0.99pl14 and what all other >> Unices had been doing all along), but it's a visible change wrt error >> returns and I don't see any sane way to paper over that part. >> >> Linus, what would you prefer? I've no strong preferences here... > > Honestly, I have no huge preferences either, simply because this has > clearly been broken so long that people who care have worked around > the breakage already, or it just didn't matter enough. The two choices are change PTRACE_KILL into: "kill(SIGKILL)" or "ptrace(PTRACE_CONT, SIGKILL)". When trying to figure out how userspace understands PTRACE_KILL today, I have found at least one piece of userspace that figures the definition of PTRACE_KILL is PTRACE_CONT with the signal SIGKILL. Frankly I find that a fair characterization, because except for the return code when the task is not stopped PTRACE_KILL works exactly like PTRACE_CONT with signal SIGKILL. As there are real userspace visible differences between PTRACE_CONT and kill(SIGKILL) I think we should go with the PTRACE_CONT definition as that is the least likely to break userspace, and the only thing we really care about here is making it so that malicious userspace can not cause the kernel to misbehave. > I don't think Eric's patch works, because if I read that one right, it > would actually do that "wait_task_inactive()" which is very much > against the whole point of PTRACE_KILL. We want to kill the target > asap, and regardless of where it is stuck. It will do wait_task_inactive in one of the cases where PTRACE_KILL is broken today. But since the cost of a wait_task_inactive looks very much like the cost of a spin_lock I don't see the problem. The code in ptrace_check_attach already waits on several other spin locks. The code in ptrace_attach verifies that the target task in in state TASK_TRACED. Which means that the target task is in ptrace_stop and has already done "set_special_state(TASK_TRACED)". At that point there are two possibilities. Either the target task will have reached freezable_schedule in ptrace_stop and wait_task_inactive won't block at all, or wait_task_inactive will need to spin waiting for the target task to reach freezable_schedule. There is nothing in ptrace_stop that can sleep as all of the work happens under a spin lock so the worst case wait in wait_task_inactive should be quite short. All of that said it is probably worth adding to my patch the logic so that when ptrace_freeze_traced fails or wait_task_inactive fails the code bails out immediately and returns 0 instead of -ESRCH. Just to avoid any userspace behavioral differences in PTRACE_KILL. So we don't even need to consider regressions. Eric