public inbox for linux-rt-users@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] ptrace: fix ptrace_unfreeze_traced() race with rt-lock
@ 2020-11-02 15:50 Oleg Nesterov
  2020-11-02 16:25 ` Oleg Nesterov
                   ` (2 more replies)
  0 siblings, 3 replies; 12+ messages in thread
From: Oleg Nesterov @ 2020-11-02 15:50 UTC (permalink / raw)
  To: Sebastian Andrzej Siewior, Thomas Gleixner
  Cc: Alexander Fyodorov, Juri Lelli, Luis Claudio R. Goncalves,
	Steven Rostedt, linux-rt-users

The commit 6362e6476cd7 ("ptrace: fix ptrace vs tasklist_lock race")
changed ptrace_freeze_traced() to take task->saved_state into account,
but ptrace_unfreeze_traced() has the same problem and needs a similar
fix: it should check/update both ->state and ->saved_state.

Reported-by: Luis Claudio R. Goncalves <lgoncalv@redhat.com>
Fixes: 6362e6476cd7 ("ptrace: fix ptrace vs tasklist_lock race")
Signed-off-by: Oleg Nesterov <oleg@redhat.com>
---
 kernel/ptrace.c | 22 ++++++++++++++--------
 1 file changed, 14 insertions(+), 8 deletions(-)

diff --git a/kernel/ptrace.c b/kernel/ptrace.c
index 3075006d720e..7e004f998233 100644
--- a/kernel/ptrace.c
+++ b/kernel/ptrace.c
@@ -197,8 +197,7 @@ static bool ptrace_freeze_traced(struct task_struct *task)
 
 static void ptrace_unfreeze_traced(struct task_struct *task)
 {
-	if (task->state != __TASK_TRACED)
-		return;
+	bool frozen = true;
 
 	WARN_ON(!task->ptrace || task->parent != current);
 
@@ -207,12 +206,19 @@ static void ptrace_unfreeze_traced(struct task_struct *task)
 	 * Recheck state under the lock to close this race.
 	 */
 	spin_lock_irq(&task->sighand->siglock);
-	if (task->state == __TASK_TRACED) {
-		if (__fatal_signal_pending(task))
-			wake_up_state(task, __TASK_TRACED);
-		else
-			task->state = TASK_TRACED;
-	}
+
+	raw_spin_lock(&task->pi_lock);
+	if (task->state == __TASK_TRACED)
+		task->state = TASK_TRACED;
+	else if (task->saved_state == __TASK_TRACED)
+		task->saved_state = TASK_TRACED;
+	else
+		frozen = false;
+	raw_spin_unlock(&task->pi_lock);
+
+	if (frozen && __fatal_signal_pending(task))
+		wake_up_state(task, __TASK_TRACED);
+
 	spin_unlock_irq(&task->sighand->siglock);
 }
 
-- 
2.25.1.362.g51ebf55



^ permalink raw reply related	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2020-11-03 17:01 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-11-02 15:50 [PATCH] ptrace: fix ptrace_unfreeze_traced() race with rt-lock Oleg Nesterov
2020-11-02 16:25 ` Oleg Nesterov
2020-11-02 16:34   ` Sebastian Andrzej Siewior
2020-11-02 17:01     ` Oleg Nesterov
2020-11-02 17:30       ` Sebastian Andrzej Siewior
2020-11-02 17:41         ` Oleg Nesterov
2020-11-02 18:04           ` Sebastian Andrzej Siewior
2020-11-02 17:42 ` Sebastian Andrzej Siewior
2020-11-03 11:37   ` Oleg Nesterov
2020-11-03 16:45     ` Sebastian Andrzej Siewior
2020-11-03 11:39 ` [PATCH v2] " Oleg Nesterov
2020-11-03 17:01   ` Sebastian Andrzej Siewior

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox