Message ID | 20210322225053.428615-3-avagin@gmail.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | arm64/ptrace: allow to get all registers on syscall traps | expand |
On Mon, Mar 22, 2021 at 03:50:51PM -0700, Andrei Vagin wrote: > diff --git a/arch/arm64/include/asm/ptrace.h b/arch/arm64/include/asm/ptrace.h > index d4cdf98ac003..1008f0fbc5ea 100644 > --- a/arch/arm64/include/asm/ptrace.h > +++ b/arch/arm64/include/asm/ptrace.h > @@ -184,6 +184,7 @@ struct pt_regs { > u64 pc; > u64 pstate; > u64 orig_x0; > + u64 orig_x7; > }; > }; > #ifdef __AARCH64EB__ > diff --git a/arch/arm64/include/uapi/asm/ptrace.h b/arch/arm64/include/uapi/asm/ptrace.h > index 3c118c5b0893..be7583ff5f4d 100644 > --- a/arch/arm64/include/uapi/asm/ptrace.h > +++ b/arch/arm64/include/uapi/asm/ptrace.h > @@ -91,6 +91,7 @@ struct user_pt_regs { > __u64 pc; > __u64 pstate; > __u64 orig_x0; > + __u64 orig_x7; > }; Same here. So unless I miss something, we better have a separate NT_ORIGREG (or some better name) regset to retrieve the additional registers. Or, if you want to get all of them in one go, just add a new one similar to NT_PRSTATUS but which restores x0 to orig_x0 and x7 to orig_x7. Sorry if this was already discussed. I had a brief look at the previous versions and couldn't see a user_pt_regs structure change, nor a suggestion to do so.
diff --git a/arch/arm64/include/asm/ptrace.h b/arch/arm64/include/asm/ptrace.h index d4cdf98ac003..1008f0fbc5ea 100644 --- a/arch/arm64/include/asm/ptrace.h +++ b/arch/arm64/include/asm/ptrace.h @@ -184,6 +184,7 @@ struct pt_regs { u64 pc; u64 pstate; u64 orig_x0; + u64 orig_x7; }; }; #ifdef __AARCH64EB__ diff --git a/arch/arm64/include/uapi/asm/ptrace.h b/arch/arm64/include/uapi/asm/ptrace.h index 3c118c5b0893..be7583ff5f4d 100644 --- a/arch/arm64/include/uapi/asm/ptrace.h +++ b/arch/arm64/include/uapi/asm/ptrace.h @@ -91,6 +91,7 @@ struct user_pt_regs { __u64 pc; __u64 pstate; __u64 orig_x0; + __u64 orig_x7; }; struct user_fpsimd_state { diff --git a/arch/arm64/kernel/ptrace.c b/arch/arm64/kernel/ptrace.c index 170f42fd6101..1ed5b4aa986b 100644 --- a/arch/arm64/kernel/ptrace.c +++ b/arch/arm64/kernel/ptrace.c @@ -1750,7 +1750,7 @@ static void tracehook_report_syscall(struct pt_regs *regs, enum ptrace_syscall_dir dir) { int regno; - unsigned long saved_reg; + u64 _saved_reg, *saved_reg; /* * We have some ABI weirdness here in the way that we handle syscall @@ -1768,19 +1768,25 @@ static void tracehook_report_syscall(struct pt_regs *regs, * - Syscall stops behave differently to seccomp and pseudo-step traps * (the latter do not nobble any registers). */ - regno = (is_compat_task() ? 12 : 7); - saved_reg = regs->regs[regno]; + if (is_compat_task()) { + regno = 12; + saved_reg = &_saved_reg; + } else { + regno = 7; + saved_reg = ®s->orig_x7; + } + *saved_reg = regs->regs[regno]; regs->regs[regno] = dir; if (dir == PTRACE_SYSCALL_ENTER) { if (tracehook_report_syscall_entry(regs)) forget_syscall(regs); - regs->regs[regno] = saved_reg; + regs->regs[regno] = *saved_reg; } else if (!test_thread_flag(TIF_SINGLESTEP)) { tracehook_report_syscall_exit(regs, 0); - regs->regs[regno] = saved_reg; + regs->regs[regno] = *saved_reg; } else { - regs->regs[regno] = saved_reg; + regs->regs[regno] = *saved_reg; /* * Signal a pseudo-step exception since we are stepping but
We have some ABI weirdness in the way that we handle syscall exit stops because we indicate whether or not the stop has been signalled from syscall entry or syscall exit by clobbering a general purpose register x7 in the tracee and restoring its old value after the stop. This behavior was inherited from ARM and it isn't common for other architectures. Now, we have PTRACE_GET_SYSCALL_INFO that gives all required information about system calls, so the hack with clobbering registers isn't needed anymore. This change instroduces orig_x7 in the user_pt_regs structure that will contains an origin value of the x7 register if the tracee is stopped in a system call.. Signed-off-by: Andrei Vagin <avagin@gmail.com> --- arch/arm64/include/asm/ptrace.h | 1 + arch/arm64/include/uapi/asm/ptrace.h | 1 + arch/arm64/kernel/ptrace.c | 18 ++++++++++++------ 3 files changed, 14 insertions(+), 6 deletions(-)