[PATCH 27/33] utrace: finish_resume_report: don't do user_xxx_step() if ptrace_wants_step()

Oleg Nesterov oleg at redhat.com
Mon Nov 21 20:02:38 UTC 2011


finish_resume_report() should not enable/disable the stepping if
ptrace_wants_step() == T. If ptrace wants block_step while utrace
wants single_step we could "promote" the stepping, but I do not
think this really makes sense.

Unless the tracee is killed this can't race with ptrace, this is
called by the tracee itself. If it is killed we do not care.

Signed-off-by: Oleg Nesterov <oleg at redhat.com>
---
 include/linux/tracehook.h |    8 ++++----
 kernel/utrace.c           |    9 ++++++---
 2 files changed, 10 insertions(+), 7 deletions(-)

diff --git a/include/linux/tracehook.h b/include/linux/tracehook.h
index 21c8ca2..b6812d4 100644
--- a/include/linux/tracehook.h
+++ b/include/linux/tracehook.h
@@ -104,8 +104,8 @@ static inline __must_check int tracehook_report_syscall_entry(
 	return 0;
 }
 
-#define ptrace_wants_step()	\
-	(current->ptrace & (PT_SINGLE_STEP | PT_SINGLE_BLOCK))
+#define ptrace_wants_step(task)	\
+	((task)->ptrace & (PT_SINGLE_STEP | PT_SINGLE_BLOCK))
 
 /**
  * tracehook_report_syscall_exit - task has just finished a system call
@@ -129,7 +129,7 @@ static inline void tracehook_report_syscall_exit(struct pt_regs *regs, int step)
 	if (task_utrace_flags(current) & UTRACE_EVENT(SYSCALL_EXIT))
 		utrace_report_syscall_exit(regs);
 
-	if (step && ptrace_wants_step()) {
+	if (step && ptrace_wants_step(current)) {
 		siginfo_t info;
 		user_single_step_siginfo(current, regs, &info);
 		force_sig_info(SIGTRAP, &info, current);
@@ -160,7 +160,7 @@ static inline void tracehook_signal_handler(int sig, siginfo_t *info,
 {
 	if (task_utrace_flags(current))
 		utrace_signal_handler(current, stepping);
-	if (stepping && ptrace_wants_step())
+	if (stepping && ptrace_wants_step(current))
 		ptrace_notify(SIGTRAP);
 }
 
diff --git a/kernel/utrace.c b/kernel/utrace.c
index 960dd9e..05e8532 100644
--- a/kernel/utrace.c
+++ b/kernel/utrace.c
@@ -1829,7 +1829,8 @@ static void finish_resume_report(struct task_struct *task,
 
 	case UTRACE_BLOCKSTEP:
 		if (likely(arch_has_block_step())) {
-			user_enable_block_step(task);
+			if (!ptrace_wants_step(task))
+				user_enable_block_step(task);
 			break;
 		}
 
@@ -1842,7 +1843,8 @@ static void finish_resume_report(struct task_struct *task,
 
 	case UTRACE_SINGLESTEP:
 		if (likely(arch_has_single_step())) {
-			user_enable_single_step(task);
+			if (!ptrace_wants_step(task))
+				user_enable_single_step(task);
 		} else {
 			/*
 			 * This means some callback is to blame for failing
@@ -1857,7 +1859,8 @@ static void finish_resume_report(struct task_struct *task,
 	case UTRACE_REPORT:
 	case UTRACE_RESUME:
 	default:
-		user_disable_single_step(task);
+		if (!ptrace_wants_step(task))
+			user_disable_single_step(task);
 		break;
 	}
 }
-- 
1.5.5.1



More information about the kernel mailing list