Currently tracehooks assume that if the ptraced task has TIF_SYSCALL_TRACE set, the tracee should report the syscall. This is not true, this thread flag can be set by utrace.
Add the new internal ptrace flag, PT_SYSCALL_TRACE. Change ptrace_set_syscall_trace() to set/clear this bit along with TIF_SYSCALL_TRACE, change ptrace_report_syscall() to check this flag instead of PT_PTRACED.
Signed-off-by: Oleg Nesterov oleg@redhat.com --- include/linux/ptrace.h | 3 +++ include/linux/tracehook.h | 2 +- kernel/ptrace.c | 7 +++++-- 3 files changed, 9 insertions(+), 3 deletions(-)
diff --git a/include/linux/ptrace.h b/include/linux/ptrace.h index 6d9282a..c10f610 100644 --- a/include/linux/ptrace.h +++ b/include/linux/ptrace.h @@ -104,6 +104,8 @@
#define PT_TRACE_MASK 0x000003f4
+#define PT_SYSCALL_TRACE 0x00020000 + /* single stepping state bits (used on ARM and PA-RISC) */ #define PT_SINGLESTEP_BIT 31 #define PT_SINGLESTEP (1<<PT_SINGLESTEP_BIT) @@ -227,6 +229,7 @@ static inline void ptrace_init_task(struct task_struct *child, bool ptrace)
if (unlikely(ptrace) && current->ptrace) { child->ptrace = current->ptrace; + child->ptrace &= ~PT_SYSCALL_TRACE; __ptrace_link(child, current->parent);
if (child->ptrace & PT_SEIZED) diff --git a/include/linux/tracehook.h b/include/linux/tracehook.h index ec2af67..eb9fe30 100644 --- a/include/linux/tracehook.h +++ b/include/linux/tracehook.h @@ -59,7 +59,7 @@ static inline void ptrace_report_syscall(struct pt_regs *regs) { int ptrace = current->ptrace;
- if (!(ptrace & PT_PTRACED)) + if (!(ptrace & PT_SYSCALL_TRACE)) return;
ptrace_notify(SIGTRAP | ((ptrace & PT_TRACESYSGOOD) ? 0x80 : 0)); diff --git a/kernel/ptrace.c b/kernel/ptrace.c index dc2ad34..7deb292 100644 --- a/kernel/ptrace.c +++ b/kernel/ptrace.c @@ -40,10 +40,13 @@ void ptrace_signal_wake_up(struct task_struct *p, int quiescent)
static void ptrace_set_syscall_trace(struct task_struct *p, bool on) { - if (on) + if (on) { + p->ptrace |= PT_SYSCALL_TRACE; set_tsk_thread_flag(p, TIF_SYSCALL_TRACE); - else + } else { + p->ptrace &= ~PT_SYSCALL_TRACE; clear_tsk_thread_flag(p, TIF_SYSCALL_TRACE); + } }
static int ptrace_trapping_sleep_fn(void *flags)