Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

ptrace/um: Replace PT_DTRACE with TIF_SINGLESTEP

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>

+10 -9
+2
arch/um/include/asm/thread_info.h
··· 60 60 #define TIF_RESTORE_SIGMASK 7 61 61 #define TIF_NOTIFY_RESUME 8 62 62 #define TIF_SECCOMP 9 /* secure computing */ 63 + #define TIF_SINGLESTEP 10 /* single stepping userspace */ 63 64 64 65 #define _TIF_SYSCALL_TRACE (1 << TIF_SYSCALL_TRACE) 65 66 #define _TIF_SIGPENDING (1 << TIF_SIGPENDING) ··· 69 68 #define _TIF_MEMDIE (1 << TIF_MEMDIE) 70 69 #define _TIF_SYSCALL_AUDIT (1 << TIF_SYSCALL_AUDIT) 71 70 #define _TIF_SECCOMP (1 << TIF_SECCOMP) 71 + #define _TIF_SINGLESTEP (1 << TIF_SINGLESTEP) 72 72 73 73 #endif
+1 -1
arch/um/kernel/exec.c
··· 43 43 { 44 44 PT_REGS_IP(regs) = eip; 45 45 PT_REGS_SP(regs) = esp; 46 - current->ptrace &= ~PT_DTRACE; 46 + clear_thread_flag(TIF_SINGLESTEP); 47 47 #ifdef SUBARCH_EXECVE1 48 48 SUBARCH_EXECVE1(regs->regs); 49 49 #endif
+1 -1
arch/um/kernel/process.c
··· 335 335 { 336 336 struct task_struct *task = t ? t : current; 337 337 338 - if (!(task->ptrace & PT_DTRACE)) 338 + if (!test_thread_flag(TIF_SINGLESTEP)) 339 339 return 0; 340 340 341 341 if (task->thread.singlestep_syscall)
+4 -4
arch/um/kernel/ptrace.c
··· 11 11 12 12 void user_enable_single_step(struct task_struct *child) 13 13 { 14 - child->ptrace |= PT_DTRACE; 14 + set_tsk_thread_flag(child, TIF_SINGLESTEP); 15 15 child->thread.singlestep_syscall = 0; 16 16 17 17 #ifdef SUBARCH_SET_SINGLESTEPPING ··· 21 21 22 22 void user_disable_single_step(struct task_struct *child) 23 23 { 24 - child->ptrace &= ~PT_DTRACE; 24 + clear_tsk_thread_flag(child, TIF_SINGLESTEP); 25 25 child->thread.singlestep_syscall = 0; 26 26 27 27 #ifdef SUBARCH_SET_SINGLESTEPPING ··· 120 120 } 121 121 122 122 /* 123 - * XXX Check PT_DTRACE vs TIF_SINGLESTEP for singlestepping check and 123 + * XXX Check TIF_SINGLESTEP for singlestepping check and 124 124 * PT_PTRACED vs TIF_SYSCALL_TRACE for syscall tracing check 125 125 */ 126 126 int syscall_trace_enter(struct pt_regs *regs) ··· 144 144 audit_syscall_exit(regs); 145 145 146 146 /* Fake a debug trap */ 147 - if (ptraced & PT_DTRACE) 147 + if (test_thread_flag(TIF_SINGLESTEP)) 148 148 send_sigtrap(&regs->regs, 0); 149 149 150 150 if (!test_thread_flag(TIF_SYSCALL_TRACE))
+2 -2
arch/um/kernel/signal.c
··· 53 53 unsigned long sp; 54 54 int err; 55 55 56 - if ((current->ptrace & PT_DTRACE) && (current->ptrace & PT_PTRACED)) 56 + if (test_thread_flag(TIF_SINGLESTEP) && (current->ptrace & PT_PTRACED)) 57 57 singlestep = 1; 58 58 59 59 /* Did we come from a system call? */ ··· 128 128 * on the host. The tracing thread will check this flag and 129 129 * PTRACE_SYSCALL if necessary. 130 130 */ 131 - if (current->ptrace & PT_DTRACE) 131 + if (test_thread_flag(TIF_SINGLESTEP)) 132 132 current->thread.singlestep_syscall = 133 133 is_syscall(PT_REGS_IP(&current->thread.regs)); 134 134
-1
include/linux/ptrace.h
··· 30 30 31 31 #define PT_SEIZED 0x00010000 /* SEIZE used, enable new behavior */ 32 32 #define PT_PTRACED 0x00000001 33 - #define PT_DTRACE 0x00000002 /* delayed trace (used on m68k, i386) */ 34 33 35 34 #define PT_OPT_FLAG_SHIFT 3 36 35 /* PT_TRACE_* event enable flags */