Linux filesystem development
 help / color / mirror / Atom feed
From: Christian Brauner <brauner@kernel.org>
To: Oleg Nesterov <oleg@redhat.com>, Jens Axboe <axboe@kernel.dk>,
	 linux-fsdevel@vger.kernel.org
Cc: Alexander Viro <viro@zeniv.linux.org.uk>, Jan Kara <jack@suse.cz>,
	 NeilBrown <neil@brown.name>, Ingo Molnar <mingo@redhat.com>,
	 Peter Zijlstra <peterz@infradead.org>,
	linux-mm@kvack.org,  io-uring@vger.kernel.org,
	 "Christian Brauner (Amutable)" <brauner@kernel.org>,
	stable@vger.kernel.org
Subject: [PATCH v2 2/7] coredump: hold RCU while releasing parked threads
Date: Thu, 17 Sep 2026 11:17:29 +0200	[thread overview]
Message-ID: <20260917-work-coredump-fixes-v2-2-f3787fcda051@kernel.org> (raw)
In-Reply-To: <20260917-work-coredump-fixes-v2-0-f3787fcda051@kernel.org>

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>
Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
---
 fs/coredump.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/fs/coredump.c b/fs/coredump.c
index 1fba3fed1a07..5b3f3a1090d7 100644
--- a/fs/coredump.c
+++ b/fs/coredump.c
@@ -598,6 +598,8 @@ static void coredump_finish(enum coredump_state state)
 	current->signal->core_state = NULL;
 	spin_unlock_irq(&current->sighand->siglock);
 
+	/* A released thread may exit and be freed before it is woken. */
+	guard(rcu)();
 	while ((curr = next) != NULL) {
 		next = curr->next;
 		task = curr->task;
@@ -606,6 +608,7 @@ static void coredump_finish(enum coredump_state state)
 		 * ->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);
 	}

-- 
2.53.0


  parent reply	other threads:[~2026-09-17  9:17 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-17  9:17 [PATCH v2 0/7] coredump & signals: an impossible affair Christian Brauner
2026-09-17  9:17 ` [PATCH v2 1/7] fork: refuse new threads while a coredump or an exec is in progress Christian Brauner
2026-09-17 16:33   ` Bradley Morgan
2026-09-18 10:40   ` Oleg Nesterov
2026-09-18 12:24     ` Christian Brauner
2026-09-18 12:52       ` Christian Brauner
2026-09-18 13:41         ` Oleg Nesterov
2026-09-18 14:29           ` Christian Brauner
2026-09-18 15:00             ` Christian Brauner
2026-09-18 15:15               ` Christian Brauner
2026-09-21 10:32               ` Oleg Nesterov
2026-09-21 11:46                 ` Christian Brauner
2026-09-21 12:37                   ` Oleg Nesterov
2026-09-17  9:17 ` Christian Brauner [this message]
2026-09-17  9:17 ` [PATCH v2 3/7] signal: only SIGKILL and the freezers interrupt a coredumping task Christian Brauner
2026-09-17  9:17 ` [PATCH v2 4/7] coredump: parse a snapshot of core_pattern Christian Brauner
2026-09-18 15:28   ` Oleg Nesterov
2026-09-17  9:17 ` [PATCH v2 5/7] io-wq: order the exit bit against worker creation task work Christian Brauner
2026-09-18 14:55   ` Oleg Nesterov
2026-09-17  9:17 ` [PATCH v2 6/7] signal: don't retarget shared signals in a dying thread group Christian Brauner
2026-09-18 14:24   ` Oleg Nesterov
2026-09-17  9:17 ` [PATCH v2 7/7] selftests/coredump: test shared signal retargeting during a dump Christian Brauner

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260917-work-coredump-fixes-v2-2-f3787fcda051@kernel.org \
    --to=brauner@kernel.org \
    --cc=axboe@kernel.dk \
    --cc=io-uring@vger.kernel.org \
    --cc=jack@suse.cz \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=mingo@redhat.com \
    --cc=neil@brown.name \
    --cc=oleg@redhat.com \
    --cc=peterz@infradead.org \
    --cc=stable@vger.kernel.org \
    --cc=viro@zeniv.linux.org.uk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox