mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Pedro Alves <pedro@palves.net>
To: Andy Lutomirski <luto@kernel.org>, x86@kernel.org
Cc: "linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	Kees Cook <keescook@chromium.org>, Borislav Petkov <bp@alien8.de>,
	Oleg Nesterov <oleg@redhat.com>
Subject: Re: [PATCH] x86/ptrace: Remove questionable TS_COMPAT usage in ptrace
Date: Sat, 18 Jun 2016 14:55:58 +0100	[thread overview]
Message-ID: <b9f316ca-5f79-91f5-1d19-773679778357@palves.net> (raw)
In-Reply-To: <94bda8cd5f326ae5591c80fb5d7c1c22624accec.1466244711.git.luto@kernel.org>

On 06/18/2016 11:21 AM, Andy Lutomirski wrote:
> A 32-bit tracer can set a tracee's TS_COMPAT flag by poking orig_ax.
> 
> - If the tracee is stopped in a 32-bit syscall, this has no effect
>   as TS_COMPAT will already be set.
> 
> - If the tracee is stopped on entry to a 64-bit syscall, this could
>   cause problems: in_compat_syscall() etc will be out of sync with
>   the actual syscall table in use.  I can imagine this bre aking
>   audit.  (It can't meaningfully break seccomp, as a malicious
>   tracer can already fully bypass seccomp.)  I could also imagine it
>   subtly confusing the implementations of a few syscalls.
> 
>  - If the tracee is stopped in a non-syscall context, then TS_COMPAT
>    will end up set in user mode, which isn't supposed to happen.  The results
>    are likely to be similar to the 64-bit syscall entry case.
> 
> Fix it by deleting the code.
> 
> Here's my understanding of the previous intent.  Suppose a
> 32-bit tracee makes a syscall that returns one of the -ERESTART
> codes.  A 32-bit tracer saves away its register state.  The tracee
> resumes, returns from the system call, and gets stopped again for a
> non-syscall reason (e.g. a signal).  Then the tracer tries to roll
> back the tracee's state by writing all of the saved registers back.
> 
> The result of this sequence of events will be that the tracee's
> registers' low bits match what they were at the end of the syscall
> but TS_COMPAT will be clear.  This will cause syscall_get_error() to
> return a *positive* number, because we zero-extend registers poked
> by 32-bit tracers instead of sign-extending them.  As a result, with
> this change, syscall restart won't happen, whereas, historically, it
> would have happened.
> 
> As far as I can tell, this corner case isn't very important, and I

I believe it's actually very much very important for gdb, for restoring
the inferior state when the user calls a function in the inferior, with:

 (gdb) print foo()

Some background here:

 http://linux-kernel.vger.kernel.narkive.com/fqrh4xKK/patch-x86-ptrace-sign-extend-eax-with-orig-eax-0

This hunk being mentioned in this thread a couple years ago too:

 https://www.sourceware.org/ml/gdb/2014-04/msg00095.html

Please don't break this use case ( and fix the one reported in
that thread :-) ).

Thanks,
Pedro Alves

  reply	other threads:[~2016-06-18 13:56 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-06-18 10:21 Andy Lutomirski
2016-06-18 13:55 ` Pedro Alves [this message]
2016-06-18 14:41   ` Pedro Alves
2016-06-18 17:02   ` Andy Lutomirski
2016-06-19 22:09     ` Andy Lutomirski
2016-06-20 10:27       ` Pedro Alves
2016-06-20 15:24       ` Oleg Nesterov
2016-06-20 16:30         ` Andy Lutomirski
2016-06-20 16:14           ` Oleg Nesterov
2016-06-20 17:25             ` Andy Lutomirski
2016-06-20 10:07     ` Pedro Alves
2016-06-20 11:12       ` Jan Kratochvil
2016-06-18 17:48 ` Kees Cook
2016-06-19 21:19 ` Oleg Nesterov
2016-06-19 22:23   ` Andy Lutomirski
2016-06-20  6:12   ` Andy Lutomirski
2016-06-20 15:31     ` Oleg Nesterov
2016-06-20 17:53     ` the usage of __SYSCALL_MASK in entry_SYSCALL_64/do_syscall_64 is not consistent Oleg Nesterov
2016-06-21 19:01       ` 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=b9f316ca-5f79-91f5-1d19-773679778357@palves.net \
    --to=pedro@palves.net \
    --cc=bp@alien8.de \
    --cc=keescook@chromium.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=luto@kernel.org \
    --cc=oleg@redhat.com \
    --cc=x86@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 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®