On Mon, 26 Jan 2026 12:05:53 -0500
Steven Rostedt <[email protected]> wrote:
> I guess we need to also test for !current->mm because the flags set for an
> exiting task is done when we can still do callchains. Thus, the only way to
> know if it is safe to do a callchain when a task is exiting is via task->mm
> and not task->flags :-/
Can you test this patch?
-- Steve
diff --git a/kernel/events/callchain.c b/kernel/events/callchain.c
index 1f6589578703..c82d61d73bd8 100644
--- a/kernel/events/callchain.c
+++ b/kernel/events/callchain.c
@@ -246,7 +246,14 @@ get_perf_callchain(struct pt_regs *regs, bool kernel, bool
user,
if (user && !crosstask) {
if (!user_mode(regs)) {
- if (current->flags & (PF_KTHREAD | PF_USER_WORKER))
+ /*
+ * Testing current->mm is not enough as some kernel
threads
+ * may have one set. But testing the flags is not enough
+ * either as this can be called after a user task
+ * frees its mm just before it exits.
+ */
+ if (!current->mm ||
+ (current->flags & (PF_KTHREAD | PF_USER_WORKER)))
goto exit_put;
regs = task_pt_regs(current);
}