[PATCH 4/5] ptrace: add PTRACE_SYSCALL_INFO_FLAG_SET_IP

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


This flag adds support for modifying the tracee's instruction pointer.

To do this, the tracer stores the new instruction pointer value in the
instruction_pointer field of the ptrace_syscall_info structure and
sets the PTRACE_SYSCALL_INFO_FLAG_SET_IP flag in the flags field.

This flag is introduced to avoid breaking existing code that uses
PTRACE_SET_SYSCALL_INFO and currently ignores the
instruction_pointer field.

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

diff --git a/include/uapi/linux/ptrace.h b/include/uapi/linux/ptrace.h
index 22489597a325..1d9c04447bb7 100644
--- a/include/uapi/linux/ptrace.h
+++ b/include/uapi/linux/ptrace.h
@@ -81,6 +81,10 @@ struct seccomp_metadata {
 #define PTRACE_SYSCALL_INFO_SECCOMP	3
 #define PTRACE_SYSCALL_INFO_SECCOMP_SKIP 4
 
+#define PTRACE_SYSCALL_INFO_FLAG_SET_IP (1 << 0)
+#define PTRACE_SYSCALL_INFO_FLAG_ALL \
+	(PTRACE_SYSCALL_INFO_FLAG_SET_IP)
+
 struct ptrace_syscall_info {
 	__u8 op;	/* PTRACE_SYSCALL_INFO_* */
 	__u8 reserved;
diff --git a/kernel/ptrace.c b/kernel/ptrace.c
index ff763c87e4f7..57a1731451d0 100644
--- a/kernel/ptrace.c
+++ b/kernel/ptrace.c
@@ -1147,8 +1147,8 @@ ptrace_set_syscall_info(struct task_struct *child, unsigned long user_size,
 	if (copy_from_user(&info, datavp, sizeof(info)))
 		return -EFAULT;
 
-	/* Reserved for future use. */
-	if (info.flags || info.reserved)
+	/* Unused flags and fields reserved for future use. */
+	if ((info.flags & ~PTRACE_SYSCALL_INFO_FLAG_ALL) || info.reserved)
 		return -EINVAL;
 
 	/*
@@ -1165,6 +1165,13 @@ ptrace_set_syscall_info(struct task_struct *child, unsigned long user_size,
 			return -EINVAL;
 	}
 
+	if (info.flags & PTRACE_SYSCALL_INFO_FLAG_SET_IP) {
+		unsigned long ip = info.instruction_pointer;
+		if (ip != info.instruction_pointer)
+			return -ERANGE;
+		instruction_pointer_set(regs, ip);
+	}
+
 	switch (info.op) {
 	case PTRACE_SYSCALL_INFO_ENTRY:
 		return ptrace_set_syscall_info_entry(child, regs, &info);
-- 
2.53.0



More information about the Strace-devel mailing list