Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp915201imu; Fri, 7 Dec 2018 10:54:27 -0800 (PST) X-Google-Smtp-Source: AFSGD/Xyufh6obEdJJvrVULozT0bmUbIQ4elfJ1i1FKEq/mJ8HSFLeJNs3+lP/wSCLRcMenrdVbb X-Received: by 2002:a63:1258:: with SMTP id 24mr2921412pgs.114.1544208867737; Fri, 07 Dec 2018 10:54:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544208867; cv=none; d=google.com; s=arc-20160816; b=Lm0JLiv/nD4hAD0RAGQ68N9Amr6sk++hfuYxFzbSIQtKNIm888agZRzlSyp/Y9uo4H m6uoZ5ARwPlFccPJozPaQfwxC9UGH6M23Yt7+WgKKyIZmYReyF0TYmNWV0y4d/IO2VkQ dP+kWSjTKuhhLezWB0LsoSMYZneLDILfAdyutywrzFzfWfCadnnPw+6Jr+Hj5B0GaP0z DT+gdgOVly8b7Wk2bSpHAZlNI1oLfd/U5HEBPk1IX/FtSrClQf9Pdta5/dQ/IeQdeUAA J9bcrKtTBAksxaoBn6B3GNRQEJQJiK4bBVdEskTa/fEh9x9zJaxoV5CMLEfV2NefvHZ7 lI6g== 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=s9K9JEUkjDOBTeiNXW3AOt7wOsvrUpxmZ5t/lMBrJFw=; b=QdYaEvsi+gfOpoy+/RRIkv/hgWfVKJ8cTGjKkW1bvsZtWWo8Bn1fnSvquwiVid5qic 3PrCttwfJz+wKPYRVQvDbTHbpl3AB9GA8UFyGG5dh0RyYFyuH0VMzK8xSiQR0wxPPfhl Ukwh+vR2x2jJs78FaZCb1iTkvzxWQHSi2NMBLggs0lNfRJHakIc/DXpmo4EHUpdGmSBi WzdE2KMBWsUmPYKL4X1fUhcE/RPzI1cZI9EuFHBC10cnHAd8NXZmBb5bwHLoPh8+1YiC bTKpsRTTAZW67bquYq7hPD1Fz8KpDSQl6lTW9RDZRjCUxN8BzA1NHyzpc7d2J/LIPMHS 1vUA== 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 k22si3439410pll.276.2018.12.07.10.54.12; Fri, 07 Dec 2018 10:54:27 -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 S1726252AbeLGSwa (ORCPT + 99 others); Fri, 7 Dec 2018 13:52:30 -0500 Received: from vmicros1.altlinux.org ([194.107.17.57]:60126 "EHLO vmicros1.altlinux.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726081AbeLGSwa (ORCPT ); Fri, 7 Dec 2018 13:52:30 -0500 Received: from mua.local.altlinux.org (mua.local.altlinux.org [192.168.1.14]) by vmicros1.altlinux.org (Postfix) with ESMTP id D266B72CC59; Fri, 7 Dec 2018 21:52:26 +0300 (MSK) Received: by mua.local.altlinux.org (Postfix, from userid 508) id C6A817CEACC; Fri, 7 Dec 2018 21:52:26 +0300 (MSK) Date: Fri, 7 Dec 2018 21:52:26 +0300 From: "Dmitry V. Levin" To: Michael Ellerman Cc: Elvira Khabirova , Benjamin Herrenschmidt , Paul Mackerras , Oleg Nesterov , Breno Leitao , Andy Lutomirski , Eugene Syromyatnikov , linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org Subject: [PATCH v6] powerpc/ptrace: replace ptrace_report_syscall() with a tracehook call Message-ID: <20181207185226.GB31278@altlinux.org> References: <20181116121701.14359da0@akathisia> <87ftw12nyn.fsf@concordia.ellerman.id.au> <20181119210139.GA8360@altlinux.org> <87efbe166y.fsf@concordia.ellerman.id.au> <20181203031823.GE11573@altlinux.org> <20181207011946.GA18558@altlinux.org> <87y391k2tq.fsf@concordia.ellerman.id.au> <20181207154255.GA28964@altlinux.org> <20181207155605.GB28964@altlinux.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20181207155605.GB28964@altlinux.org> 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") Cc: Michael Ellerman Cc: Benjamin Herrenschmidt Cc: Paul Mackerras Cc: Oleg Nesterov Cc: Breno Leitao Cc: Andy Lutomirski Cc: Eugene Syromyatnikov Cc: linuxppc-dev@lists.ozlabs.org Signed-off-by: Elvira Khabirova Signed-off-by: Dmitry V. Levin --- Please make either v5 or v6 edition of this fix, or any similar fix, into v4.20. v6: reverted to a fixed version of v4, compile- and run-tested with strace v5: reverted to a simple approach, compile- and run-tested 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..fcfdc1229f08 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