[PATCH 1/5] ptrace: add PTRACE_SYSCALL_INFO_SECCOMP_SKIP

Renzo Davoli renzo at cs.unibo.it
Wed Jul 1 15:05:54 UTC 2026


This patch extends PTRACE_SET_SYSCALL_INFO with support for skipping a system
call triggered via seccomp.

When the tracer retrieves a ptrace_syscall_info structure with
op == PTRACE_SYSCALL_INFO_SECCOMP, it may choose to skip the system
call by changing op to PTRACE_SYSCALL_INFO_SECCOMP_SKIP and
populating the exit union fields (rval and is_error) to define
the return value and error status for the tracee.

Signed-off-by: Renzo Davoli <renzo at cs.unibo.it>
---
 include/uapi/linux/ptrace.h |  1 +
 kernel/ptrace.c             | 28 +++++++++++++++++++++++++---
 2 files changed, 26 insertions(+), 3 deletions(-)

diff --git a/include/uapi/linux/ptrace.h b/include/uapi/linux/ptrace.h
index 5f8ef6156752..22489597a325 100644
--- a/include/uapi/linux/ptrace.h
+++ b/include/uapi/linux/ptrace.h
@@ -79,6 +79,7 @@ struct seccomp_metadata {
 #define PTRACE_SYSCALL_INFO_ENTRY	1
 #define PTRACE_SYSCALL_INFO_EXIT	2
 #define PTRACE_SYSCALL_INFO_SECCOMP	3
+#define PTRACE_SYSCALL_INFO_SECCOMP_SKIP 4
 
 struct ptrace_syscall_info {
 	__u8 op;	/* PTRACE_SYSCALL_INFO_* */
diff --git a/kernel/ptrace.c b/kernel/ptrace.c
index d041645d9d17..ff763c87e4f7 100644
--- a/kernel/ptrace.c
+++ b/kernel/ptrace.c
@@ -1119,12 +1119,22 @@ ptrace_set_syscall_info_exit(struct task_struct *child, struct pt_regs *regs,
 	return 0;
 }
 
+static int
+ptrace_set_syscall_info_seccomp_skip(struct task_struct *child,
+				     struct pt_regs *regs,
+				     struct ptrace_syscall_info *info)
+{
+	syscall_set_nr(child, regs, -1);
+	return ptrace_set_syscall_info_exit(child, regs, info);
+}
+
 static int
 ptrace_set_syscall_info(struct task_struct *child, unsigned long user_size,
 			const void __user *datavp)
 {
 	struct pt_regs *regs = task_pt_regs(child);
 	struct ptrace_syscall_info info;
+	int child_op;
 
 	if (user_size < sizeof(info))
 		return -EINVAL;
@@ -1141,9 +1151,19 @@ ptrace_set_syscall_info(struct task_struct *child, unsigned long user_size,
 	if (info.flags || info.reserved)
 		return -EINVAL;
 
-	/* Changing the type of the system call stop is not supported yet. */
-	if (ptrace_get_syscall_info_op(child) != info.op)
-		return -EINVAL;
+	/*
+	 * Changing the type of the system call stop is
+	 * not allowed, with the following exception:
+	 * PTRACE_SYSCALL_INFO_SECCOMP can be changed to
+	 * PTRACE_SYSCALL_INFO_SECCOMP_SKIP.
+	 */
+
+	child_op = ptrace_get_syscall_info_op(child);
+	if (child_op != info.op) {
+		if ((info.op != PTRACE_SYSCALL_INFO_SECCOMP_SKIP) ||
+				(child_op != PTRACE_SYSCALL_INFO_SECCOMP))
+			return -EINVAL;
+	}
 
 	switch (info.op) {
 	case PTRACE_SYSCALL_INFO_ENTRY:
@@ -1152,6 +1172,8 @@ ptrace_set_syscall_info(struct task_struct *child, unsigned long user_size,
 		return ptrace_set_syscall_info_exit(child, regs, &info);
 	case PTRACE_SYSCALL_INFO_SECCOMP:
 		return ptrace_set_syscall_info_seccomp(child, regs, &info);
+	case PTRACE_SYSCALL_INFO_SECCOMP_SKIP:
+		return ptrace_set_syscall_info_seccomp_skip(child, regs, &info);
 	default:
 		/* Other types of system call stops are not supported yet. */
 		return -EINVAL;
-- 
2.53.0



More information about the Strace-devel mailing list