From: David Carrillo-Cisneros <davidcc@google.com>
To: linux-kernel@vger.kernel.org
Cc: "x86@kernel.org" <x86@kernel.org>, Ingo Molnar <mingo@redhat.com>,
"Yan, Zheng" <zheng.z.yan@intel.com>,
Andi Kleen <ak@linux.intel.com>, Kan Liang <kan.liang@intel.com>,
Peter Zijlstra <peterz@infradead.org>,
David Carrillo-Cisneros <davidcc@google.com>,
Stephane Eranian <eranian@google.com>
Subject: [PATCH] perf/core: make account/unaccount_sb_event consistent
Date: Wed, 1 Jun 2016 12:33:05 -0700 [thread overview]
Message-ID: <1464809585-66072-1-git-send-email-davidcc@google.com> (raw)
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 ...
Patch rebased on peterz/queue/perf/core .
Reviewed-by: Stephane Eranian <eranian@google.com>
Signed-off-by: David Carrillo-Cisneros <davidcc@google.com>
---
kernel/events/core.c | 34 ++++++++++++++++++----------------
1 file changed, 18 insertions(+), 16 deletions(-)
diff --git a/kernel/events/core.c b/kernel/events/core.c
index 1e48efc..6af0f01 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -3682,15 +3682,28 @@ static void detach_sb_event(struct perf_event *event)
raw_spin_unlock(&pel->lock);
}
-static void unaccount_pmu_sb_event(struct perf_event *event)
+static bool is_sb_event(struct perf_event *event)
{
+ struct perf_event_attr *attr = &event->attr;
+
if (event->parent)
- return;
+ return false;
if (event->attach_state & PERF_ATTACH_TASK)
- return;
+ return false;
- detach_sb_event(event);
+ if (attr->mmap || attr->mmap_data || attr->mmap2 ||
+ attr->comm || attr->comm_exec ||
+ attr->task ||
+ attr->context_switch)
+ return true;
+ return false;
+}
+
+static void unaccount_pmu_sb_event(struct perf_event *event)
+{
+ if (is_sb_event(event))
+ detach_sb_event(event);
}
static void unaccount_event_cpu(struct perf_event *event, int cpu)
@@ -8666,18 +8679,7 @@ static void attach_sb_event(struct perf_event *event)
*/
static void account_pmu_sb_event(struct perf_event *event)
{
- struct perf_event_attr *attr = &event->attr;
-
- if (event->parent)
- return;
-
- if (event->attach_state & PERF_ATTACH_TASK)
- return;
-
- if (attr->mmap || attr->mmap_data || attr->mmap2 ||
- attr->comm || attr->comm_exec ||
- attr->task ||
- attr->context_switch)
+ if (is_sb_event(event))
attach_sb_event(event);
}
--
2.8.0.rc3.226.g39d4020
next reply other threads:[~2016-06-01 19:35 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-06-01 19:33 David Carrillo-Cisneros [this message]
2016-06-07 9:15 ` [PATCH] perf/core: make account/unaccount_sb_event consistent Borislav Petkov
2016-06-08 8:52 ` [tip:perf/core] perf/core: Fix crash due to account/unaccount_sb_event() inconsistency tip-bot for David Carrillo-Cisneros
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1464809585-66072-1-git-send-email-davidcc@google.com \
--to=davidcc@google.com \
--cc=ak@linux.intel.com \
--cc=eranian@google.com \
--cc=kan.liang@intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=peterz@infradead.org \
--cc=x86@kernel.org \
--cc=zheng.z.yan@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).