aboutsummaryrefslogtreecommitdiffstats
path: root/kernel/events
diff options
context:
space:
mode:
authorPeter Zijlstra <peterz@infradead.org>2015-02-25 09:56:04 -0500
committerIngo Molnar <mingo@kernel.org>2015-03-27 04:49:45 -0400
commitccd41c86ad4d464d0ed4e48d80759ff85c2115b0 (patch)
treeb53b1e7507761a9144f900eff6f97cd4bb6d15c5 /kernel/events
parent9332d250b4b4f67c633894b311e022e3cf943bd5 (diff)
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) <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>
Diffstat (limited to 'kernel/events')
-rw-r--r--kernel/events/core.c11
1 files changed, 11 insertions, 0 deletions
diff --git a/kernel/events/core.c b/kernel/events/core.c
index b01dfb602db1..bb1a7c36e794 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -7036,12 +7036,23 @@ EXPORT_SYMBOL_GPL(perf_pmu_unregister);
7036 7036
7037static int perf_try_init_event(struct pmu *pmu, struct perf_event *event) 7037static int perf_try_init_event(struct pmu *pmu, struct perf_event *event)
7038{ 7038{
7039 struct perf_event_context *ctx = NULL;
7039 int ret; 7040 int ret;
7040 7041
7041 if (!try_module_get(pmu->module)) 7042 if (!try_module_get(pmu->module))
7042 return -ENODEV; 7043 return -ENODEV;
7044
7045 if (event->group_leader != event) {
7046 ctx = perf_event_ctx_lock(event->group_leader);
7047 BUG_ON(!ctx);
7048 }
7049
7043 event->pmu = pmu; 7050 event->pmu = pmu;
7044 ret = pmu->event_init(event); 7051 ret = pmu->event_init(event);
7052
7053 if (ctx)
7054 perf_event_ctx_unlock(event->group_leader, ctx);
7055
7045 if (ret) 7056 if (ret)
7046 module_put(pmu->module); 7057 module_put(pmu->module);
7047 7058