Re: [PATCH] perf/core: Fix race between perf_event_exit_task and perf_pending_task
From: Dmitry Vyukov
Date: Fri Sep 18 2026 - 05:20:19 EST
On Tue, 15 Sept 2026 at 23:35, Ian Rogers <irogers@xxxxxxxxxx> wrote:
>
> On Wed, Apr 15, 2026 at 8:08 PM Luo Gengkun <luogengkun2@xxxxxxxxxx> wrote:
> >
> > A race condition exists between perf_event_exit_task() and perf_pending_task().
> >
> > During begin_new_exec(), perf_event_exit_task() may be called, and the
> > PF_EXITING flag is not set on task. so perf_sigtrap() continues to execute
> > and triggers WARN_ON_ONCE(event->ctx->task != current).
> >
> > To fix this problem, also check if the event->ctx->task is TASK_TOMBSTONE.
> >
> > Fixes: 97ba62b27867 ("perf: Add support for SIGTRAP on perf events")
> > Signed-off-by: Luo Gengkun <luogengkun2@xxxxxxxxxx>
>
> Dmitry, the description and patch look sensible. Could you take a look?
Marco, please take a look.
I paged out all context long time ago... The code is too tricky to say
if it's possible/not possible/fixed by the patch/not fixed by the
patch looking at the diff.
A test would be helpful. Will also prevent regression in the next release.
> Thanks,
> Ian
>
> > ---
> > kernel/events/core.c | 2 +-
> > 1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/kernel/events/core.c b/kernel/events/core.c
> > index 1f5699b339ec..3422900263fa 100644
> > --- a/kernel/events/core.c
> > +++ b/kernel/events/core.c
> > @@ -7543,7 +7543,7 @@ static void perf_sigtrap(struct perf_event *event)
> > * Both perf_pending_task() and perf_pending_irq() can race with the
> > * task exiting.
> > */
> > - if (current->flags & PF_EXITING)
> > + if (current->flags & PF_EXITING || event->ctx->task == TASK_TOMBSTONE)
> > return;
> >
> > /*
> > --
> > 2.34.1
> >