* [PATCH v4 0/2] ptrace: reject out of range error values in PTRACE_SET_SYSCALL_INFO
@ 2026-11-16 13:40 Renzo Davoli
2026-11-16 13:40 ` [PATCH v4 1/2] " Renzo Davoli
2026-11-16 13:40 ` [PATCH v4 2/2] selftests/ptrace: check that PTRACE_SET_SYSCALL_INFO rejects invalid error values Renzo Davoli
0 siblings, 2 replies; 7+ messages in thread
From: Renzo Davoli @ 2026-11-16 13:40 UTC (permalink / raw)
To: linux-kernel
Cc: Renzo Davoli, Oleg Nesterov, Andrew Morton, Dmitry V . Levin,
Alexey Gladkov, Eugene Syromyatnikov, Charlie Jenkins,
Bradley Morgan, Shuah Khan, strace-devel, linux-api,
linux-kselftest
With is_error set, PTRACE_SET_SYSCALL_INFO passes info.exit.rval to
syscall_set_return_value() as an "int" error without checking it: a
positive value, or on 64-bit one outside the "int" range, turns the
error into a success or is truncated.
Patch 1 rejects with -ERANGE any error value outside [-MAX_ERRNO, -1].
Patch 2 adds a test case for this to the set_syscall_info selftest.
This series is independent of the PTRACE_SET_SYSCALL_INFO seccomp skip
and SET_IP series: they apply on top of each other in either order.
Testing (x86_64, QEMU): tools/testing/selftests/ptrace/set_syscall_info
passes 1/1 with this series applied.
Changes in v4:
* patch 1: use !IS_ERR_VALUE(rval) instead of open-coding the range
check, no functional change. Thanks to Oleg Nesterov for the
suggestion.
* rebased on current mainline (23c62304dde2)
* added Reviewed-by of Bradley Morgan to patch 2
Changes in v3:
* added Reviewed-by of Dmitry V. Levin and Bradley Morgan to patch 1
* new patch 2: selftest, as suggested by Dmitry V. Levin
Changes in v2:
* shorter commit message and comment, dropped Assisted-by
(Bradley Morgan)
v3: https://lore.kernel.org/lkml/20261115152703.416254-1-renzo@cs.unibo.it/
v2: https://lore.kernel.org/lkml/20261115082540.385386-1-renzo@cs.unibo.it/
v1: https://lore.kernel.org/lkml/20261114184842.373304-1-renzo@cs.unibo.it/
Renzo Davoli (2):
ptrace: reject out of range error values in PTRACE_SET_SYSCALL_INFO
selftests/ptrace: check that PTRACE_SET_SYSCALL_INFO rejects invalid
error values
kernel/ptrace.c | 4 ++
.../selftests/ptrace/set_syscall_info.c | 51 +++++++++++++++++++
2 files changed, 55 insertions(+)
base-commit: 23c62304dde29abe92013d85910d03a77dada35d
--
2.47.3
^ permalink raw reply [flat|nested] 7+ messages in thread* [PATCH v4 1/2] ptrace: reject out of range error values in PTRACE_SET_SYSCALL_INFO 2026-11-16 13:40 [PATCH v4 0/2] ptrace: reject out of range error values in PTRACE_SET_SYSCALL_INFO Renzo Davoli @ 2026-11-16 13:40 ` Renzo Davoli 2026-11-16 14:03 ` Oleg Nesterov 2026-11-16 13:40 ` [PATCH v4 2/2] selftests/ptrace: check that PTRACE_SET_SYSCALL_INFO rejects invalid error values Renzo Davoli 1 sibling, 1 reply; 7+ messages in thread From: Renzo Davoli @ 2026-11-16 13:40 UTC (permalink / raw) To: linux-kernel Cc: Renzo Davoli, Oleg Nesterov, Andrew Morton, Dmitry V . Levin, Alexey Gladkov, Eugene Syromyatnikov, Charlie Jenkins, Bradley Morgan, Shuah Khan, strace-devel, linux-api, linux-kselftest With is_error set, PTRACE_SET_SYSCALL_INFO passes info.exit.rval to syscall_set_return_value() as an "int" error without checking it: a positive value, or on 64-bit one outside the "int" range, turns the error into a success or is truncated. Reject with -ERANGE any error value outside [-MAX_ERRNO, -1]. Fixes: 26bb32768fe6 ("ptrace: introduce PTRACE_SET_SYSCALL_INFO request") Reviewed-by: Dmitry V. Levin <ldv@strace.io> Reviewed-by: Bradley Morgan <bradley.morgan@linux.dev> Signed-off-by: Renzo Davoli <renzo@cs.unibo.it> --- kernel/ptrace.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/kernel/ptrace.c b/kernel/ptrace.c index 3f2fe68ccb14..7d51cb60c091 100644 --- a/kernel/ptrace.c +++ b/kernel/ptrace.c @@ -1111,6 +1111,10 @@ ptrace_set_syscall_info_exit(struct task_struct *child, struct pt_regs *regs, if (rval != info->exit.rval) return -ERANGE; + /* An error must be a negative errno value. */ + if (info->exit.is_error && !IS_ERR_VALUE(rval)) + return -ERANGE; + if (info->exit.is_error) syscall_set_return_value(child, regs, rval, 0); else -- 2.47.3 ^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH v4 1/2] ptrace: reject out of range error values in PTRACE_SET_SYSCALL_INFO 2026-11-16 13:40 ` [PATCH v4 1/2] " Renzo Davoli @ 2026-11-16 14:03 ` Oleg Nesterov 0 siblings, 0 replies; 7+ messages in thread From: Oleg Nesterov @ 2026-11-16 14:03 UTC (permalink / raw) To: Renzo Davoli Cc: linux-kernel, Andrew Morton, Dmitry V . Levin, Alexey Gladkov, Eugene Syromyatnikov, Charlie Jenkins, Bradley Morgan, Shuah Khan, strace-devel, linux-api, linux-kselftest On 11/16, Renzo Davoli wrote: > > --- a/kernel/ptrace.c > +++ b/kernel/ptrace.c > @@ -1111,6 +1111,10 @@ ptrace_set_syscall_info_exit(struct task_struct *child, struct pt_regs *regs, > if (rval != info->exit.rval) > return -ERANGE; > > + /* An error must be a negative errno value. */ > + if (info->exit.is_error && !IS_ERR_VALUE(rval)) > + return -ERANGE; Reviewed-by: Oleg Nesterov <oleg@redhat.com> (I think you can even drop the comment, IS_ERR_VALUE() is self-explanatory) ^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH v4 2/2] selftests/ptrace: check that PTRACE_SET_SYSCALL_INFO rejects invalid error values 2026-11-16 13:40 [PATCH v4 0/2] ptrace: reject out of range error values in PTRACE_SET_SYSCALL_INFO Renzo Davoli 2026-11-16 13:40 ` [PATCH v4 1/2] " Renzo Davoli @ 2026-11-16 13:40 ` Renzo Davoli 2026-11-16 23:36 ` Andrew Morton 1 sibling, 1 reply; 7+ messages in thread From: Renzo Davoli @ 2026-11-16 13:40 UTC (permalink / raw) To: linux-kernel Cc: Renzo Davoli, Oleg Nesterov, Andrew Morton, Dmitry V . Levin, Alexey Gladkov, Eugene Syromyatnikov, Charlie Jenkins, Bradley Morgan, Shuah Khan, strace-devel, linux-api, linux-kselftest At every exit stop of the set_syscall_info test, try to set with is_error set a few values outside [-MAX_ERRNO, -1], check that PTRACE_SET_SYSCALL_INFO fails with ERANGE and that the return value of the system call is left untouched. Reviewed-by: Bradley Morgan <bradley.morgan@linux.dev> Signed-off-by: Renzo Davoli <renzo@cs.unibo.it> --- .../selftests/ptrace/set_syscall_info.c | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/tools/testing/selftests/ptrace/set_syscall_info.c b/tools/testing/selftests/ptrace/set_syscall_info.c index 1cc411a41cd6..366ef0ec228f 100644 --- a/tools/testing/selftests/ptrace/set_syscall_info.c +++ b/tools/testing/selftests/ptrace/set_syscall_info.c @@ -126,6 +126,54 @@ check_psi_exit(struct __test_metadata *_metadata, } } +/* Error values that PTRACE_SET_SYSCALL_INFO must reject with ERANGE. */ +static const long long bad_error_rval[] = { + 0, + 1, + ESRCH, + -4095 - 1, /* -MAX_ERRNO - 1 */ + -2147483647LL - 1, +#if __SIZEOF_LONG__ > 4 + 0x100000000LL, + -0x100000000LL - ESRCH, +#endif +}; + +static void +check_psi_exit_bad_rval(struct __test_metadata *_metadata, + const struct ptrace_syscall_info *orig, + const struct si_exit *exp_exit) +{ + struct ptrace_syscall_info info; + unsigned int i; + + for (i = 0; i < ARRAY_SIZE(bad_error_rval); ++i) { + info = *orig; + info.exit.is_error = 1; + info.exit.rval = bad_error_rval[i]; + ASSERT_EQ(-1, sys_ptrace(PTRACE_SET_SYSCALL_INFO, + tracee_pid, sizeof(info), + (uintptr_t) &info)) { + LOG_KILL_TRACEE("PTRACE_SET_SYSCALL_INFO: error rval %lld accepted", + bad_error_rval[i]); + } + ASSERT_EQ(ERANGE, errno) { + LOG_KILL_TRACEE("PTRACE_SET_SYSCALL_INFO: error rval %lld: %m", + bad_error_rval[i]); + } + + /* the return value must be left untouched */ + memset(&info, 0, sizeof(info)); + info.op = 0xff; + ASSERT_LT(0, sys_ptrace(PTRACE_GET_SYSCALL_INFO, tracee_pid, + sizeof(info), (uintptr_t) &info)) { + LOG_KILL_TRACEE("PTRACE_GET_SYSCALL_INFO: %m"); + } + check_psi_exit(_metadata, &info, exp_exit, + "PTRACE_SET_SYSCALL_INFO with bad error rval"); + } +} + TEST(set_syscall_info) { const pid_t tracer_pid = getpid(); @@ -476,6 +524,9 @@ TEST(set_syscall_info) check_psi_exit(_metadata, &info, exp_exit, "PTRACE_GET_SYSCALL_INFO #1"); + /* invalid error values must be rejected */ + check_psi_exit_bad_rval(_metadata, &info, exp_exit); + /* apply the changes */ info.exit.is_error = set_exit->is_error; info.exit.rval = set_exit->rval; -- 2.47.3 ^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH v4 2/2] selftests/ptrace: check that PTRACE_SET_SYSCALL_INFO rejects invalid error values 2026-11-16 13:40 ` [PATCH v4 2/2] selftests/ptrace: check that PTRACE_SET_SYSCALL_INFO rejects invalid error values Renzo Davoli @ 2026-11-16 23:36 ` Andrew Morton 2026-11-17 9:05 ` Renzo Davoli 0 siblings, 1 reply; 7+ messages in thread From: Andrew Morton @ 2026-11-16 23:36 UTC (permalink / raw) To: Renzo Davoli Cc: linux-kernel, Oleg Nesterov, Dmitry V . Levin, Alexey Gladkov, Eugene Syromyatnikov, Charlie Jenkins, Bradley Morgan, Shuah Khan, strace-devel, linux-api, linux-kselftest On Mon, 16 Nov 2026 14:40:46 +0100 Renzo Davoli <renzo@cs.unibo.it> wrote: > At every exit stop of the set_syscall_info test, try to set with > is_error set a few values outside [-MAX_ERRNO, -1], check that > PTRACE_SET_SYSCALL_INFO fails with ERANGE and that the return value > of the system call is left untouched. Thanks. LLM suggested a little fixup here, please check. From: Andrew Morton <akpm@linux-foundation.org> Subject: selftests/ptrace: test the lowest valid syscall error Date: Mon, 16 Nov 2026 22:27:14 +0000 PTRACE_SET_SYSCALL_INFO must reject values below -MAX_ERRNO while accepting -MAX_ERRNO itself. Name the bound locally for this userspace selftest, and add a successful exit-stop case at that boundary. Retain the existing -EISDIR case. The tracee checks the resulting errno. Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Cc: Renzo Davoli <renzo@cs.unibo.it> tools/testing/selftests/ptrace/set_syscall_info.c | 25 +++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) --- a/tools/testing/selftests/ptrace/set_syscall_info.c~selftests-ptrace-check-that-ptrace_set_syscall_info-rejects-invalid-error-values-fix +++ a/tools/testing/selftests/ptrace/set_syscall_info.c @@ -15,6 +15,8 @@ #include <linux/types.h> #include <linux/ptrace.h> +#define MAX_ERRNO 4095 + #if defined(_MIPS_SIM) && _MIPS_SIM == _MIPS_SIM_NABI32 /* * MIPS N32 is the only architecture where __kernel_ulong_t @@ -131,7 +133,7 @@ static const long long bad_error_rval[] 0, 1, ESRCH, - -4095 - 1, /* -MAX_ERRNO - 1 */ + -MAX_ERRNO - 1, -2147483647LL - 1, #if __SIZEOF_LONG__ > 4 0x100000000LL, @@ -325,6 +327,27 @@ TEST(set_syscall_info) } }, + /* change scno, change non-error rval to -MAX_ERRNO */ + { + { + { + __NR_chdir, + { + dummy[0], dummy[1], dummy[2], + dummy[3], dummy[4], dummy[5] + } + }, { + __NR_getppid, + { + dummy[0], dummy[1], dummy[2], + dummy[3], dummy[4], dummy[5] + } + } + }, { + { 0, tracer_pid }, { 1, -MAX_ERRNO } + } + }, + /* change scno and all args, change non-error rval */ { { _ ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v4 2/2] selftests/ptrace: check that PTRACE_SET_SYSCALL_INFO rejects invalid error values 2026-11-16 23:36 ` Andrew Morton @ 2026-11-17 9:05 ` Renzo Davoli 2026-11-17 9:51 ` Renzo Davoli 0 siblings, 1 reply; 7+ messages in thread From: Renzo Davoli @ 2026-11-17 9:05 UTC (permalink / raw) To: Andrew Morton Cc: linux-kernel, Oleg Nesterov, Dmitry V . Levin, Alexey Gladkov, Eugene Syromyatnikov, Charlie Jenkins, Bradley Morgan, Shuah Khan, strace-devel, linux-api, linux-kselftest On Mon, 16 Nov 2026 15:36:42 -0800 Andrew Morton <akpm@linux-foundation.org> wrote: > LLM suggested a little fixup here, please check. > > From: Andrew Morton <akpm@linux-foundation.org> > Subject: selftests/ptrace: test the lowest valid syscall error Thanks Andrew, the fixup is correct and a good addition: the test now covers both sides of the -MAX_ERRNO boundary. I tested it on top of v4 (x86_64, QEMU): set_syscall_info passes. Reviewed-by: Renzo Davoli <renzo@cs.unibo.it> Tested-by: Renzo Davoli <renzo@cs.unibo.it> renzo ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v4 2/2] selftests/ptrace: check that PTRACE_SET_SYSCALL_INFO rejects invalid error values 2026-11-17 9:05 ` Renzo Davoli @ 2026-11-17 9:51 ` Renzo Davoli 0 siblings, 0 replies; 7+ messages in thread From: Renzo Davoli @ 2026-11-17 9:51 UTC (permalink / raw) To: Andrew Morton Cc: linux-kernel, Oleg Nesterov, Dmitry V . Levin, Alexey Gladkov, Eugene Syromyatnikov, Charlie Jenkins, Bradley Morgan, Shuah Khan, strace-devel, linux-api, linux-kselftest On Tue, Nov 17, 2026 at 10:05:37AM +0100, Renzo Davoli wrote: > Thanks Andrew, the fixup is correct and a good addition: the test now > covers both sides of the -MAX_ERRNO boundary. A follow-up for when the other two PTRACE_SET_SYSCALL_INFO series come up: [PATCH v11 0/3] PTRACE_SET_SYSCALL_INFO: add support for seccomp syscall skipping https://lore.kernel.org/lkml/20261114181923.370930-1-renzo@cs.unibo.it/ [PATCH v4 0/3] ptrace_set_syscall_info: add support for instruction pointer modification https://lore.kernel.org/lkml/20261114184720.373178-1-renzo@cs.unibo.it/ I tested the full stack on x86_64 (QEMU): this series with your fixup, then the syscall-skipping v11, then SET_IP v4 (which depends on syscall-skipping). set_syscall_info passes. There is one trivial textual conflict: your "#define MAX_ERRNO" lands right where syscall-skipping v11 patch 3/3 adds new #includes, so it does not apply with plain "git am"; "git am -3" resolves it, and the result differs from the stack without your fixup only by the fixup itself. If you prefer, I can send syscall-skipping v12 rebased on top of mm-nonmm-unstable. renzo ^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2026-11-17 9:51 UTC | newest] Thread overview: 7+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2026-11-16 13:40 [PATCH v4 0/2] ptrace: reject out of range error values in PTRACE_SET_SYSCALL_INFO Renzo Davoli 2026-11-16 13:40 ` [PATCH v4 1/2] " Renzo Davoli 2026-11-16 14:03 ` Oleg Nesterov 2026-11-16 13:40 ` [PATCH v4 2/2] selftests/ptrace: check that PTRACE_SET_SYSCALL_INFO rejects invalid error values Renzo Davoli 2026-11-16 23:36 ` Andrew Morton 2026-11-17 9:05 ` Renzo Davoli 2026-11-17 9:51 ` Renzo Davoli
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox