perf: Fix racy group access
authorPeter Zijlstra <[email protected]>
Wed, 25 Feb 2015 14:56:04 +0000 (15:56 +0100)
committerIngo Molnar <[email protected]>
Fri, 27 Mar 2015 08:49:45 +0000 (09:49 +0100)
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]>
kernel/events/core.c

index b01dfb602db15222d9be368eca166fc2d2e3a27d..bb1a7c36e7941d38c542449c467862effc6a282f 100644 (file)
@@ -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);