summaryrefslogtreecommitdiffstats
path: root/debian/patches-rt/0334-ptrace-fix-ptrace_unfreeze_traced-race-with-rt-lock.patch
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-06 01:02:38 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-06 01:02:38 +0000
commit08b74a000942a380fe028845f92cd3a0dee827d5 (patch)
treeaa78b4e12607c3e1fcce8d5cc42df4330792f118 /debian/patches-rt/0334-ptrace-fix-ptrace_unfreeze_traced-race-with-rt-lock.patch
parentAdding upstream version 4.19.249. (diff)
downloadlinux-08b74a000942a380fe028845f92cd3a0dee827d5.tar.xz
linux-08b74a000942a380fe028845f92cd3a0dee827d5.zip
Adding debian version 4.19.249-2.debian/4.19.249-2debian
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'debian/patches-rt/0334-ptrace-fix-ptrace_unfreeze_traced-race-with-rt-lock.patch')
-rw-r--r--debian/patches-rt/0334-ptrace-fix-ptrace_unfreeze_traced-race-with-rt-lock.patch68
1 files changed, 68 insertions, 0 deletions
diff --git a/debian/patches-rt/0334-ptrace-fix-ptrace_unfreeze_traced-race-with-rt-lock.patch b/debian/patches-rt/0334-ptrace-fix-ptrace_unfreeze_traced-race-with-rt-lock.patch
new file mode 100644
index 000000000..ab3bf14d5
--- /dev/null
+++ b/debian/patches-rt/0334-ptrace-fix-ptrace_unfreeze_traced-race-with-rt-lock.patch
@@ -0,0 +1,68 @@
+From a888cf3e5934c79d8edfca69dfe7fbe8f52c7476 Mon Sep 17 00:00:00 2001
+From: Oleg Nesterov <oleg@redhat.com>
+Date: Tue, 3 Nov 2020 12:39:01 +0100
+Subject: [PATCH 334/347] ptrace: fix ptrace_unfreeze_traced() race with
+ rt-lock
+Origin: https://www.kernel.org/pub/linux/kernel/projects/rt/4.19/older/patches-4.19.246-rt110.tar.xz
+
+[ 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>
+---
+ kernel/ptrace.c | 23 +++++++++++++++--------
+ 1 file changed, 15 insertions(+), 8 deletions(-)
+
+diff --git a/kernel/ptrace.c b/kernel/ptrace.c
+index 9c59e523f3cd..b7d2a22534da 100644
+--- a/kernel/ptrace.c
++++ b/kernel/ptrace.c
+@@ -207,8 +207,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);
+
+@@ -217,12 +217,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);
+ }
+
+--
+2.36.1
+