Re: arm64: Register modification during syscall entry/exit stop

2020-06-01 Thread Dave Martin
On Mon, Jun 01, 2020 at 05:40:28AM -0400, Keno Fischer wrote: > On Mon, Jun 1, 2020 at 5:23 AM Dave Martin wrote: > > > > Can't PTRACE_SYSEMU be emulated by using PTRACE_SYSCALL, cancelling the > > > > syscall at the syscall enter stop, then modifying the regs at the > > > > syscall exit stop? > >

Re: arm64: Register modification during syscall entry/exit stop

2020-06-01 Thread Dave Martin
On Mon, Jun 01, 2020 at 05:23:01AM -0400, Keno Fischer wrote: > On Mon, Jun 1, 2020 at 5:14 AM Dave Martin wrote: > > Can you explain why userspace would write a changed value for x7 > > but at the same time need that new to be thrown away? > > The discarding behavior is the primary reason things

Re: arm64: Register modification during syscall entry/exit stop

2020-06-01 Thread Keno Fischer
On Mon, Jun 1, 2020 at 5:23 AM Dave Martin wrote: > > > Can't PTRACE_SYSEMU be emulated by using PTRACE_SYSCALL, cancelling the > > > syscall at the syscall enter stop, then modifying the regs at the > > > syscall exit stop? > > > > Yes, it can. The idea behind SYSEMU is to be able to save half th

Re: arm64: Register modification during syscall entry/exit stop

2020-06-01 Thread Keno Fischer
On Mon, Jun 1, 2020 at 5:14 AM Dave Martin wrote: > Can you explain why userspace would write a changed value for x7 > but at the same time need that new to be thrown away? The discarding behavior is the primary reason things aren't completely broken at the moment. If it read the wrong x7 value a

Re: arm64: Register modification during syscall entry/exit stop

2020-06-01 Thread Dave Martin
On Sun, May 31, 2020 at 12:20:51PM -0400, Keno Fischer wrote: > > Can't PTRACE_SYSEMU be emulated by using PTRACE_SYSCALL, cancelling the > > syscall at the syscall enter stop, then modifying the regs at the > > syscall exit stop? > > Yes, it can. The idea behind SYSEMU is to be able to save half

Re: arm64: Register modification during syscall entry/exit stop

2020-06-01 Thread Dave Martin
On Sun, May 31, 2020 at 12:13:18PM -0400, Keno Fischer wrote: > > Keno -- are you planning to send out a patch? You previously spoke about > > implementing this using PTRACE_SETOPTIONS. > > Yes, I'll have a patch for you. Though I've come to the conclusion > that introducing a new regset is probab

Re: arm64: Register modification during syscall entry/exit stop

2020-05-31 Thread Keno Fischer
> Can't PTRACE_SYSEMU be emulated by using PTRACE_SYSCALL, cancelling the > syscall at the syscall enter stop, then modifying the regs at the > syscall exit stop? Yes, it can. The idea behind SYSEMU is to be able to save half the ptrace traps that would require, in theory making the ptracer a dece

Re: arm64: Register modification during syscall entry/exit stop

2020-05-31 Thread Keno Fischer
> Keno -- are you planning to send out a patch? You previously spoke about > implementing this using PTRACE_SETOPTIONS. Yes, I'll have a patch for you. Though I've come to the conclusion that introducing a new regset is probably a better way to solve it. We can then also expose orig_x0 at the same

Re: arm64: Register modification during syscall entry/exit stop

2020-05-31 Thread Will Deacon
On Wed, May 27, 2020 at 11:19:29AM +0100, Dave Martin wrote: > On Wed, May 27, 2020 at 10:55:29AM +0100, Will Deacon wrote: > > On Sun, May 24, 2020 at 02:56:35AM -0400, Keno Fischer wrote: > > > Just ran into this issue again, with what I think may be most compelling > > > example yet why this is

Re: arm64: Register modification during syscall entry/exit stop

2020-05-27 Thread Dave Martin
On Wed, May 27, 2020 at 10:55:29AM +0100, Will Deacon wrote: > On Sun, May 24, 2020 at 02:56:35AM -0400, Keno Fischer wrote: > > Just ran into this issue again, with what I think may be most compelling > > example yet why this is problematic: > > > > The tracee incurred a signal, we PTRACE_SYSEMU'

Re: arm64: Register modification during syscall entry/exit stop

2020-05-27 Thread Will Deacon
On Sun, May 24, 2020 at 02:56:35AM -0400, Keno Fischer wrote: > Just ran into this issue again, with what I think may be most compelling > example yet why this is problematic: > > The tracee incurred a signal, we PTRACE_SYSEMU'd to the rt_sigreturn, > which the tracer tried to emulate by applying

Re: arm64: Register modification during syscall entry/exit stop

2020-05-23 Thread Keno Fischer
Just ran into this issue again, with what I think may be most compelling example yet why this is problematic: The tracee incurred a signal, we PTRACE_SYSEMU'd to the rt_sigreturn, which the tracer tried to emulate by applying the state from the signal frame. However, the PTRACE_SYSEMU stop is a sy

Re: arm64: Register modification during syscall entry/exit stop

2020-05-22 Thread Keno Fischer
I got bitten by this again, so I decided to write up a simple example that shows the problem: https://gist.github.com/Keno/cde691b26e32373307fb7449ad305739 This runs the same child twice. First vanilla where it prints "Hello world". The second time, using a textbook ptrace example, to only print

Re: arm64: Register modification during syscall entry/exit stop

2020-05-20 Thread Will Deacon
Hi Keno, On Tue, May 19, 2020 at 04:37:34AM -0400, Keno Fischer wrote: > > Yes, we inherited this from ARM and I think strace relies on it. In > > hindsight, it is a little odd, although x7 is a parameter register in the > > PCS and so it won't be live on entry to a system call. > > I'm not famil

Re: arm64: Register modification during syscall entry/exit stop

2020-05-19 Thread Keno Fischer
Hi Will, > Yes, we inherited this from ARM and I think strace relies on it. In > hindsight, it is a little odd, although x7 is a parameter register in the > PCS and so it won't be live on entry to a system call. I'm not familiar with the PCS acronym, but I assume you mean the calling convention?

Re: arm64: Register modification during syscall entry/exit stop

2020-05-19 Thread Will Deacon
Hi Keno, On Mon, May 18, 2020 at 09:05:30PM -0400, Keno Fischer wrote: > Continuing my theme of "weird things I encounter > while trying to use ptrace on arm64", I ran into the > effect of the following code in the syscall entry/exit > reporting: > > ``` > /* > * A scratch register (ip(r12) on AA

arm64: Register modification during syscall entry/exit stop

2020-05-18 Thread Keno Fischer
Continuing my theme of "weird things I encounter while trying to use ptrace on arm64", I ran into the effect of the following code in the syscall entry/exit reporting: ``` /* * A scratch register (ip(r12) on AArch32, x7 on AArch64) is * used to denote syscall entry/exit: */ regno = (is_compat_task