Skip to content

Commit ccd41c8

Browse files
Peter ZijlstraIngo Molnar
authored andcommitted
perf: Fix racy group access
While looking at some fuzzer output I noticed that we do not hold any locks on leader->ctx and therefore the sibling_list iteration is unsafe. Acquire the relevant ctx->mutex before calling into the pmu specific code. Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Cc: Vince Weaver <[email protected]> Cc: Jiri Olsa <[email protected]> Cc: Sasha Levin <[email protected]> Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: Ingo Molnar <[email protected]>
1 parent 9332d25 commit ccd41c8

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

kernel/events/core.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7036,12 +7036,23 @@ EXPORT_SYMBOL_GPL(perf_pmu_unregister);
70367036

70377037
static int perf_try_init_event(struct pmu *pmu, struct perf_event *event)
70387038
{
7039+
struct perf_event_context *ctx = NULL;
70397040
int ret;
70407041

70417042
if (!try_module_get(pmu->module))
70427043
return -ENODEV;
7044+
7045+
if (event->group_leader != event) {
7046+
ctx = perf_event_ctx_lock(event->group_leader);
7047+
BUG_ON(!ctx);
7048+
}
7049+
70437050
event->pmu = pmu;
70447051
ret = pmu->event_init(event);
7052+
7053+
if (ctx)
7054+
perf_event_ctx_unlock(event->group_leader, ctx);
7055+
70457056
if (ret)
70467057
module_put(pmu->module);
70477058

0 commit comments

Comments
 (0)