From: "Dmitry V. Levin" <ldv@strace.io>
To: Oleg Nesterov <oleg@redhat.com>
Cc: Alexey Gladkov <legion@kernel.org>,
Eugene Syromyatnikov <evgsyr@gmail.com>,
Mike Frysinger <vapier@gentoo.org>,
Renzo Davoli <renzo@cs.unibo.it>,
Davide Berardi <berardi.dav@gmail.com>,
strace-devel@lists.strace.io, linux-kernel@vger.kernel.org
Subject: [PATCH v3 4/6] ptrace_get_syscall_info: factor out ptrace_get_syscall_info_op
Date: Tue, 28 Jan 2025 11:16:43 +0200 [thread overview]
Message-ID: <20250128091643.GD8601@strace.io> (raw)
In-Reply-To: <20250128091445.GA8257@strace.io>
Move the code that calculates the type of the system call stop
out of ptrace_get_syscall_info() into a separate function
ptrace_get_syscall_info_op() which is going to be used later
to implement PTRACE_SET_SYSCALL_INFO API.
Signed-off-by: Dmitry V. Levin <ldv@strace.io>
---
kernel/ptrace.c | 58 +++++++++++++++++++++++++++++--------------------
1 file changed, 34 insertions(+), 24 deletions(-)
diff --git a/kernel/ptrace.c b/kernel/ptrace.c
index d5f89f9ef29f..22e7d74cf4cd 100644
--- a/kernel/ptrace.c
+++ b/kernel/ptrace.c
@@ -921,7 +921,6 @@ ptrace_get_syscall_info_entry(struct task_struct *child, struct pt_regs *regs,
unsigned long args[ARRAY_SIZE(info->entry.args)];
int i;
- info->op = PTRACE_SYSCALL_INFO_ENTRY;
info->entry.nr = syscall_get_nr(child, regs);
syscall_get_arguments(child, regs, args);
for (i = 0; i < ARRAY_SIZE(args); i++)
@@ -943,7 +942,6 @@ ptrace_get_syscall_info_seccomp(struct task_struct *child, struct pt_regs *regs,
* diverge significantly enough.
*/
ptrace_get_syscall_info_entry(child, regs, info);
- info->op = PTRACE_SYSCALL_INFO_SECCOMP;
info->seccomp.ret_data = child->ptrace_message;
/* ret_data is the last field in struct ptrace_syscall_info.seccomp */
@@ -954,7 +952,6 @@ static unsigned long
ptrace_get_syscall_info_exit(struct task_struct *child, struct pt_regs *regs,
struct ptrace_syscall_info *info)
{
- info->op = PTRACE_SYSCALL_INFO_EXIT;
info->exit.rval = syscall_get_error(child, regs);
info->exit.is_error = !!info->exit.rval;
if (!info->exit.is_error)
@@ -965,19 +962,8 @@ ptrace_get_syscall_info_exit(struct task_struct *child, struct pt_regs *regs,
}
static int
-ptrace_get_syscall_info(struct task_struct *child, unsigned long user_size,
- void __user *datavp)
+ptrace_get_syscall_info_op(struct task_struct *child)
{
- struct pt_regs *regs = task_pt_regs(child);
- struct ptrace_syscall_info info = {
- .op = PTRACE_SYSCALL_INFO_NONE,
- .arch = syscall_get_arch(child),
- .instruction_pointer = instruction_pointer(regs),
- .stack_pointer = user_stack_pointer(regs),
- };
- unsigned long actual_size = offsetof(struct ptrace_syscall_info, entry);
- unsigned long write_size;
-
/*
* This does not need lock_task_sighand() to access
* child->last_siginfo because ptrace_freeze_traced()
@@ -988,18 +974,42 @@ ptrace_get_syscall_info(struct task_struct *child, unsigned long user_size,
case SIGTRAP | 0x80:
switch (child->ptrace_message) {
case PTRACE_EVENTMSG_SYSCALL_ENTRY:
- actual_size = ptrace_get_syscall_info_entry(child, regs,
- &info);
- break;
+ return PTRACE_SYSCALL_INFO_ENTRY;
case PTRACE_EVENTMSG_SYSCALL_EXIT:
- actual_size = ptrace_get_syscall_info_exit(child, regs,
- &info);
- break;
+ return PTRACE_SYSCALL_INFO_EXIT;
+ default:
+ return PTRACE_SYSCALL_INFO_NONE;
}
- break;
case SIGTRAP | (PTRACE_EVENT_SECCOMP << 8):
- actual_size = ptrace_get_syscall_info_seccomp(child, regs,
- &info);
+ return PTRACE_SYSCALL_INFO_SECCOMP;
+ default:
+ return PTRACE_SYSCALL_INFO_NONE;
+ }
+}
+
+static int
+ptrace_get_syscall_info(struct task_struct *child, unsigned long user_size,
+ void __user *datavp)
+{
+ struct pt_regs *regs = task_pt_regs(child);
+ struct ptrace_syscall_info info = {
+ .op = ptrace_get_syscall_info_op(child),
+ .arch = syscall_get_arch(child),
+ .instruction_pointer = instruction_pointer(regs),
+ .stack_pointer = user_stack_pointer(regs),
+ };
+ unsigned long actual_size = offsetof(struct ptrace_syscall_info, entry);
+ unsigned long write_size;
+
+ switch (info.op) {
+ case PTRACE_SYSCALL_INFO_ENTRY:
+ actual_size = ptrace_get_syscall_info_entry(child, regs, &info);
+ break;
+ case PTRACE_SYSCALL_INFO_EXIT:
+ actual_size = ptrace_get_syscall_info_exit(child, regs, &info);
+ break;
+ case PTRACE_SYSCALL_INFO_SECCOMP:
+ actual_size = ptrace_get_syscall_info_seccomp(child, regs, &info);
break;
}
--
ldv
next prev parent reply other threads:[~2025-01-28 9:16 UTC|newest]
Thread overview: 39+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-01-28 9:14 [PATCH v3 0/6] ptrace: introduce PTRACE_SET_SYSCALL_INFO API Dmitry V. Levin
2025-01-28 9:14 ` Dmitry V. Levin
2025-01-28 9:14 ` Dmitry V. Levin
2025-01-28 9:16 ` [PATCH v3 1/6] mips: fix mips_get_syscall_arg() for o32 Dmitry V. Levin
2025-01-28 9:16 ` [PATCH v3 2/6] syscall.h: add syscall_set_arguments() and syscall_set_return_value() Dmitry V. Levin
2025-01-28 9:16 ` Dmitry V. Levin
2025-01-28 9:16 ` Dmitry V. Levin
2025-01-28 15:04 ` Christophe Leroy
2025-01-28 15:04 ` Christophe Leroy
2025-01-28 15:04 ` Christophe Leroy
2025-01-28 16:17 ` Dmitry V. Levin
2025-01-28 16:17 ` Dmitry V. Levin
2025-01-28 16:17 ` Dmitry V. Levin
2025-01-30 8:33 ` Sven Schnelle
2025-01-30 8:33 ` Sven Schnelle
2025-01-30 8:33 ` Sven Schnelle
2025-01-30 11:22 ` Dmitry V. Levin
2025-01-30 11:22 ` Dmitry V. Levin
2025-01-30 11:22 ` Dmitry V. Levin
2025-01-30 11:36 ` Sven Schnelle
2025-01-30 11:36 ` Sven Schnelle
2025-01-30 11:36 ` Sven Schnelle
2025-01-28 9:16 ` [PATCH v3 3/6] syscall.h: introduce syscall_set_nr() Dmitry V. Levin
2025-01-28 9:16 ` Dmitry V. Levin
2025-01-28 9:16 ` Dmitry V. Levin
2025-01-28 15:13 ` Christophe Leroy
2025-01-28 15:13 ` Christophe Leroy
2025-01-28 15:13 ` Christophe Leroy
2025-01-28 16:25 ` Dmitry V. Levin
2025-01-28 16:25 ` Dmitry V. Levin
2025-01-28 16:25 ` Dmitry V. Levin
2025-01-28 9:16 ` Dmitry V. Levin [this message]
2025-01-28 9:16 ` [PATCH v3 5/6] ptrace: introduce PTRACE_SET_SYSCALL_INFO request Dmitry V. Levin
2025-01-28 15:21 ` Christophe Leroy
2025-01-28 15:58 ` Dmitry V. Levin
2025-01-28 9:16 ` [PATCH v3 6/6] selftests/ptrace: add a test case for PTRACE_SET_SYSCALL_INFO Dmitry V. Levin
2025-01-29 18:51 ` [PATCH v3 0/6] ptrace: introduce PTRACE_SET_SYSCALL_INFO API Oleg Nesterov
2025-01-29 18:51 ` Oleg Nesterov
2025-01-29 18:51 ` Oleg Nesterov
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=20250128091643.GD8601@strace.io \
--to=ldv@strace.io \
--cc=berardi.dav@gmail.com \
--cc=evgsyr@gmail.com \
--cc=legion@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=oleg@redhat.com \
--cc=renzo@cs.unibo.it \
--cc=strace-devel@lists.strace.io \
--cc=vapier@gentoo.org \
/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.