Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp6475582imu; Sun, 2 Dec 2018 19:21:17 -0800 (PST) X-Google-Smtp-Source: AFSGD/XloonePsqYhhC5RrSnoePe7PECfzpzTkxurXyxGqZGKMoXrMrqRaDGRFLT2IPE4wiq8W37 X-Received: by 2002:a62:e704:: with SMTP id s4mr14491665pfh.124.1543807277797; Sun, 02 Dec 2018 19:21:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543807277; cv=none; d=google.com; s=arc-20160816; b=fdAwZYtNbKjzSYea+PDqQUsJCweRWNWFJ4wiTbn3OIRFLX63ZWfsr2aMjafno63KVI KNsQw3lmuGo/t/oB0I0HPTMw0D/cDsF/1c2dfiOSMjUZwhP3HjZpNBAW2nfwAxq+EZA3 pGyw3KBnqJziyUDc5G93Ufx2jXjhPzq/tNQz4CeyTZYYY/j4NhvHesmpiC4u31V0MVF2 sFQrp4OiDyuzkxlWfn359DQuwxheUiOCC4g5Xne90shdO3VtN6l1hNmYhNIJVmxt9v8j NWrsKUiNAGYQ2MWxFi2nZYcEv7Th1AxR8WwtDRkXlAr8l8AuyutzWMzCSjslSrm9GMjb xk5w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date; bh=pXlh290lUQanez3P/qICD9v9lTDVk1WckyCpL7NCb4E=; b=NfBQTBLKTV5HjlGBoSEA7K8ZdROlGhhyJFuIK8gaHZ8FUoN/4tRvpBkent+f9A004M Ka7ykncpzPaolsUzqYyvCyKNXkZoPY032IPtJYqInCqy9igKIfxrddvsTl4jrk5U8H4O gPfUtU4yvXVvnvSSXRF+EPGZfUqS1/abcogtiZJBB814umKTVxVP2zcS2TQLXc2Srsxd 5dwn7fLMhY/15HxcJ0/9I4Aj/TvXrQsP81izVCyU3oMIQ6KJz18p5F+jK8IPupKl97ps WG0u67IdIHKZFmjzBqhRlcfF9l8czXYXj/rS5rDx1EHgiMGKM95lOidcGWuLzMQyY67J ndJw== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w2si12117813pfg.78.2018.12.02.19.21.03; Sun, 02 Dec 2018 19:21:17 -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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725973AbeLCDS1 (ORCPT + 99 others); Sun, 2 Dec 2018 22:18:27 -0500 Received: from vmicros1.altlinux.org ([194.107.17.57]:52920 "EHLO vmicros1.altlinux.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725803AbeLCDS0 (ORCPT ); Sun, 2 Dec 2018 22:18:26 -0500 Received: from mua.local.altlinux.org (mua.local.altlinux.org [192.168.1.14]) by vmicros1.altlinux.org (Postfix) with ESMTP id 1509972CA65; Mon, 3 Dec 2018 06:18:24 +0300 (MSK) Received: by mua.local.altlinux.org (Postfix, from userid 508) id 0C7467CCEA3; Mon, 3 Dec 2018 06:18:23 +0300 (MSK) Date: Mon, 3 Dec 2018 06:18:23 +0300 From: "Dmitry V. Levin" To: Michael Ellerman Cc: Benjamin Herrenschmidt , Paul Mackerras , Oleg Nesterov , Breno Leitao , Andy Lutomirski , Eugene Syromyatnikov , Elvira Khabirova , linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org Subject: [PATCH v4] powerpc/ptrace: replace ptrace_report_syscall() with a tracehook call Message-ID: <20181203031823.GE11573@altlinux.org> References: <20181116121701.14359da0@akathisia> <87ftw12nyn.fsf@concordia.ellerman.id.au> <20181119210139.GA8360@altlinux.org> <87efbe166y.fsf@concordia.ellerman.id.au> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <87efbe166y.fsf@concordia.ellerman.id.au> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Elvira Khabirova Arch code should use tracehook_*() helpers, as documented in include/linux/tracehook.h, ptrace_report_syscall() is not expected to be used outside that file. Co-authored-by: Dmitry V. Levin Fixes: 5521eb4bca2d ("powerpc/ptrace: Add support for PTRACE_SYSEMU") Signed-off-by: Elvira Khabirova Signed-off-by: Dmitry V. Levin --- v4: rewritten to call tracehook_report_syscall_entry() once, compile-tested v3: add a descriptive comment v2: explicitly ignore tracehook_report_syscall_entry() return code arch/powerpc/kernel/ptrace.c | 54 +++++++++++++++++++++++------------- 1 file changed, 35 insertions(+), 19 deletions(-) diff --git a/arch/powerpc/kernel/ptrace.c b/arch/powerpc/kernel/ptrace.c index afb819f4ca68..59c8c9a3d7ea 100644 --- a/arch/powerpc/kernel/ptrace.c +++ b/arch/powerpc/kernel/ptrace.c @@ -3263,27 +3263,43 @@ static inline int do_seccomp(struct pt_regs *regs) { return 0; } */ long do_syscall_trace_enter(struct pt_regs *regs) { + struct thread_info *ti; + u32 cached_flags; + user_exit(); - if (test_thread_flag(TIF_SYSCALL_EMU)) { - ptrace_report_syscall(regs); - /* - * Returning -1 will skip the syscall execution. We want to - * avoid clobbering any register also, thus, not 'gotoing' - * skip label. - */ - return -1; - } + ti = current_thread_info(); + cached_flags = + READ_ONCE(ti->flags) & + (TIF_SYSCALL_EMU | TIF_SYSCALL_TRACE | TIF_SYSCALL_TRACEPOINT); - /* - * The tracer may decide to abort the syscall, if so tracehook - * will return !0. Note that the tracer may also just change - * regs->gpr[0] to an invalid syscall number, that is handled - * below on the exit path. - */ - if (test_thread_flag(TIF_SYSCALL_TRACE) && - tracehook_report_syscall_entry(regs)) - goto skip; + if (cached_flags & (TIF_SYSCALL_EMU | TIF_SYSCALL_TRACE)) { + int rc = tracehook_report_syscall_entry(regs); + + if (unlikely(cached_flags & _TIF_SYSCALL_EMU)) { + /* + * A nonzero return code from + * tracehook_report_syscall_entry() tells us + * to prevent the syscall execution, but + * we are not going to execute it anyway. + * + * Returning -1 will skip the syscall execution. + * We want to avoid clobbering any register also, + * thus, not 'gotoing' skip label. + */ + return -1; + } + + if (rc) { + /* + * The tracer decided to abort the syscall. + * Note that the tracer may also just change + * regs->gpr[0] to an invalid syscall number, + * that is handled below on the exit path. + */ + goto skip; + } + } /* Run seccomp after ptrace; allow it to set gpr[3]. */ if (do_seccomp(regs)) @@ -3293,7 +3309,7 @@ long do_syscall_trace_enter(struct pt_regs *regs) if (regs->gpr[0] >= NR_syscalls) goto skip; - if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT))) + if (unlikely(cached_flags & TIF_SYSCALL_TRACEPOINT)) trace_sys_enter(regs, regs->gpr[0]); #ifdef CONFIG_PPC64 -- ldv