From: James Hogan <james.hogan@imgtec.com>
To: Kees Cook <keescook@chromium.org>
Cc: Linux MIPS Mailing List <linux-mips@linux-mips.org>,
LKML <linux-kernel@vger.kernel.org>,
Ralf Baechle <ralf@linux-mips.org>,
Oleg Nesterov <oleg@redhat.com>,
Andy Lutomirski <luto@amacapital.net>,
Will Drewry <wad@chromium.org>
Subject: Re: [PATCH 4/4] MIPS/ptrace: Add PTRACE_SET_SYSCALL operation
Date: Mon, 14 Aug 2017 10:41:45 +0100 [thread overview]
Message-ID: <20170814094145.GP6973@jhogan-linux.le.imgtec.org> (raw)
In-Reply-To: <CAGXu5j+Z_n1G9_q=FrOHVbz0axR8G6izB2Rvku1k6bRjJ6rMrA@mail.gmail.com>
[-- Attachment #1: Type: text/plain, Size: 5494 bytes --]
On Fri, Aug 11, 2017 at 03:23:34PM -0700, Kees Cook wrote:
> On Fri, Aug 11, 2017 at 1:56 PM, James Hogan <james.hogan@imgtec.com> wrote:
> > Add a PTRACE_SET_SYSCALL ptrace operation to allow the system call to be
> > cancelled independently to the value of the v0 system call number
> > register.
> >
> > This is needed for SECCOMP_RET_TRACE when the tracer wants to cancel the
> > system call, since it has to set both the system call number to -1 and
> > the chosen return value, both of which reside in the same register (v0).
> > The tracer should set the return value first, followed by
> > PTRACE_SET_SYSCALL to set the system call number to -1.
> >
> > That is in contrast to the normal ptrace syscall hook which triggers the
> > tracer on both entry and exit, allowing the system call to be cancelled
> > during the entry hook (setting system call number register to -1, or
> > optionally using PTRACE_SET_SYSCALL), separately to setting the return
> > value during the exit hook.
> >
> > Positive values (to change the syscall that should be executed instead
> > of cancelling it entirely) are explicitly disallowed at the moment. The
> > same thing can be done safely already by writing the v0 system call
> > number register and the argument registers, and allowing
> > thread_info::syscall to be changed to a different value independently of
> > the v0 register would potentially allow seccomp or the syscall trace
> > events to be fooled into thinking a different system call was being
> > executed.
>
> Wouldn't the sycall be reloaded, so no spoofing could occur?
The case I was thinking of was:
- PTRACE_POKEUSR v0 = __NR_some_disallowed_syscall
- PTRACE_SET_SYSCALL __NR_some_allowed_syscall
syscall_get_nr() will return __NR_some_allowed_syscall, so seccomp will
allow, but when syscall_trace_enter() returns to syscall_trace_entry in
arch/mips/kernel/scall32-o32.S, it will reload the syscall number from
v0 (i.e. __NR_some_disallowed_syscall).
>
> Regardless, can you update
> tools/testing/selftests/seccomp/seccomp_bpf.c to update or eliminate
> the MIPS-only SYSCALL_NUM_RET_SHARE_REG special-case? (Or maybe it
> needs to be further special-cased to split syscall-changing from
> syscall-cancelling?)
Sure, i'll look into that,
Thanks for reviewing,
Cheers
James
>
> -Kees
>
> >
> > Signed-off-by: James Hogan <james.hogan@imgtec.com>
> > Cc: Ralf Baechle <ralf@linux-mips.org>
> > Cc: Oleg Nesterov <oleg@redhat.com>
> > Cc: Kees Cook <keescook@chromium.org>
> > Cc: Andy Lutomirski <luto@amacapital.net>
> > Cc: Will Drewry <wad@chromium.org>
> > Cc: linux-mips@linux-mips.org
> > ---
> > arch/mips/include/uapi/asm/ptrace.h | 1 +
> > arch/mips/kernel/ptrace.c | 11 +++++++++++
> > arch/mips/kernel/ptrace32.c | 11 +++++++++++
> > 3 files changed, 23 insertions(+)
> >
> > diff --git a/arch/mips/include/uapi/asm/ptrace.h b/arch/mips/include/uapi/asm/ptrace.h
> > index 91a3d197ede3..23af103c4e8d 100644
> > --- a/arch/mips/include/uapi/asm/ptrace.h
> > +++ b/arch/mips/include/uapi/asm/ptrace.h
> > @@ -58,6 +58,7 @@ struct pt_regs {
> >
> > #define PTRACE_GET_THREAD_AREA 25
> > #define PTRACE_SET_THREAD_AREA 26
> > +#define PTRACE_SET_SYSCALL 27
> >
> > /* Calls to trace a 64bit program from a 32bit program. */
> > #define PTRACE_PEEKTEXT_3264 0xc0
> > diff --git a/arch/mips/kernel/ptrace.c b/arch/mips/kernel/ptrace.c
> > index 465fc5633e61..9bf31a990c6e 100644
> > --- a/arch/mips/kernel/ptrace.c
> > +++ b/arch/mips/kernel/ptrace.c
> > @@ -853,6 +853,17 @@ long arch_ptrace(struct task_struct *child, long request,
> > ret = put_user(task_thread_info(child)->tp_value, datalp);
> > break;
> >
> > + case PTRACE_SET_SYSCALL:
> > + /*
> > + * This is currently only useful to cancel the syscall from a
> > + * seccomp RET_TRACE tracer.
> > + */
> > + if ((long)data >= 0)
> > + return -EINVAL;
> > + task_thread_info(child)->syscall = -1;
> > + ret = 0;
> > + break;
> > +
> > case PTRACE_GET_WATCH_REGS:
> > ret = ptrace_get_watch_regs(child, addrp);
> > break;
> > diff --git a/arch/mips/kernel/ptrace32.c b/arch/mips/kernel/ptrace32.c
> > index 2b9260f92ccd..cca76aec9c10 100644
> > --- a/arch/mips/kernel/ptrace32.c
> > +++ b/arch/mips/kernel/ptrace32.c
> > @@ -287,6 +287,17 @@ long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
> > (unsigned int __user *) (unsigned long) data);
> > break;
> >
> > + case PTRACE_SET_SYSCALL:
> > + /*
> > + * This is currently only useful to cancel the syscall from a
> > + * seccomp RET_TRACE tracer.
> > + */
> > + if ((long)data >= 0)
> > + return -EINVAL;
> > + task_thread_info(child)->syscall = -1;
> > + ret = 0;
> > + break;
> > +
> > case PTRACE_GET_THREAD_AREA_3264:
> > ret = put_user(task_thread_info(child)->tp_value,
> > (unsigned long __user *) (unsigned long) data);
> > --
> > 2.13.2
> >
>
>
>
> --
> Kees Cook
> Pixel Security
[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
next prev parent reply other threads:[~2017-08-14 9:41 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-08-11 20:56 [PATCH 0/4] MIPS: syscall tracing fixes James Hogan
2017-08-11 20:56 ` [PATCH 1/4] MIPS/seccomp: Fix indirect syscall args James Hogan
2017-08-11 22:17 ` Kees Cook
2017-08-11 20:56 ` [PATCH 2/4] MIPS/ptrace: Pick up ptrace/seccomp changed syscalls James Hogan
2017-08-11 22:18 ` Kees Cook
2017-08-11 20:56 ` [PATCH 3/4] MIPS/ptrace: Update syscall nr on register changes James Hogan
2017-08-11 20:56 ` [PATCH 4/4] MIPS/ptrace: Add PTRACE_SET_SYSCALL operation James Hogan
2017-08-11 22:23 ` Kees Cook
2017-08-14 9:41 ` James Hogan [this message]
2017-08-14 17:55 ` Kees Cook
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=20170814094145.GP6973@jhogan-linux.le.imgtec.org \
--to=james.hogan@imgtec.com \
--cc=keescook@chromium.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mips@linux-mips.org \
--cc=luto@amacapital.net \
--cc=oleg@redhat.com \
--cc=ralf@linux-mips.org \
--cc=wad@chromium.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
all inboxes | Powered by JetHome®