From: Kees Cook <keescook@chromium.org>
To: Michael Ellerman <mpe@ellerman.id.au>
Cc: Thadeu Lima de Souza Cascardo <cascardo@canonical.com>,
linux-kselftest@vger.kernel.org, Oleg Nesterov <oleg@redhat.com>,
Shuah Khan <shuah@kernel.org>,
linuxppc-dev@lists.ozlabs.org
Subject: Re: [PATCH] selftests/seccomp: fix ptrace tests on powerpc
Date: Thu, 17 Sep 2020 15:37:16 -0700 [thread overview]
Message-ID: <202009171536.7FACD19@keescook> (raw)
In-Reply-To: <875z8hrh2o.fsf@mpe.ellerman.id.au>
On Sun, Sep 13, 2020 at 10:34:23PM +1000, Michael Ellerman wrote:
> Thadeu Lima de Souza Cascardo <cascardo@canonical.com> writes:
> > On Tue, Sep 08, 2020 at 04:18:17PM -0700, Kees Cook wrote:
> >> On Tue, Jun 30, 2020 at 01:47:39PM -0300, Thadeu Lima de Souza Cascardo wrote:
> ...
> >> > @@ -1809,10 +1818,15 @@ void tracer_ptrace(struct __test_metadata *_metadata, pid_t tracee,
> >> > EXPECT_EQ(entry ? PTRACE_EVENTMSG_SYSCALL_ENTRY
> >> > : PTRACE_EVENTMSG_SYSCALL_EXIT, msg);
> >> >
> >> > - if (!entry)
> >> > + if (!entry && !syscall_nr)
> >> > return;
> >> >
> >> > - nr = get_syscall(_metadata, tracee);
> >> > + if (entry)
> >> > + nr = get_syscall(_metadata, tracee);
> >> > + else
> >> > + nr = *syscall_nr;
> >>
> >> This is weird? Shouldn't get_syscall() be modified to do the right thing
> >> here instead of depending on the extra arg?
> >>
> >
> > R0 might be clobered. Same documentation mentions it as volatile. So, during
> > syscall exit, we can't tell for sure that R0 will have the original syscall
> > number. So, we need to grab it during syscall enter, save it somewhere and
> > reuse it. I used the test context/args for that.
>
> The user r0 (in regs->gpr[0]) shouldn't be clobbered.
>
> But it is modified if the tracer skips the syscall, by setting the
> syscall number to -1. Or if the tracer changes the syscall number.
>
> So if you need the original syscall number in the exit path then I think
> you do need to save it at entry.
... the selftest code wants to test the updated syscall (-1 or
whatever), so this sounds correct. Was this test actually failing on
powerpc? (I'd really rather not split entry/exit if I don't have to.)
--
Kees Cook
WARNING: multiple messages have this Message-ID (diff)
From: Kees Cook <keescook@chromium.org>
To: Michael Ellerman <mpe@ellerman.id.au>
Cc: Thadeu Lima de Souza Cascardo <cascardo@canonical.com>,
linuxppc-dev@lists.ozlabs.org, Shuah Khan <shuah@kernel.org>,
Oleg Nesterov <oleg@redhat.com>,
linux-kselftest@vger.kernel.org
Subject: Re: [PATCH] selftests/seccomp: fix ptrace tests on powerpc
Date: Thu, 17 Sep 2020 15:37:16 -0700 [thread overview]
Message-ID: <202009171536.7FACD19@keescook> (raw)
In-Reply-To: <875z8hrh2o.fsf@mpe.ellerman.id.au>
On Sun, Sep 13, 2020 at 10:34:23PM +1000, Michael Ellerman wrote:
> Thadeu Lima de Souza Cascardo <cascardo@canonical.com> writes:
> > On Tue, Sep 08, 2020 at 04:18:17PM -0700, Kees Cook wrote:
> >> On Tue, Jun 30, 2020 at 01:47:39PM -0300, Thadeu Lima de Souza Cascardo wrote:
> ...
> >> > @@ -1809,10 +1818,15 @@ void tracer_ptrace(struct __test_metadata *_metadata, pid_t tracee,
> >> > EXPECT_EQ(entry ? PTRACE_EVENTMSG_SYSCALL_ENTRY
> >> > : PTRACE_EVENTMSG_SYSCALL_EXIT, msg);
> >> >
> >> > - if (!entry)
> >> > + if (!entry && !syscall_nr)
> >> > return;
> >> >
> >> > - nr = get_syscall(_metadata, tracee);
> >> > + if (entry)
> >> > + nr = get_syscall(_metadata, tracee);
> >> > + else
> >> > + nr = *syscall_nr;
> >>
> >> This is weird? Shouldn't get_syscall() be modified to do the right thing
> >> here instead of depending on the extra arg?
> >>
> >
> > R0 might be clobered. Same documentation mentions it as volatile. So, during
> > syscall exit, we can't tell for sure that R0 will have the original syscall
> > number. So, we need to grab it during syscall enter, save it somewhere and
> > reuse it. I used the test context/args for that.
>
> The user r0 (in regs->gpr[0]) shouldn't be clobbered.
>
> But it is modified if the tracer skips the syscall, by setting the
> syscall number to -1. Or if the tracer changes the syscall number.
>
> So if you need the original syscall number in the exit path then I think
> you do need to save it at entry.
... the selftest code wants to test the updated syscall (-1 or
whatever), so this sounds correct. Was this test actually failing on
powerpc? (I'd really rather not split entry/exit if I don't have to.)
--
Kees Cook
next prev parent reply other threads:[~2020-09-17 22:37 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-06-30 16:47 [PATCH] selftests/seccomp: fix ptrace tests on powerpc Thadeu Lima de Souza Cascardo
2020-06-30 16:47 ` Thadeu Lima de Souza Cascardo
2020-09-08 23:18 ` Kees Cook
2020-09-08 23:18 ` Kees Cook
2020-09-11 18:06 ` Thadeu Lima de Souza Cascardo
2020-09-11 18:06 ` Thadeu Lima de Souza Cascardo
2020-09-13 12:34 ` Michael Ellerman
2020-09-13 12:34 ` Michael Ellerman
2020-09-17 22:37 ` Kees Cook [this message]
2020-09-17 22:37 ` Kees Cook
2020-09-17 22:51 ` Thadeu Lima de Souza Cascardo
2020-09-17 22:51 ` Thadeu Lima de Souza Cascardo
2020-09-18 6:22 ` Michael Ellerman
2020-09-18 6:22 ` Michael Ellerman
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=202009171536.7FACD19@keescook \
--to=keescook@chromium.org \
--cc=cascardo@canonical.com \
--cc=linux-kselftest@vger.kernel.org \
--cc=linuxppc-dev@lists.ozlabs.org \
--cc=mpe@ellerman.id.au \
--cc=oleg@redhat.com \
--cc=shuah@kernel.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 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.