Multiple syscalls are liable to PTRACE_EVENT_* tracing and thus require full user context saved on the kernel stack. We only save those registers not preserved by C code currently. do_exit() calls ptrace_stop() which may require access to all saved registers. Add code to save additional registers in the switch_stack struct for exit and exit_group syscalls (similar to what is already done for fork, vfork and clone3). According to Eric's analysis, execve and execveat can be traced as well, so have been given the same treatment. Tested on both ARAnyM and Falcon hardware. CC: Eric W. Biederman <ebiederm@xxxxxxxxxxxx> CC: Linus Torvalds <torvalds@xxxxxxxxxxxxxxxxxxxx> CC: Andreas Schwab <schwab@xxxxxxxxxxxxxx> Signed-off-by: Michael Schmitz <schmitzmic@xxxxxxxxx> -- Changes from v2: - drop handling of io_uring_setup syscall Changes from v1: - added exec, execve and io_uring_setup syscalls - save extra registers around kworker thread calls drop io_uring_setup handling --- arch/m68k/kernel/entry.S | 28 ++++++++++++++++++++++++++++ arch/m68k/kernel/process.c | 33 +++++++++++++++++++++++++++++++++ arch/m68k/kernel/syscalls/syscall.tbl | 8 ++++---- 3 files changed, 65 insertions(+), 4 deletions(-) diff --git a/arch/m68k/kernel/entry.S b/arch/m68k/kernel/entry.S index 9dd76fb..275452a 100644 --- a/arch/m68k/kernel/entry.S +++ b/arch/m68k/kernel/entry.S @@ -76,6 +76,34 @@ ENTRY(__sys_clone3) lea %sp@(28),%sp rts +ENTRY(__sys_exit) + SAVE_SWITCH_STACK + pea %sp@(SWITCH_STACK_SIZE) + jbsr m68k_exit + lea %sp@(28),%sp + rts + +ENTRY(__sys_exit_group) + SAVE_SWITCH_STACK + pea %sp@(SWITCH_STACK_SIZE) + jbsr m68k_exit_group + lea %sp@(28),%sp + rts + +ENTRY(__sys_execve) + SAVE_SWITCH_STACK + pea %sp@(SWITCH_STACK_SIZE) + jbsr m68k_execve + lea %sp@(28),%sp + rts + +ENTRY(__sys_execveat) + SAVE_SWITCH_STACK + pea %sp@(SWITCH_STACK_SIZE) + jbsr m68k_execveat + lea %sp@(28),%sp + rts + ENTRY(sys_sigreturn) SAVE_SWITCH_STACK movel %sp,%sp@- | switch_stack pointer diff --git a/arch/m68k/kernel/process.c b/arch/m68k/kernel/process.c index da83cc8..7dd0eea 100644 --- a/arch/m68k/kernel/process.c +++ b/arch/m68k/kernel/process.c @@ -138,6 +138,39 @@ asmlinkage int m68k_clone3(struct pt_regs *regs) return sys_clone3((struct clone_args __user *)regs->d1, regs->d2); } +/* + * Because extra registers are saved on the stack after the sys_exit() + * arguments, this C wrapper extracts them from pt_regs * and then calls the + * generic sys_exit() implementation. + */ +asmlinkage int m68k_exit(struct pt_regs *regs) +{ + return sys_exit(regs->d1); +} + +/* Same for sys_exit_group ... */ +asmlinkage int m68k_exit_group(struct pt_regs *regs) +{ + return sys_exit_group(regs->d1); +} + +/* Same for sys_exit_group ... */ +asmlinkage int m68k_execve(struct pt_regs *regs) +{ + return sys_execve((const char __user *)regs->d1, + (const char __user *const __user*)regs->d2, + (const char __user *const __user*)regs->d3); +} + +/* Same for sys_exit_group ... */ +asmlinkage int m68k_execveat(struct pt_regs *regs) +{ + return sys_execveat(regs->d1, (const char __user *)regs->d2, + (const char __user *const __user*)regs->d3, + (const char __user *const __user*)regs->d4, + regs->d5); +} + int copy_thread(unsigned long clone_flags, unsigned long usp, unsigned long arg, struct task_struct *p, unsigned long tls) { diff --git a/arch/m68k/kernel/syscalls/syscall.tbl b/arch/m68k/kernel/syscalls/syscall.tbl index 0dd019d..13dd02e 100644 --- a/arch/m68k/kernel/syscalls/syscall.tbl +++ b/arch/m68k/kernel/syscalls/syscall.tbl @@ -8,7 +8,7 @@ # The <abi> is always "common" for this file # 0 common restart_syscall sys_restart_syscall -1 common exit sys_exit +1 common exit __sys_exit 2 common fork __sys_fork 3 common read sys_read 4 common write sys_write @@ -18,7 +18,7 @@ 8 common creat sys_creat 9 common link sys_link 10 common unlink sys_unlink -11 common execve sys_execve +11 common execve __sys_execve 12 common chdir sys_chdir 13 common time sys_time32 14 common mknod sys_mknod @@ -254,7 +254,7 @@ 244 common io_submit sys_io_submit 245 common io_cancel sys_io_cancel 246 common fadvise64 sys_fadvise64 -247 common exit_group sys_exit_group +247 common exit_group __sys_exit_group 248 common lookup_dcookie sys_lookup_dcookie 249 common epoll_create sys_epoll_create 250 common epoll_ctl sys_epoll_ctl @@ -362,7 +362,7 @@ 352 common getrandom sys_getrandom 353 common memfd_create sys_memfd_create 354 common bpf sys_bpf -355 common execveat sys_execveat +355 common execveat __sys_execveat 356 common socket sys_socket 357 common socketpair sys_socketpair 358 common bind sys_bind -- 2.7.4