linux-stable/kernel/events
Namhyung Kim c5de60cd62 perf/core: Fix cgroup event list management
The active cgroup events are managed in the per-cpu cgrp_cpuctx_list.
This list is only accessed from current cpu and not protected by any
locks.  But from the commit ef54c1a476 ("perf: Rework
perf_event_exit_event()"), it's possible to access (actually modify)
the list from another cpu.

In the perf_remove_from_context(), it can remove an event from the
context without an IPI when the context is not active.  This is not
safe with cgroup events which can have some active events in the
context even if ctx->is_active is 0 at the moment.  The target cpu
might be in the middle of list iteration at the same time.

If the event is enabled when it's about to be closed, it might call
perf_cgroup_event_disable() and list_del() with the cgrp_cpuctx_list
on a different cpu.

This resulted in a crash due to an invalid list pointer access during
the cgroup list traversal on the cpu which the event belongs to.

Let's fallback to IPI to access the cgrp_cpuctx_list from that cpu.
Similarly, perf_install_in_context() should use IPI for the cgroup
events too.

Fixes: ef54c1a476 ("perf: Rework perf_event_exit_event()")
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Link: https://lkml.kernel.org/r/20220124195808.2252071-1-namhyung@kernel.org
2022-01-26 15:06:06 +01:00
..
callchain.c uaccess: add force_uaccess_{begin,end} helpers 2020-08-12 10:57:59 -07:00
core.c perf/core: Fix cgroup event list management 2022-01-26 15:06:06 +01:00
hw_breakpoint.c perf/hw_breakpoint: Replace deprecated CPU-hotplug functions 2021-08-26 09:14:36 +02:00
internal.h tracing/perf: Add interrupt_context_level() helper 2021-10-19 20:33:20 -04:00
Makefile perf/core: allow ftrace for functions in kernel/event/core.c 2021-10-25 22:50:42 -04:00
ring_buffer.c perf: Cap allocation order at aux_watermark 2021-04-16 16:32:39 +02:00
uprobes.c mm/memcg: Convert mem_cgroup_charge() to take a folio 2021-09-27 09:27:31 -04:00