linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Dmitry V. Levin" <ldv@altlinux.org>
To: Oleg Nesterov <oleg@redhat.com>
Cc: Michael Ellerman <mpe@ellerman.id.au>,
	Elvira Khabirova <lineprinter@altlinux.org>,
	Benjamin Herrenschmidt <benh@kernel.crashing.org>,
	Paul Mackerras <paulus@samba.org>,
	Breno Leitao <leitao@debian.org>,
	Andy Lutomirski <luto@kernel.org>,
	Eugene Syromyatnikov <esyr@redhat.com>,
	linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v6] powerpc/ptrace: replace ptrace_report_syscall() with a tracehook call
Date: Mon, 10 Dec 2018 16:36:55 +0300	[thread overview]
Message-ID: <20181210133655.GH11942@altlinux.org> (raw)
In-Reply-To: <20181210132806.GA4177@redhat.com>

[-- Attachment #1: Type: text/plain, Size: 3167 bytes --]

On Mon, Dec 10, 2018 at 02:28:07PM +0100, Oleg Nesterov wrote:
> On 12/07, Dmitry V. Levin wrote:
> >
> > Please make either v5 or v6 edition of this fix, or any similar fix,
> > into v4.20.
> 
> IIUC, v5 above means
> 
> 	[PATCH v5 23/25] powerpc/ptrace: replace ptrace_report_syscall() with a tracehook call
> 
> you sent in another series...

They just happen to have the same v5 here and there.
In that series I included the most trivial variant of the change.

> >  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))
> 
> I will leave this to maintainers, but to me this change looks good and imo it
> also cleanups the code.
> 
> However I am not sure cached_flags should include _TIF_SYSCALL_TRACEPOINT. If
> nothing else, the caller can sleep in ptrace_stop() unpredictably long and
> TIF_SYSCALL_TRACEPOINT can be set/cleared meanwhile.

I agree, we shouldn't cache _TIF_SYSCALL_TRACEPOINT.


-- 
ldv

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 801 bytes --]

  reply	other threads:[~2018-12-10 13:37 UTC|newest]

Thread overview: 20+ 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 12:42 ` Michael Ellerman
2018-11-19 21:01   ` [PATCH v3] " Dmitry V. Levin
2018-11-21 21:17     ` Michael Ellerman
2018-12-03  3:18       ` [PATCH v4] " Dmitry V. Levin
2018-12-07  1:19         ` Dmitry V. Levin
2018-12-07 11:12           ` Michael Ellerman
2018-12-07 15:42             ` Dmitry V. Levin
2018-12-07 15:56               ` [PATCH v5] " Dmitry V. Levin
2018-12-07 18:52                 ` [PATCH v6] " Dmitry V. Levin
2018-12-10 13:28                   ` Oleg Nesterov
2018-12-10 13:36                     ` Dmitry V. Levin [this message]
2018-12-16 17:28                       ` [PATCH] powerpc/ptrace: cleanup do_syscall_trace_enter Dmitry V. Levin
2018-12-17 11:20                         ` Michael Ellerman
2018-12-17 11:23                           ` Dmitry V. Levin
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-07 16:34               ` [PATCH v4] " Oleg Nesterov
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=20181210133655.GH11942@altlinux.org \
    --to=ldv@altlinux.org \
    --cc=benh@kernel.crashing.org \
    --cc=esyr@redhat.com \
    --cc=leitao@debian.org \
    --cc=lineprinter@altlinux.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=luto@kernel.org \
    --cc=mpe@ellerman.id.au \
    --cc=oleg@redhat.com \
    --cc=paulus@samba.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).