Re: [PATCH v2 05/12] perf/core: Don't unwind the user stack without an mm
From: Arnd Bergmann
Date: Wed Dec 02 2026 - 05:13:38 EST
On Wed, Dec 2, 2026, at 03:39, James Houghton wrote:
> get_perf_callchain() only checks is_user_task(current) when the regs it
> is given aren't user mode regs. That's fine for perf events: a task's
> own events are torn down by perf_event_exit_task() before exit_mm(), and
> samples from CPU-wide events go through perf_callchain(), which already
> skips the user callchain if current isn't a user task with an mm.
>
> However, BPF's bpf_get_task_stack() (and bpf_get_task_stack_sleepable())
> call get_perf_callchain() directly, passing task_pt_regs(current) when
> called on the current task. Those are user mode regs for a user task even
> after it has gone through exit_mm(), e.g. when the helper is called from
> a program attached to exit_files() or to the dying task's final
> sched_switch.
>
> perf_callchain_user() then unwinds the user stack without an mm. That
> access does not reliably fail: the user half of the address space
> belongs to whatever mm happens to be lazily loaded, if any, so the
> unwinder may read another task's memory. This affects e.g. arm64,
> riscv, loongarch and csky, whose perf_callchain_user() doesn't check
> current->mm itself.
>
> Check is_user_task(current) regardless of the regs' mode.
>
> Fixes: fa28dcb82a38 ("bpf: Introduce helper bpf_get_task_stack()")
> Signed-off-by: James Houghton <jthoughton@xxxxxxxxxx>
Reviewed-by: Arnd Bergmann <arnd@xxxxxxxx>