From patchwork Wed May 18 22:53:54 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Eric W. Biederman" X-Patchwork-Id: 1633001 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=BjOBclr+; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:e::133; helo=bombadil.infradead.org; envelope-from=linux-um-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4L3Sxx2cKGz9vDx for ; Thu, 19 May 2022 08:55:33 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Subject:MIME-Version:References: In-Reply-To:Message-Id:Date:Cc:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=KiWVr+qM5KX0htPKX/i+U01kxRPDz1rgsgS1vZoDGdw=; b=BjOBclr+h663R8qLjmmVzxaujA K2rylGJbQ+S5U77X4IeKLhwkD9nHeC1S0lwZr/QttL+6c71K2vEScnGuMqMwxV2OyEc+8HzNK6gal lp5fLdp1MgQQdEDBCBQojuewZiOfHg8vMs0D2XYIC8JmQQOmDj3IwVWfEvobYrFKkJ41Vq6R7peEz p1AUtiKM0n8lVuEtfZddPcLTeJfpt5NakJmu2YOX+zmji57uY07MNG8hZimM6bMm2Tx/dyhtZ8U03 0lsvmnEJWANCOH2UtgQsc2P79/IL+3M+/wj/RWpLqHvLvViWT4v1yCy3ooEBHZDEsWPbqkzlCL6d1 PIC5asQQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nrSZi-004CKK-3T; Wed, 18 May 2022 22:55:26 +0000 Received: from out03.mta.xmission.com ([166.70.13.233]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nrSZe-004CI4-RN for linux-um@lists.infradead.org; Wed, 18 May 2022 22:55:24 +0000 Received: from in01.mta.xmission.com ([166.70.13.51]:33438) by out03.mta.xmission.com with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.93) (envelope-from ) id 1nrSZd-00Ckcv-Nn; Wed, 18 May 2022 16:55:21 -0600 Received: from ip68-227-174-4.om.om.cox.net ([68.227.174.4]:38724 helo=localhost.localdomain) by in01.mta.xmission.com with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.93) (envelope-from ) id 1nrSZc-002Z0O-KW; Wed, 18 May 2022 16:55:21 -0600 From: "Eric W. Biederman" To: linux-kernel@vger.kernel.org Cc: rjw@rjwysocki.net, Oleg Nesterov , mingo@kernel.org, vincent.guittot@linaro.org, dietmar.eggemann@arm.com, rostedt@goodmis.org, mgorman@suse.de, bigeasy@linutronix.de, Will Deacon , tj@kernel.org, linux-pm@vger.kernel.org, Peter Zijlstra , Richard Weinberger , Anton Ivanov , Johannes Berg , linux-um@lists.infradead.org, Chris Zankel , Max Filippov , linux-xtensa@linux-xtensa.org, Kees Cook , Jann Horn , linux-ia64@vger.kernel.org, Robert OCallahan , Kyle Huey , Richard Henderson , Ivan Kokshaysky , Matt Turner , Jason Wessel , Daniel Thompson , Douglas Anderson , Douglas Miller , Michael Ellerman , Benjamin Herrenschmidt , Paul Mackerras , "Eric W. Biederman" Date: Wed, 18 May 2022 17:53:54 -0500 Message-Id: <20220518225355.784371-15-ebiederm@xmission.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <871qwq5ucx.fsf_-_@email.froward.int.ebiederm.org> References: <871qwq5ucx.fsf_-_@email.froward.int.ebiederm.org> MIME-Version: 1.0 X-XM-SPF: eid=1nrSZc-002Z0O-KW; ; ; mid=<20220518225355.784371-15-ebiederm@xmission.com>; ; ; hst=in01.mta.xmission.com; ; ; ip=68.227.174.4; ; ; frm=ebiederm@xmission.com; ; ; spf=softfail X-XM-AID: U2FsdGVkX19BX42rXAmEdeldIBaC1nvKtXoRgWt4/eg= X-SA-Exim-Connect-IP: 68.227.174.4 X-SA-Exim-Mail-From: ebiederm@xmission.com X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on sa04.xmission.com X-Spam-Level: ***** X-Spam-Status: No, score=5.5 required=8.0 tests=ALL_TRUSTED,BAYES_50, DCC_CHECK_NEGATIVE,T_TooManySym_01,XMNoVowels,XMSubLong, XM_Body_Dirty_Words,XM_SPF_SoftFail 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 DCC_CHECK_NEGATIVE Not listed in DCC * [sa04 1397; Body=1 Fuz1=1 Fuz2=1] * 0.0 T_TooManySym_01 4+ unique symbols in subject * 2.5 XM_SPF_SoftFail SPF-SoftFail * 1.0 XM_Body_Dirty_Words Contains a dirty word X-Spam-DCC: XMission; sa04 1397; Body=1 Fuz1=1 Fuz2=1 X-Spam-Combo: *****;linux-kernel@vger.kernel.org X-Spam-Relay-Country: X-Spam-Timing: total 473 ms - load_scoreonly_sql: 0.10 (0.0%), signal_user_changed: 14 (3.0%), b_tie_ro: 12 (2.5%), parse: 2.0 (0.4%), extract_message_metadata: 19 (4.0%), get_uri_detail_list: 2.4 (0.5%), tests_pri_-1000: 23 (4.8%), tests_pri_-950: 1.71 (0.4%), tests_pri_-900: 1.47 (0.3%), tests_pri_-90: 64 (13.5%), check_bayes: 62 (13.1%), b_tokenize: 13 (2.7%), b_tok_get_all: 8 (1.6%), b_comp_prob: 3.2 (0.7%), b_tok_touch_all: 35 (7.4%), b_finish: 0.87 (0.2%), tests_pri_0: 321 (67.8%), check_dkim_signature: 0.97 (0.2%), check_dkim_adsp: 3.5 (0.7%), poll_dns_idle: 0.92 (0.2%), tests_pri_10: 2.2 (0.5%), tests_pri_500: 20 (4.2%), rewrite_mail: 0.00 (0.0%) Subject: [PATCH 15/16] ptrace: Use siglock instead of tasklist_lock in ptrace_check_attach X-SA-Exim-Version: 4.2.1 (built Sat, 08 Feb 2020 21:53:50 +0000) X-SA-Exim-Scanned: Yes (on in01.mta.xmission.com) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220518_155522_947264_5695BD40 X-CRM114-Status: GOOD ( 13.64 ) X-Spam-Score: -0.7 (/) X-Spam-Report: Spam detection software, running on the system "bombadil.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: Now that siglock protects tsk->parent and tsk->ptrace there is no need to grab tasklist_lock in ptrace_check_attach. The siglock can handle all of the locking needs of ptrace_check_attach. Signed-off-by: "Eric W. Biederman" --- kernel/ptrace.c | 23 +++++++++ 1 file changed, 9 insertions(+), 14 deletions(-) Content analysis details: (-0.7 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at https://www.dnswl.org/, low trust [166.70.13.233 listed in list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record X-BeenThere: linux-um@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-um" Errors-To: linux-um-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org Now that siglock protects tsk->parent and tsk->ptrace there is no need to grab tasklist_lock in ptrace_check_attach. The siglock can handle all of the locking needs of ptrace_check_attach. Signed-off-by: "Eric W. Biederman" --- kernel/ptrace.c | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/kernel/ptrace.c b/kernel/ptrace.c index 77dfdb3d1ced..fa65841bbdbe 100644 --- a/kernel/ptrace.c +++ b/kernel/ptrace.c @@ -194,17 +194,14 @@ static bool ptrace_freeze_traced(struct task_struct *task) { bool ret = false; - /* Lockless, nobody but us can set this flag */ if (task->jobctl & JOBCTL_LISTENING) return ret; - spin_lock_irq(&task->sighand->siglock); if (task_is_traced(task) && !looks_like_a_spurious_pid(task) && !__fatal_signal_pending(task)) { task->jobctl |= JOBCTL_PTRACE_FROZEN; ret = true; } - spin_unlock_irq(&task->sighand->siglock); return ret; } @@ -240,32 +237,30 @@ static void ptrace_unfreeze_traced(struct task_struct *task) * state. * * CONTEXT: - * Grabs and releases tasklist_lock and @child->sighand->siglock. + * Grabs and releases @child->sighand->siglock. * * RETURNS: * 0 on success, -ESRCH if %child is not ready. */ static int ptrace_check_attach(struct task_struct *child, bool ignore_state) { + unsigned long flags; int ret = -ESRCH; /* - * We take the read lock around doing both checks to close a + * We take the siglock around doing both checks to close a * possible race where someone else was tracing our child and * detached between these two checks. After this locked check, * we are sure that this is our traced child and that can only * be changed by us so it's not changing right after this. */ - read_lock(&tasklist_lock); - if (child->ptrace && child->parent == current) { - /* - * child->sighand can't be NULL, release_task() - * does ptrace_unlink() before __exit_signal(). - */ - if (ignore_state || ptrace_freeze_traced(child)) - ret = 0; + if (lock_task_sighand(child, &flags)) { + if (child->ptrace && child->parent == current) { + if (ignore_state || ptrace_freeze_traced(child)) + ret = 0; + } + unlock_task_sighand(child, &flags); } - read_unlock(&tasklist_lock); if (!ret && !ignore_state && WARN_ON_ONCE(!wait_task_inactive(child, __TASK_TRACED)))