summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOleg Nesterov <oleg@redhat.com>2020-11-03 12:39:01 +0100
committerMark Gross <markgross@kernel.org>2022-03-02 16:43:06 -0800
commit927cf4cc62bf7c41e5dbe74a111699819b79bcdf (patch)
tree094980a6b1365e3a2c334b1150d851db331f0843
parent209424478b42f12331dc4513d421909690d1b56b (diff)
downloadlinux-rt-927cf4cc62bf7c41e5dbe74a111699819b79bcdf.tar.gz
ptrace: fix ptrace_unfreeze_traced() race with rt-lock
[ Upstream commit 0fdc91971b34cf6857b4cfd8c322ae936cfc189b ] The patch "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: "ptrace: fix ptrace vs tasklist_lock race" Signed-off-by: Oleg Nesterov <oleg@redhat.com> Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de> Cc: stable-rt@vger.kernel.org Signed-off-by: Tom Zanussi <zanussi@kernel.org> Signed-off-by: Luis Claudio R. Goncalves <lgoncalv@redhat.com>
-rw-r--r--kernel/ptrace.c23
1 files changed, 15 insertions, 8 deletions
diff --git a/kernel/ptrace.c b/kernel/ptrace.c
index cd869b487adc..c738827f29f7 100644
--- a/kernel/ptrace.c
+++ b/kernel/ptrace.c
@@ -203,8 +203,8 @@ static bool ptrace_freeze_traced(struct task_struct *task)
static void ptrace_unfreeze_traced(struct task_struct *task)
{
- if (task->state != __TASK_TRACED)
- return;
+ unsigned long flags;
+ bool frozen = true;
WARN_ON(!task->ptrace || task->parent != current);
@@ -213,12 +213,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_irqsave(&task->pi_lock, flags);
+ 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_irqrestore(&task->pi_lock, flags);
+
+ if (frozen && __fatal_signal_pending(task))
+ wake_up_state(task, __TASK_TRACED);
+
spin_unlock_irq(&task->sighand->siglock);
}