From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 1nrSZ6-004Bta-OF for linux-um@lists.infradead.org; Wed, 18 May 2022 22:54:50 +0000 From: "Eric W. Biederman" Date: Wed, 18 May 2022 17:53:45 -0500 Message-Id: <20220518225355.784371-6-ebiederm@xmission.com> In-Reply-To: <871qwq5ucx.fsf_-_@email.froward.int.ebiederm.org> References: <871qwq5ucx.fsf_-_@email.froward.int.ebiederm.org> MIME-Version: 1.0 Subject: [PATCH 06/16] ptrace: Remove unnecessary locking in ptrace_(get|set)siginfo List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-um" Errors-To: linux-um-bounces+geert=linux-m68k.org@lists.infradead.org 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" Since commit 9899d11f6544 ("ptrace: ensure arch_ptrace/ptrace_request can never race with SIGKILL") it has been unnecessary for ptrace_getsiginfo and ptrace_setsiginfo to use lock_task_sighand. Having the code taking an unnecessary lock is confusing as it suggests that other parts of the code need to take the unnecessary lock as well. So remove the unnecessary lock to make the code more efficient, simpler, and less confusing. Signed-off-by: "Eric W. Biederman" --- kernel/ptrace.c | 30 ++++++++---------------------- 1 file changed, 8 insertions(+), 22 deletions(-) diff --git a/kernel/ptrace.c b/kernel/ptrace.c index ca0e47691229..15e93eafa6f0 100644 --- a/kernel/ptrace.c +++ b/kernel/ptrace.c @@ -677,34 +677,20 @@ static int ptrace_setoptions(struct task_struct *child, unsigned long data) static int ptrace_getsiginfo(struct task_struct *child, kernel_siginfo_t *info) { - unsigned long flags; - int error = -ESRCH; + if (unlikely(!child->last_siginfo)) + return -EINVAL; - if (lock_task_sighand(child, &flags)) { - error = -EINVAL; - if (likely(child->last_siginfo != NULL)) { - copy_siginfo(info, child->last_siginfo); - error = 0; - } - unlock_task_sighand(child, &flags); - } - return error; + copy_siginfo(info, child->last_siginfo); + return 0; } static int ptrace_setsiginfo(struct task_struct *child, const kernel_siginfo_t *info) { - unsigned long flags; - int error = -ESRCH; + if (unlikely(!child->last_siginfo)) + return -EINVAL; - if (lock_task_sighand(child, &flags)) { - error = -EINVAL; - if (likely(child->last_siginfo != NULL)) { - copy_siginfo(child->last_siginfo, info); - error = 0; - } - unlock_task_sighand(child, &flags); - } - return error; + copy_siginfo(child->last_siginfo, info); + return 0; } static int ptrace_peek_siginfo(struct task_struct *child, -- 2.35.3 _______________________________________________ linux-um mailing list linux-um@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-um