Re: [PATCH 3/6] syscall.h: introduce syscall_set_nr()

Sven Schnelle
2025-01-10T07:39:11Z

"Dmitry V. Levin" <ldv@strace.io> writes:

> Similar to syscall_set_arguments() that complements
> syscall_get_arguments(), introduce syscall_set_nr()
> that complements syscall_get_nr().
>
> syscall_set_nr() is going to be needed along with
> syscall_set_arguments() on all HAVE_ARCH_TRACEHOOK
> architectures to implement PTRACE_SET_SYSCALL_INFO API.
>
> Signed-off-by: Dmitry V. Levin <ldv@strace.io>
> ---
> arch/arc/include/asm/syscall.h | 6 ++++++
> arch/arm/include/asm/syscall.h | 12 ++++++++++++
> arch/arm64/include/asm/syscall.h | 7 +++++++
> arch/hexagon/include/asm/syscall.h | 7 +++++++
> arch/loongarch/include/asm/syscall.h | 7 +++++++
> arch/m68k/include/asm/syscall.h | 7 +++++++
> arch/microblaze/include/asm/syscall.h | 7 +++++++
> arch/mips/include/asm/syscall.h | 7 +++++++
> arch/nios2/include/asm/syscall.h | 5 +++++
> arch/openrisc/include/asm/syscall.h | 6 ++++++
> arch/parisc/include/asm/syscall.h | 7 +++++++
> arch/powerpc/include/asm/syscall.h | 5 +++++
> arch/riscv/include/asm/syscall.h | 7 +++++++
> arch/s390/include/asm/syscall.h | 7 +++++++
> arch/sh/include/asm/syscall_32.h | 7 +++++++
> arch/sparc/include/asm/syscall.h | 7 +++++++
> arch/um/include/asm/syscall-generic.h | 5 +++++
> arch/x86/include/asm/syscall.h | 7 +++++++
> arch/xtensa/include/asm/syscall.h | 7 +++++++
> include/asm-generic/syscall.h | 14 ++++++++++++++
> 20 files changed, 144 insertions(+)
>
> diff --git a/arch/s390/include/asm/syscall.h b/arch/s390/include/asm/syscall.h
> index b3dd883699e7..1c0e349fd5c9 100644
> --- a/arch/s390/include/asm/syscall.h
> +++ b/arch/s390/include/asm/syscall.h
> @@ -24,6 +24,13 @@ static inline long syscall_get_nr(struct task_struct *task,
> (regs->int_code & 0xffff) : -1;
> }
>
> +static inline void syscall_set_nr(struct task_struct *task,
> + struct pt_regs *regs,
> + int nr)
> +{

I think there should be a

if (!test_pt_regs_flags(regs, PIF_SYSCALL))
return;

before the modification so a user can't accidentally change int_code
when ptrace stopped in a non-syscall path.

> + regs->int_code = (regs->int_code & ~0xffff) | (nr & 0xffff);
> +}
> +
> static inline void syscall_rollback(struct task_struct *task,
> struct pt_regs *regs)
> {