From: Christian Brauner <brauner@kernel.org> maillist inclusion category: bugfix bugzilla: https://atomgit.com/src-openeuler/kernel/issues/21066 Reference: https://lore.kernel.org/all/20261028171306.1530342-1-sashal@kernel.org/ -------------------------------- [ Upstream commit 61d58591aa0188bf2463e263962256316ff8b576 ] coredump_finish() releases the parked threads by clearing ->task in their core_thread entry and calling wake_up_process() on each of them. It does that without holding a reference on the task and without being inside rcu. But calling wake_up_process(task) without rcu here isn't safe. A parked thread doesn't need that wakeup to leave. A spurious wakeup or a preemption after the store is enough for the task to go away. So if the coredump client is preempted between the store and wake_up_process() the thread can exit and be freed in the meantime and try_to_wake_up() takes pi_lock in freed memory. Hold rcu across the loop. Fixes: a94e2d408eae ("coredump: kill mm->core_done") Cc: stable@vger.kernel.org Acked-by: Oleg Nesterov <oleg@redhat.com> Link: https://patch.msgid.link/20260921-work-coredump-fixes-v3-1-8e4adb1619e6@kern... Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org> [ sashal: Replaced guard(rcu)() with explicit rcu_read_lock() and rcu_read_unlock() calls. ] Signed-off-by: Sasha Levin <sashal@kernel.org> Signed-off-by: Zizhi Wo <wozizhi@huawei.com> --- fs/coredump.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/fs/coredump.c b/fs/coredump.c index 535c3fdc1598..3449a7cd7b39 100644 --- a/fs/coredump.c +++ b/fs/coredump.c @@ -498,21 +498,25 @@ static void coredump_finish(struct mm_struct *mm, bool core_dumped) current->signal->group_exit_task = NULL; current->signal->flags = SIGNAL_GROUP_EXIT; spin_unlock_irq(¤t->sighand->siglock); next = mm->core_state->dumper.next; + /* A released thread may exit and be freed before it is woken. */ + rcu_read_lock(); while ((curr = next) != NULL) { next = curr->next; task = curr->task; /* * see exit_mm(), curr->task must not see * ->task == NULL before we read ->next. */ smp_mb(); + /* Any wakeup now lets the thread exit, rcu keeps it alive. */ curr->task = NULL; wake_up_process(task); } + rcu_read_unlock(); mm->core_state = NULL; } static bool dump_interrupted(void) -- 2.52.0