All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andy Lutomirski <luto@amacapital.net>
To: Dmitry Safonov <dsafonov@virtuozzo.com>, Oleg Nesterov <oleg@redhat.com>
Cc: "linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	Dmitry Safonov <0x7f454c46@gmail.com>,
	Andy Lutomirski <luto@kernel.org>, Ingo Molnar <mingo@redhat.com>,
	Thomas Gleixner <tglx@linutronix.de>,
	"H. Peter Anvin" <hpa@zytor.com>, X86 ML <x86@kernel.org>
Subject: Re: [RFC 3/3] x86/ptrace: down with test_thread_flag(TIF_IA32)
Date: Mon, 25 Apr 2016 09:53:43 -0700	[thread overview]
Message-ID: <CALCETrU5O66hT0fwRLP-hwJ9_CK1Q4F2vSXRXZPQ1Je7Y1CKoQ@mail.gmail.com> (raw)
In-Reply-To: <1461600763-3534-3-git-send-email-dsafonov@virtuozzo.com>

On Mon, Apr 25, 2016 at 9:12 AM, Dmitry Safonov <dsafonov@virtuozzo.com> wrote:
> As the task isn't executing at the moment of {GET,SET}REGS,
> return regset that corresponds to code selector.
> So, for i386 elf binary that changed it's CS to __USER_CS
> it will return full x86_64 register set.
>
> That will change ABI: i.e, strace uses returned register size
> to determine, in which mode the application is.
> With the current ABI that way is buggy:

Oleg, any comment here?

>
> int main(int argc, char **argv, char **envp)
> {
>         printf("Here we exit\n");
>         fflush(stdout);
>         asm volatile ("int $0x80" : : "a" (__NR_exit), "D" (1));
>         printf("After exit\n");
>
>         return 0;
> }
>
> This program will confuse strace:
>
> [tst]$ strace ./confuse 2>&1 | tail
> brk(0x1ca1000)                          = 0x1ca1000
> write(1, "Here we exit\n", 13Here we exit
> )          = 13
> exit(1)                                 = ?
> <... exit resumed> strace: _exit returned!
> )                    = ?
> write(1, "After exit\n", 11After exit
> )            = 11
> exit_group(0)                           = ?
> +++ exited with 0 +++
>
> So this ABI change should make PTRACE_GETREGSET more reliable and
> this will be another step to drop TIF_{IA32,X32} flags.

Does strace start working again with this change?  I suspect that
we'll eventually have to expose syscall_get_arch directly through
ptrace, but that's a project for another day.

I think this patch is fine, but I'm not a ptrace expert.

--Andy

>
> Cc: Andy Lutomirski <luto@kernel.org>
> Cc: Ingo Molnar <mingo@redhat.com>
> Cc: Thomas Gleixner <tglx@linutronix.de>
> Cc: "H. Peter Anvin" <hpa@zytor.com>
> Cc: Oleg Nesterov <oleg@redhat.com>
> Cc: x86@kernel.org
> Signed-off-by: Dmitry Safonov <dsafonov@virtuozzo.com>
> ---
>  arch/x86/kernel/ptrace.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/arch/x86/kernel/ptrace.c b/arch/x86/kernel/ptrace.c
> index 0f4d2a5df2dc..d7d72f2f8b46 100644
> --- a/arch/x86/kernel/ptrace.c
> +++ b/arch/x86/kernel/ptrace.c
> @@ -1387,7 +1387,7 @@ void update_regset_xstate_info(unsigned int size, u64 xstate_mask)
>  const struct user_regset_view *task_user_regset_view(struct task_struct *task)
>  {
>  #ifdef CONFIG_IA32_EMULATION
> -       if (test_tsk_thread_flag(task, TIF_IA32))
> +       if (!user_64bit_mode(task_pt_regs(task)))
>  #endif
>  #if defined CONFIG_X86_32 || defined CONFIG_IA32_EMULATION
>                 return &user_x86_32_view;
> --
> 2.8.0
>



-- 
Andy Lutomirski
AMA Capital Management, LLC

  reply	other threads:[~2016-04-25 16:54 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-04-25 16:12 [RFC 1/3] x86/signal: add SA_{X32,IA32}_ABI sa_flags Dmitry Safonov
2016-04-25 16:12 ` [RFC 2/3] x86/coredump: use core regs, rather that TIF_IA32 flag Dmitry Safonov
2016-04-25 16:51   ` Andy Lutomirski
2016-04-25 16:12 ` [RFC 3/3] x86/ptrace: down with test_thread_flag(TIF_IA32) Dmitry Safonov
2016-04-25 16:53   ` Andy Lutomirski [this message]
2016-04-25 17:14     ` Dmitry Safonov
2016-04-25 18:09       ` Dmitry Safonov
2016-04-25 18:13         ` Dmitry Safonov
2016-04-25 19:33         ` Andy Lutomirski
2016-04-25 20:37           ` Dmitry Safonov
2016-04-25 19:20 ` [RFC 1/3] x86/signal: add SA_{X32,IA32}_ABI sa_flags Andy Lutomirski
2016-04-25 20:34   ` Dmitry Safonov
2016-04-25 20:38     ` Andy Lutomirski

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=CALCETrU5O66hT0fwRLP-hwJ9_CK1Q4F2vSXRXZPQ1Je7Y1CKoQ@mail.gmail.com \
    --to=luto@amacapital.net \
    --cc=0x7f454c46@gmail.com \
    --cc=dsafonov@virtuozzo.com \
    --cc=hpa@zytor.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=luto@kernel.org \
    --cc=mingo@redhat.com \
    --cc=oleg@redhat.com \
    --cc=tglx@linutronix.de \
    --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 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.