mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Roland McGrath <roland@redhat.com>
To: Andi Kleen <ak@suse.de>
Cc: Andrew Morton <akpm@osdl.org>, Linus Torvalds <torvalds@osdl.org>,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] x86-64: ptrace ia32 BP fix
Date: Tue,  5 Jul 2005 03:19:34 -0700 (PDT)	[thread overview]
Message-ID: <20050705101934.2E307180980@magilla.sf.frob.com> (raw)
In-Reply-To: Andi Kleen's message of  Tuesday, 5 July 2005 11:59:16 +0200 <20050705095916.GV21330@wotan.suse.de>

> On Tue, Jul 05, 2005 at 02:31:15AM -0700, Roland McGrath wrote:
> > --- a/arch/x86_64/ia32/ia32entry.S
> > +++ b/arch/x86_64/ia32/ia32entry.S
> > @@ -102,6 +102,7 @@ sysenter_do_call:	
> >  	.byte	0xf, 0x35
> >  
> >  sysenter_tracesys:
> > +	movl	%r9d,%ebp
> >  	SAVE_REST
> 
> This is wrong because it will clobber ebp before it is saved.
> It is only saved in SAVE_REST.

It is right because it stores %ebp before it is saved in the argument block
that ptrace can access.  That is the point of it.  %r9d has the value
loaded from (%rbp) just prior to this code, which is what %ebp should
reflect to match the i386 behavior.

> 
> >  	CLEAR_RREGS
> >  	movq	$-ENOSYS,RAX(%rsp)	/* really needed? */
> > @@ -109,13 +110,7 @@ sysenter_tracesys:
> >  	call	syscall_trace_enter
> >  	LOAD_ARGS ARGOFFSET  /* reload args from stack in case ptrace changed it */
> >  	RESTORE_REST
> > -	movl	%ebp, %ebp
> > -	/* no need to do an access_ok check here because rbp has been
> > -	   32bit zero extended */ 
> > -1:	movl	(%rbp),%r9d
> > -	.section __ex_table,"a"
> > -	.quad 1b,ia32_badarg
> > -	.previous
> > +	movl	%ebp,%r9d
> 
> And this also cannot be correct because RESTORE_REST has overwritten %rbp
> already.

This is also correct because RESTORE_REST has stored into %rbp the value in
the argument block, which ptrace may have modified.  This movl ensures that
this changed value is what the system call's argument will be.

The patch is tested and works.  Just try strace on a 32-bit program that
calls mmap2 and look at the 6th argument value.  It shows a stack address
without this patch.  With this patch, it shows the argument value the same
as strace on a native i386 kernel does.


Thanks,
Roland

       reply	other threads:[~2005-07-05 10:26 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20050705095916.GV21330@wotan.suse.de>
2005-07-05 10:19 ` Roland McGrath [this message]
2005-07-05  9:31 Roland McGrath
2005-07-05 14:07 ` Daniel Jacobowitz
2005-07-05 14:16   ` Andi Kleen
2005-07-05 19:11   ` Roland McGrath

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=20050705101934.2E307180980@magilla.sf.frob.com \
    --to=roland@redhat.com \
    --cc=ak@suse.de \
    --cc=akpm@osdl.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=torvalds@osdl.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®