aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Carrillo-Cisneros <davidcc@google.com>2016-06-01 15:33:05 -0400
committerIngo Molnar <mingo@kernel.org>2016-06-08 03:18:45 -0400
commita4f144ebbdf6f7807c477bce8e136047ed27321f (patch)
tree93fbb633948b9c6e47c52fe7b2eab07d351ee50d
parent030ba6cd105c68ce919c5e239853b567490cd059 (diff)
perf/core: Fix crash due to account/unaccount_sb_event() inconsistency
unaccount_pmu_sb_event() did not check for attributes in event->attr before calling detach_sb_event(), while account_pmu_event() did. This caused NULL pointer reference in cgroup events that did not have any of the attributes checked by account_pmu_event(). To trigger the bug just wait for a cgroup event to terminate, e.g.: $ mkdir /dev/cgroup/devices/test $ perf stat -e cycles -a -G test sleep 0 ... see crash ... Signed-off-by: David Carrillo-Cisneros <davidcc@google.com> Reviewed-by: Stephane Eranian <eranian@google.com> Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com> Cc: Arnaldo Carvalho de Melo <acme@redhat.com> Cc: Jiri Olsa <jolsa@redhat.com> Cc: Kan Liang <kan.liang@intel.com> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: Zheng <zheng.z.yan@intel.com> Link: http://lkml.kernel.org/r/1464809585-66072-1-git-send-email-davidcc@google.com Signed-off-by: Ingo Molnar <mingo@kernel.org>
-rw-r--r--kernel/events/core.c34
1 files changed, 18 insertions, 16 deletions
diff --git a/kernel/events/core.c b/kernel/events/core.c
index 5d48306879d5..ae081a141a4a 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -3682,15 +3682,28 @@ static void detach_sb_event(struct perf_event *event)
3682 raw_spin_unlock(&pel->lock); 3682 raw_spin_unlock(&pel->lock);
3683} 3683}
3684 3684
3685static void unaccount_pmu_sb_event(struct perf_event *event) 3685static bool is_sb_event(struct perf_event *event)
3686{ 3686{
3687 struct perf_event_attr *attr = &event->attr;
3688
3687 if (event->parent) 3689 if (event->parent)
3688 return; 3690 return false;
3689 3691
3690 if (event->attach_state & PERF_ATTACH_TASK) 3692 if (event->attach_state & PERF_ATTACH_TASK)
3691 return; 3693 return false;
3692 3694
3693 detach_sb_event(event); 3695 if (attr->mmap || attr->mmap_data || attr->mmap2 ||
3696 attr->comm || attr->comm_exec ||
3697 attr->task ||
3698 attr->context_switch)
3699 return true;
3700 return false;
3701}
3702
3703static void unaccount_pmu_sb_event(struct perf_event *event)
3704{
3705 if (is_sb_event(event))
3706 detach_sb_event(event);
3694} 3707}
3695 3708
3696static void unaccount_event_cpu(struct perf_event *event, int cpu) 3709static void unaccount_event_cpu(struct perf_event *event, int cpu)
@@ -8666,18 +8679,7 @@ static void attach_sb_event(struct perf_event *event)
8666 */ 8679 */
8667static void account_pmu_sb_event(struct perf_event *event) 8680static void account_pmu_sb_event(struct perf_event *event)
8668{ 8681{
8669 struct perf_event_attr *attr = &event->attr; 8682 if (is_sb_event(event))
8670
8671 if (event->parent)
8672 return;
8673
8674 if (event->attach_state & PERF_ATTACH_TASK)
8675 return;
8676
8677 if (attr->mmap || attr->mmap_data || attr->mmap2 ||
8678 attr->comm || attr->comm_exec ||
8679 attr->task ||
8680 attr->context_switch)
8681 attach_sb_event(event); 8683 attach_sb_event(event);
8682} 8684}
8683 8685