All of lore.kernel.org
 help / color / mirror / Atom feed
From: Michael Ellerman <mpe@ellerman.id.au>
To: "Dmitry V. Levin" <ldv@altlinux.org>, Oleg Nesterov <oleg@redhat.com>
Cc: linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] powerpc/ptrace: cleanup do_syscall_trace_enter
Date: Mon, 17 Dec 2018 22:20:26 +1100	[thread overview]
Message-ID: <87y38otn5x.fsf@concordia.ellerman.id.au> (raw)
In-Reply-To: <20181216172828.GA25359@altlinux.org>

"Dmitry V. Levin" <ldv@altlinux.org> writes:
> Invoke tracehook_report_syscall_entry once.

Thanks.

> Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
> ---
>  arch/powerpc/kernel/ptrace.c | 54 +++++++++++++++++++++---------------
>  1 file changed, 31 insertions(+), 23 deletions(-)
>
> diff --git a/arch/powerpc/kernel/ptrace.c b/arch/powerpc/kernel/ptrace.c
> index 714c3480c52d..8794d32c2d9e 100644
> --- a/arch/powerpc/kernel/ptrace.c
> +++ b/arch/powerpc/kernel/ptrace.c
> @@ -3263,32 +3263,40 @@ static inline int do_seccomp(struct pt_regs *regs) { return 0; }
>   */
>  long do_syscall_trace_enter(struct pt_regs *regs)
>  {
> +	u32 cached_flags;
> +

Do you mind if I just call it "flags", I find "cached_flags" a bit
unwieldy for some reason.

I'm happy to fix it up when applying.

cheers

>  	user_exit();
>  
> -	if (test_thread_flag(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.
> -		 */
> -		if (tracehook_report_syscall_entry(regs))
> -			;
> -		return -1;
> -	}
> +	cached_flags = READ_ONCE(current_thread_info()->flags) &
> +		       (_TIF_SYSCALL_EMU | _TIF_SYSCALL_TRACE);
>  
> -	/*
> -	 * 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) {
> +		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))
> -- 
> ldv

  reply	other threads:[~2018-12-17 11:20 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-11-16 11:17 [PATCH v2] powerpc/ptrace: replace ptrace_report_syscall() with a tracehook call Elvira Khabirova
2018-11-16 11:17 ` Elvira Khabirova
2018-11-16 12:42 ` Michael Ellerman
2018-11-16 12:42   ` Michael Ellerman
2018-11-19 21:01   ` [PATCH v3] " Dmitry V. Levin
2018-11-19 21:01     ` Dmitry V. Levin
2018-11-21 21:17     ` Michael Ellerman
2018-11-21 21:17       ` Michael Ellerman
2018-12-03  3:18       ` [PATCH v4] " Dmitry V. Levin
2018-12-03  3:18         ` Dmitry V. Levin
2018-12-07  1:19         ` Dmitry V. Levin
2018-12-07  1:19           ` Dmitry V. Levin
2018-12-07 11:12           ` Michael Ellerman
2018-12-07 11:12             ` Michael Ellerman
2018-12-07 15:42             ` Dmitry V. Levin
2018-12-07 15:42               ` Dmitry V. Levin
2018-12-07 15:56               ` [PATCH v5] " Dmitry V. Levin
2018-12-07 15:56                 ` Dmitry V. Levin
2018-12-07 18:52                 ` [PATCH v6] " Dmitry V. Levin
2018-12-07 18:52                   ` Dmitry V. Levin
2018-12-10 13:28                   ` Oleg Nesterov
2018-12-10 13:28                     ` Oleg Nesterov
2018-12-10 13:36                     ` Dmitry V. Levin
2018-12-10 13:36                       ` Dmitry V. Levin
2018-12-16 17:28                       ` [PATCH] powerpc/ptrace: cleanup do_syscall_trace_enter Dmitry V. Levin
2018-12-17 11:20                         ` Michael Ellerman [this message]
2018-12-17 11:23                           ` Dmitry V. Levin
2018-12-17 11:23                             ` Dmitry V. Levin
2018-12-17 11:27                         ` Oleg Nesterov
2018-12-17 11:27                           ` Oleg Nesterov
2018-12-22  9:54                         ` Michael Ellerman
2018-12-11 13:45                 ` [v5] powerpc/ptrace: replace ptrace_report_syscall() with a tracehook call Michael Ellerman
2018-12-11 13:45                   ` Michael Ellerman
2018-12-07 16:34               ` [PATCH v4] " Oleg Nesterov
2018-12-07 16:34                 ` Oleg Nesterov
2018-12-07 18:42                 ` Dmitry V. Levin
2018-12-07 18:42                   ` Dmitry V. Levin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87y38otn5x.fsf@concordia.ellerman.id.au \
    --to=mpe@ellerman.id.au \
    --cc=ldv@altlinux.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=oleg@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.