ptrace/um: Replace PT_DTRACE with TIF_SINGLESTEP
authorEric W. Biederman <ebiederm@xmission.com>
Tue, 26 Apr 2022 21:30:17 +0000 (16:30 -0500)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 9 Jun 2022 08:22:29 +0000 (10:22 +0200)
commit c200e4bb44e80b343c09841e7caaaca0aac5e5fa upstream.

User mode linux is the last user of the PT_DTRACE flag.  Using the flag to indicate
single stepping is a little confusing and worse changing tsk->ptrace without locking
could potentionally cause problems.

So use a thread info flag with a better name instead of flag in tsk->ptrace.

Remove the definition PT_DTRACE as uml is the last user.

Cc: stable@vger.kernel.org
Acked-by: Johannes Berg <johannes@sipsolutions.net>
Tested-by: Kees Cook <keescook@chromium.org>
Reviewed-by: Oleg Nesterov <oleg@redhat.com>
Link: https://lkml.kernel.org/r/20220505182645.497868-3-ebiederm@xmission.com
Signed-off-by: "Eric W. Biederman" <ebiederm@xmission.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
arch/um/include/asm/thread_info.h
arch/um/kernel/exec.c
arch/um/kernel/process.c
arch/um/kernel/ptrace.c
arch/um/kernel/signal.c
include/linux/ptrace.h

index 3b1cb8b3b1864deca470f97bcc28b2849b788085..e610e932cfe1e3fa4444b1bff8cf975ebdd7a300 100644 (file)
@@ -64,6 +64,7 @@ static inline struct thread_info *current_thread_info(void)
 #define TIF_RESTORE_SIGMASK    7
 #define TIF_NOTIFY_RESUME      8
 #define TIF_SECCOMP            9       /* secure computing */
+#define TIF_SINGLESTEP         10      /* single stepping userspace */
 
 #define _TIF_SYSCALL_TRACE     (1 << TIF_SYSCALL_TRACE)
 #define _TIF_SIGPENDING                (1 << TIF_SIGPENDING)
@@ -72,5 +73,6 @@ static inline struct thread_info *current_thread_info(void)
 #define _TIF_MEMDIE            (1 << TIF_MEMDIE)
 #define _TIF_SYSCALL_AUDIT     (1 << TIF_SYSCALL_AUDIT)
 #define _TIF_SECCOMP           (1 << TIF_SECCOMP)
+#define _TIF_SINGLESTEP                (1 << TIF_SINGLESTEP)
 
 #endif
index 4d84981003419b7aa8d57de8f8f73238105b26e0..335dcb2d63e78368d89012370a4b2a37253e228d 100644 (file)
@@ -42,7 +42,7 @@ void start_thread(struct pt_regs *regs, unsigned long eip, unsigned long esp)
 {
        PT_REGS_IP(regs) = eip;
        PT_REGS_SP(regs) = esp;
-       current->ptrace &= ~PT_DTRACE;
+       clear_thread_flag(TIF_SINGLESTEP);
 #ifdef SUBARCH_EXECVE1
        SUBARCH_EXECVE1(regs->regs);
 #endif
index 457a38db368b7d77ed4b13ccace09d0939a905f4..b3fbfca494006c8f5820eb7685752cf4aacc598a 100644 (file)
@@ -339,7 +339,7 @@ int singlestepping(void * t)
 {
        struct task_struct *task = t ? t : current;
 
-       if (!(task->ptrace & PT_DTRACE))
+       if (!test_thread_flag(TIF_SINGLESTEP))
                return 0;
 
        if (task->thread.singlestep_syscall)
index b425f47bddbb3f22465efe4534d1fb5104d75ee8..d37802ced563674d97ca6b29a2dfc4e90164eb85 100644 (file)
@@ -12,7 +12,7 @@
 
 void user_enable_single_step(struct task_struct *child)
 {
-       child->ptrace |= PT_DTRACE;
+       set_tsk_thread_flag(child, TIF_SINGLESTEP);
        child->thread.singlestep_syscall = 0;
 
 #ifdef SUBARCH_SET_SINGLESTEPPING
@@ -22,7 +22,7 @@ void user_enable_single_step(struct task_struct *child)
 
 void user_disable_single_step(struct task_struct *child)
 {
-       child->ptrace &= ~PT_DTRACE;
+       clear_tsk_thread_flag(child, TIF_SINGLESTEP);
        child->thread.singlestep_syscall = 0;
 
 #ifdef SUBARCH_SET_SINGLESTEPPING
@@ -121,7 +121,7 @@ static void send_sigtrap(struct uml_pt_regs *regs, int error_code)
 }
 
 /*
- * XXX Check PT_DTRACE vs TIF_SINGLESTEP for singlestepping check and
+ * XXX Check TIF_SINGLESTEP for singlestepping check and
  * PT_PTRACED vs TIF_SYSCALL_TRACE for syscall tracing check
  */
 int syscall_trace_enter(struct pt_regs *regs)
@@ -145,7 +145,7 @@ void syscall_trace_leave(struct pt_regs *regs)
        audit_syscall_exit(regs);
 
        /* Fake a debug trap */
-       if (ptraced & PT_DTRACE)
+       if (test_thread_flag(TIF_SINGLESTEP))
                send_sigtrap(&regs->regs, 0);
 
        if (!test_thread_flag(TIF_SYSCALL_TRACE))
index 88cd9b5c1b74442f72658b6740e24e9869e5c5f1..ae4658f576ab7ad26658187f130e4d4d57d48267 100644 (file)
@@ -53,7 +53,7 @@ static void handle_signal(struct ksignal *ksig, struct pt_regs *regs)
        unsigned long sp;
        int err;
 
-       if ((current->ptrace & PT_DTRACE) && (current->ptrace & PT_PTRACED))
+       if (test_thread_flag(TIF_SINGLESTEP) && (current->ptrace & PT_PTRACED))
                singlestep = 1;
 
        /* Did we come from a system call? */
@@ -128,7 +128,7 @@ void do_signal(struct pt_regs *regs)
         * on the host.  The tracing thread will check this flag and
         * PTRACE_SYSCALL if necessary.
         */
-       if (current->ptrace & PT_DTRACE)
+       if (test_thread_flag(TIF_SINGLESTEP))
                current->thread.singlestep_syscall =
                        is_syscall(PT_REGS_IP(&current->thread.regs));
 
index b5ebf6c012924db8949667e0e10a2cc99712f060..99610cc363d11c1ca8d10ca063989e07f02ac86c 100644 (file)
@@ -30,7 +30,6 @@ extern int ptrace_access_vm(struct task_struct *tsk, unsigned long addr,
 
 #define PT_SEIZED      0x00010000      /* SEIZE used, enable new behavior */
 #define PT_PTRACED     0x00000001
-#define PT_DTRACE      0x00000002      /* delayed trace (used on m68k, i386) */
 
 #define PT_OPT_FLAG_SHIFT      3
 /* PT_TRACE_* event enable flags */