Skip to content

Commit

Permalink
perf: Fix racy group access
Browse files Browse the repository at this point in the history
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) <peterz@infradead.org>
Cc: Vince Weaver <vincent.weaver@maine.edu>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Sasha Levin <sasha.levin@oracle.com>
Link: http://lkml.kernel.org/r/20150225151639.GL5029@twins.programming.kicks-ass.net
Signed-off-by: Ingo Molnar <mingo@kernel.org>
  • Loading branch information
Peter Zijlstra authored and Ingo Molnar committed Mar 27, 2015
1 parent 9332d25 commit ccd41c8
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions kernel/events/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -7036,12 +7036,23 @@ EXPORT_SYMBOL_GPL(perf_pmu_unregister);

static int perf_try_init_event(struct pmu *pmu, struct perf_event *event)
{
struct perf_event_context *ctx = NULL;
int ret;

if (!try_module_get(pmu->module))
return -ENODEV;

if (event->group_leader != event) {
ctx = perf_event_ctx_lock(event->group_leader);
BUG_ON(!ctx);
}

event->pmu = pmu;
ret = pmu->event_init(event);

if (ctx)
perf_event_ctx_unlock(event->group_leader, ctx);

if (ret)
module_put(pmu->module);

Expand Down

0 comments on commit ccd41c8

Please sign in to comment.