From: Rich Felker <dalias@libc.org>
To: John Paul Adrian Glaubitz <glaubitz@physik.fu-berlin.de>
Cc: linux-sh@vger.kernel.org,
Michael Karcher <kernel@mkarcher.dialup.fu-berlin.de>,
linux-kernel@vger.kernel.org,
Yoshinori Sato <ysato@users.sourceforge.jp>
Subject: Re: [PATCH] sh: fix syscall tracing
Date: Thu, 3 Sep 2020 12:16:40 -0400 [thread overview]
Message-ID: <20200903161639.GE3265@brightrain.aerifal.cx> (raw)
In-Reply-To: <e456a455-62cd-4f76-a69a-84d1e5b4d153@physik.fu-berlin.de>
On Thu, Sep 03, 2020 at 12:14:43PM +0200, John Paul Adrian Glaubitz wrote:
> Hi Rich!
>
> On 9/3/20 7:48 AM, Rich Felker wrote:
> > Addition of SECCOMP_FILTER exposed a longstanding bug in
> > do_syscall_trace_enter, whereby r0 (the 5th argument register) was
> > mistakenly used where r3 (syscall_nr) was intended. By overwriting r0
> > rather than r3 with -1 when attempting to block a syscall, the
> > existing code would instead have caused the syscall to execute with an
> > argument clobbered.
> >
> > Commit 0bb605c2c7f2b4b3 then introduced skipping of the syscall when
> > do_syscall_trace_enter returns -1, so that the return value set by
> > seccomp filters would not be clobbered by -ENOSYS. This eliminated the
> > clobbering of the 5th argument register, but instead caused syscalls
> > made with a 5th argument of -1 to be misinterpreted as a request by
> > do_syscall_trace_enter to suppress the syscall.
> >
> > Fixes: 0bb605c2c7f2b4b3 ("sh: Add SECCOMP_FILTER")
> > Fixes: ab99c733ae73cce3 ("sh: Make syscall tracer use tracehook notifiers, add TIF_NOTIFY_RESUME.")
> > Signed-off-by: Rich Felker <dalias@libc.org>
> > ---
> > arch/sh/kernel/entry-common.S | 1 -
> > arch/sh/kernel/ptrace_32.c | 15 +++++----------
> > 2 files changed, 5 insertions(+), 11 deletions(-)
> >
> > diff --git a/arch/sh/kernel/entry-common.S b/arch/sh/kernel/entry-common.S
> > index ad963104d22d..91ab2607a1ff 100644
> > --- a/arch/sh/kernel/entry-common.S
> > +++ b/arch/sh/kernel/entry-common.S
> > @@ -370,7 +370,6 @@ syscall_trace_entry:
> > nop
> > cmp/eq #-1, r0
> > bt syscall_exit
> > - mov.l r0, @(OFF_R0,r15) ! Save return value
> > ! Reload R0-R4 from kernel stack, where the
> > ! parent may have modified them using
> > ! ptrace(POKEUSR). (Note that R0-R2 are
> > diff --git a/arch/sh/kernel/ptrace_32.c b/arch/sh/kernel/ptrace_32.c
> > index b05bf92f9c32..5281685f6ad1 100644
> > --- a/arch/sh/kernel/ptrace_32.c
> > +++ b/arch/sh/kernel/ptrace_32.c
> > @@ -455,16 +455,11 @@ long arch_ptrace(struct task_struct *child, long request,
> >
> > asmlinkage long do_syscall_trace_enter(struct pt_regs *regs)
> > {
> > - long ret = 0;
> > -
> > if (test_thread_flag(TIF_SYSCALL_TRACE) &&
> > - tracehook_report_syscall_entry(regs))
> > - /*
> > - * Tracing decided this syscall should not happen.
> > - * We'll return a bogus call number to get an ENOSYS
> > - * error, but leave the original number in regs->regs[0].
> > - */
> > - ret = -1L;
> > + tracehook_report_syscall_entry(regs)) {
> > + regs->regs[0] = -ENOSYS;
> > + return -1;
> > + }
> >
> > if (secure_computing() == -1)
> > return -1;
> > @@ -475,7 +470,7 @@ asmlinkage long do_syscall_trace_enter(struct pt_regs *regs)
> > audit_syscall_entry(regs->regs[3], regs->regs[4], regs->regs[5],
> > regs->regs[6], regs->regs[7]);
> >
> > - return ret ?: regs->regs[0];
> > + return 0;
> > }
> >
> > asmlinkage void do_syscall_trace_leave(struct pt_regs *regs)
> >
>
> I can confirm that this patch fixes both strace for me and does not break libseccomp,
> I have run the libseccomp testsuite with my patch for SuperH support applied on top
> of a rebased libseccomp with the 32-bit fixes. Attaching the testsuite log.
>
> Tested-by: John Paul Adrian Glaubitz <glaubitz@physik.fu-berlin.de>
Great! Thanks!
Rich
next prev parent reply other threads:[~2020-09-03 16:16 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-09-03 5:48 Rich Felker
2020-09-03 8:13 ` John Paul Adrian Glaubitz
2020-09-03 10:14 ` John Paul Adrian Glaubitz
2020-09-03 16:16 ` Rich Felker [this message]
2020-09-07 9:52 ` John Paul Adrian Glaubitz
2020-09-07 17:44 ` Rich Felker
2020-09-10 9:55 ` John Paul Adrian Glaubitz
2020-09-10 11:02 ` Rob Landley
2020-09-10 13:37 ` Rich Felker
2020-09-15 10:35 ` John Paul Adrian Glaubitz
2020-09-16 0:28 ` Rich Felker
2020-09-18 19:29 ` Rich Felker
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=20200903161639.GE3265@brightrain.aerifal.cx \
--to=dalias@libc.org \
--cc=glaubitz@physik.fu-berlin.de \
--cc=kernel@mkarcher.dialup.fu-berlin.de \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-sh@vger.kernel.org \
--cc=ysato@users.sourceforge.jp \
/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
all inboxes | Powered by JetHome®