From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754919AbcDYQyG (ORCPT ); Mon, 25 Apr 2016 12:54:06 -0400 Received: from mail-oi0-f43.google.com ([209.85.218.43]:34541 "EHLO mail-oi0-f43.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754262AbcDYQyE (ORCPT ); Mon, 25 Apr 2016 12:54:04 -0400 MIME-Version: 1.0 In-Reply-To: <1461600763-3534-3-git-send-email-dsafonov@virtuozzo.com> References: <1461600763-3534-1-git-send-email-dsafonov@virtuozzo.com> <1461600763-3534-3-git-send-email-dsafonov@virtuozzo.com> From: Andy Lutomirski Date: Mon, 25 Apr 2016 09:53:43 -0700 Message-ID: Subject: Re: [RFC 3/3] x86/ptrace: down with test_thread_flag(TIF_IA32) To: Dmitry Safonov , Oleg Nesterov Cc: "linux-kernel@vger.kernel.org" , Dmitry Safonov <0x7f454c46@gmail.com>, Andy Lutomirski , Ingo Molnar , Thomas Gleixner , "H. Peter Anvin" , X86 ML Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Apr 25, 2016 at 9:12 AM, Dmitry Safonov 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 > Cc: Ingo Molnar > Cc: Thomas Gleixner > Cc: "H. Peter Anvin" > Cc: Oleg Nesterov > Cc: x86@kernel.org > Signed-off-by: Dmitry Safonov > --- > 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