Skip to content

ptrace: introduce PTRACE_SET_SYSCALL_INFO API

Dmitry V. Levin linux-api linux-arch linux-csky linux-hexagon linux-kselftest linux-m68k linux-mips linux-parisc linux-riscv linux-s390 linux-sh linux-snps-arc linux-um linuxppc-dev lkml loongarch openrisc sparclinux 7 versions – In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v7 Latest6 patches 10 repliesIn review 5 of 6 applied
  2. v66 patches 8 repliesSuperseded
  3. v57 patches 2 repliesSuperseded
Earlier versions · 4
VersionPostedPatchesRepliesStatus
v47 patches6 repliesSuperseded
v36 patches10 repliesSuperseded
v20 of 7 patches0 repliesSuperseded
v16 patches12 repliesSuperseded

Changes in v7 from the cover letter

* csky: Fix typo in comment
* mips: syscall_set_arguments: Remove mips_syscall_is_indirect check
* mips: syscall_set_nr: Reword comment
* mips: Add Reviewed-by
* v6: https://lore.kernel.org/all/[email protected]/

Patches in v7 5 of 6 applied

#Subject and filesSizeRepliesApplied
1/6hexagon: add syscall_set_return_value()arch/hexagon/include/asm/syscall.h+7 -00 repliesApplied
2/6syscall.h: add syscall_set_arguments()arch/arc/include/asm/syscall.h arch/arm/include/asm/syscall.h arch/arm64/include/asm/syscall.h +16 more+253 -07 replies
3/6syscall.h: introduce syscall_set_nr()arch/arc/include/asm/syscall.h arch/arm/include/asm/syscall.h arch/arm64/include/asm/syscall.h +17 more+198 -00 repliesApplied
4/6ptrace_get_syscall_info: factor out ptrace_get_syscall_info_opkernel/ptrace.c+34 -240 repliesApplied
5/6ptrace: introduce PTRACE_SET_SYSCALL_INFO requestinclude/uapi/linux/ptrace.h kernel/ptrace.c+126 -20 repliesApplied
6/6selftests/ptrace: add a test case for PTRACE_SET_SYSCALL_INFOtools/testing/selftests/ptrace/Makefile tools/testing/selftests/ptrace/set_syscall_info.c+520 -10 repliesApplied

Reviews trailers per patch

5 of 6 patches have a Reviewed-by or Acked-by.

PatchCharlie JenkinsHelge DellerMaciej W. RozyckiOleg NesterovAlexey GladkovEugene Syromiatnikov
1/6
2/6T-b R-b A-b R-b
3/6T-b R-b A-b R-b
4/6R-b
5/6R-b T-b R-b R-b R-b
6/6R-b

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes. Scroll the table sideways for all 6 reviewers.

Read the v7 thread

Cover letter [PATCH v7 0/6] ptrace: introduce PTRACE_SET_SYSCALL_INFO API

PTRACE_SET_SYSCALL_INFO is a generic ptrace API that complements PTRACE_GET_SYSCALL_INFO by letting the ptracer modify details of system calls the tracee is blocked in.

This API allows ptracers to obtain and modify system call details in a straightforward and architecture-agnostic way, providing a consistent way of manipulating the system call number and arguments across architectures.

As in case of PTRACE_GET_SYSCALL_INFO, PTRACE_SET_SYSCALL_INFO also does not aim to address numerous architecture-specific system call ABI peculiarities, like differences in the number of system call arguments for such system calls as pread64 and preadv.

The current implementation supports changing only those bits of system call information that are used by strace system call tampering, namely, syscall number, syscall arguments, and syscall return value.

Support of changing additional details returned by PTRACE_GET_SYSCALL_INFO, such as instruction pointer and stack pointer, could be added later if needed, by using struct ptrace_syscall_info.flags to specify the additional details that should be set. Currently, "flags" and "reserved" fields of struct ptrace_syscall_info must be initialized with zeroes; "arch", "instruction_pointer", and "stack_pointer" fields are currently ignored.

PTRACE_SET_SYSCALL_INFO currently supports only PTRACE_SYSCALL_INFO_ENTRY, PTRACE_SYSCALL_INFO_EXIT, and PTRACE_SYSCALL_INFO_SECCOMP operations. Other operations could be added later if needed.

Ideally, PTRACE_SET_SYSCALL_INFO should have been introduced along with PTRACE_GET_SYSCALL_INFO, but it didn't happen. The last straw that convinced me to implement PTRACE_SET_SYSCALL_INFO was apparent failure to provide an API of changing the first system call argument on riscv architecture [1].

ptrace(2) man page:

long ptrace(enum __ptrace_request request, pid_t pid, void *addr, void *data);
...
PTRACE_SET_SYSCALL_INFO
Modify information about the system call that caused the stop. The "data" argument is a pointer to struct ptrace_syscall_info that specifies the system call information to be set.
The "addr" argument should be set to sizeof(struct ptrace_syscall_info)).

[1] https://lore.kernel.org/all/[email protected]/

Notes:
v7:
* csky: Fix typo in comment
* mips: syscall_set_arguments: Remove mips_syscall_is_indirect check
* mips: syscall_set_nr: Reword comment
* mips: Add Reviewed-by
* v6: https://lore.kernel.org/all/[email protected]/

v6:
* mips: Submit mips_get_syscall_arg() o32 fix via mips tree to get it merged into v6.14-rc3
* Rebase to v6.14-rc3
* v5: https://lore.kernel.org/all/[email protected]/

v5:
* ptrace: Extend the commit message to say that the new API does not aim to address numerous architecture-specific syscall ABI peculiarities
* selftests: Add a workaround for s390 16-bit syscall numbers
* parisc: Add Acked-by
* v4: https://lore.kernel.org/all/[email protected]/

v4:
* Split out syscall_set_return_value() for hexagon into a separate patch
* s390: Change the style of syscall_set_arguments() implementation as requested
* ptrace: Add Reviewed-by
* v3: https://lore.kernel.org/all/[email protected]/

v3:
* powerpc: Submit syscall_set_return_value() fix for "sc" case separately
* mips: Do not introduce erroneous argument truncation on mips n32, add a detailed description to the commit message of the mips_get_syscall_arg() change
* ptrace: Add explicit padding to the end of struct ptrace_syscall_info, simplify obtaining of user ptrace_syscall_info,
do not introduce PTRACE_SYSCALL_INFO_SIZE_VER0
* ptrace: Change the return type of ptrace_set_syscall_info_* functions from "unsigned long" to "int"
* ptrace: Add -ERANGE check to ptrace_set_syscall_info_exit(), add comments to -ERANGE checks
* ptrace: Update comments about supported syscall stops
* selftests: Extend set_syscall_info test, fix for mips n32
* riscv: Add Tested-by and Reviewed-by

v2:
* Add patch to fix syscall_set_return_value() on powerpc
* Add patch to fix mips_get_syscall_arg() on mips
* Add syscall_set_return_value() implementation on hexagon
* Add syscall_set_return_value() invocation to syscall_set_nr() on arm and arm64.
* Fix syscall_set_nr() and mips_set_syscall_arg() on mips
* Add a comment to syscall_set_nr() on arc, powerpc, s390, sh, and sparc
* Remove redundant ptrace_syscall_info.op assignments in ptrace_get_syscall_info_*
* Minor style tweaks in ptrace_get_syscall_info_op()
* Remove syscall_set_return_value() invocation from ptrace_set_syscall_info_entry()
* Skip syscall_set_arguments() invocation in case of syscall number -1 in ptrace_set_syscall_info_entry()
* Split ptrace_syscall_info.reserved into ptrace_syscall_info.reserved and ptrace_syscall_info.flags
* Use __kernel_ulong_t instead of unsigned long in set_syscall_info test

Dmitry V. Levin (6):
hexagon: add syscall_set_return_value()
syscall.h: add syscall_set_arguments()
syscall.h: introduce syscall_set_nr()
ptrace_get_syscall_info: factor out ptrace_get_syscall_info_op
ptrace: introduce PTRACE_SET_SYSCALL_INFO request selftests/ptrace: add a test case for PTRACE_SET_SYSCALL_INFO

 arch/arc/include/asm/syscall.h                |  25 +
 arch/arm/include/asm/syscall.h                |  37 ++
 arch/arm64/include/asm/syscall.h              |  29 +
 arch/csky/include/asm/syscall.h               |  13 +
 arch/hexagon/include/asm/syscall.h            |  21 +
 arch/loongarch/include/asm/syscall.h          |  15 +
 arch/m68k/include/asm/syscall.h               |   7 +
 arch/microblaze/include/asm/syscall.h         |   7 +
 arch/mips/include/asm/syscall.h               |  43 ++
 arch/nios2/include/asm/syscall.h              |  16 +
 arch/openrisc/include/asm/syscall.h           |  13 +
 arch/parisc/include/asm/syscall.h             |  19 +
 arch/powerpc/include/asm/syscall.h            |  20 +
 arch/riscv/include/asm/syscall.h              |  16 +
 arch/s390/include/asm/syscall.h               |  21 +
 arch/sh/include/asm/syscall_32.h              |  24 +
 arch/sparc/include/asm/syscall.h              |  22 +
 arch/um/include/asm/syscall-generic.h         |  19 +
 arch/x86/include/asm/syscall.h                |  43 ++
 arch/xtensa/include/asm/syscall.h             |  18 +
 include/asm-generic/syscall.h                 |  30 +
 include/uapi/linux/ptrace.h                   |   7 +-
 kernel/ptrace.c                               | 179 +++++-
 tools/testing/selftests/ptrace/Makefile       |   2 +-
 .../selftests/ptrace/set_syscall_info.c       | 519 ++++++++++++++++++
 25 files changed, 1138 insertions(+), 27 deletions(-)
 create mode 100644 tools/testing/selftests/ptrace/set_syscall_info.c

base-commit: 7eb172143d5508b4da468ed59ee857c6e5e01da6

Signature · 1 line
ldv