From: Bradley Morgan <bradley.morgan@linux.dev>
To: Renzo Davoli <renzo@cs.unibo.it>, linux-kernel@vger.kernel.org
Cc: Oleg Nesterov <oleg@redhat.com>,
Andrew Morton <akpm@linux-foundation.org>,
"Dmitry V . Levin" <ldv@strace.io>,
Alexey Gladkov <legion@kernel.org>,
Eugene Syromyatnikov <evgsyr@gmail.com>,
Charlie Jenkins <thecharlesjenkins@gmail.com>,
Shuah Khan <shuah@kernel.org>,
strace-devel@lists.strace.io, linux-api@vger.kernel.org,
linux-kselftest@vger.kernel.org
Subject: Re: [PATCH v3 2/2] selftests/ptrace: check that PTRACE_SET_SYSCALL_INFO rejects invalid error values
Date: Sun, 15 Nov 2026 16:17:06 +0000 [thread overview]
Message-ID: <DEC23DE6-5D6B-42FA-8A31-2914B730C777@linux.dev> (raw)
In-Reply-To: <20261115152703.416254-3-renzo@cs.unibo.it>
On 15 November 2026 15:27:00 GMT, 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.
>
>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
>+};
yeah sure. Bit of a odd way to show error codes but okie dokie.
>+
>+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);
>+
Reviewed-by: Bradley Morgan <bradley.morgan@linux.dev>
A feature suggestion on the table here is that you can modify the
bad_error_rval[] parameter thru sysfs so you'd provide custom addresses or
custom whatever.
E.g:
Echoing 0 to the sysfs directory. Then checking dmesg to see if it passed
or if a hole happened.
> /* apply the changes */
> info.exit.is_error = set_exit->is_error;
> info.exit.rval = set_exit->rval;
>
--- Thanks!
prev parent reply other threads:[~2026-11-15 16:17 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-15 15:26 [PATCH v3 0/2] ptrace: reject out of range error values in PTRACE_SET_SYSCALL_INFO Renzo Davoli
2026-11-15 15:26 ` [PATCH v3 1/2] " Renzo Davoli
2026-11-16 12:58 ` Oleg Nesterov
2026-11-15 15:27 ` [PATCH v3 2/2] selftests/ptrace: check that PTRACE_SET_SYSCALL_INFO rejects invalid error values Renzo Davoli
2026-11-15 16:17 ` Bradley Morgan [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=DEC23DE6-5D6B-42FA-8A31-2914B730C777@linux.dev \
--to=bradley.morgan@linux.dev \
--cc=akpm@linux-foundation.org \
--cc=evgsyr@gmail.com \
--cc=ldv@strace.io \
--cc=legion@kernel.org \
--cc=linux-api@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=oleg@redhat.com \
--cc=renzo@cs.unibo.it \
--cc=shuah@kernel.org \
--cc=strace-devel@lists.strace.io \
--cc=thecharlesjenkins@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.