Skip to contentSkip to conversation

perf/x86/intel/bts: Fix exclusive event reference leak

PATCH New Alexander Shishkin 2 participants 2 messages Oct 23, 2017 – Oct 24, 2017

Subsystems (2)
lore
Share & tools
lore

Alexander Shishkin

author reviewer
#0 lore raw

PATCH 1/1 perf/x86/intel/bts: Fix exclusive event reference leak

Commit

d2878d642a4ed ("perf/x86/intel/bts: Disallow use by unprivileged users on paranoid systems")

adds a privilege check in the exactly wrong place in the event init path:
after the 'LBR exclusive' reference has been taken, and doesn't release it in the case of insuffucient privileges. After this, nobody in the system gets to use PT or LBR afterwards.

This patch moves the privilege check to where it should have been in the first place.

Fixes d2878d642a4ed ("perf/x86/intel/bts: Disallow use by unprivileged users on paranoid systems")
---
 arch/x86/events/intel/bts.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
arch/x86/events/intel/bts.c +3 -3
index ce1dac7115c9..91bbf0a3f27e 100644
@@ -555,9 +555,6 @@ static int bts_event_init(struct perf_event *event)
 	if (event->attr.type != bts_pmu.type)
 		return -ENOENT;
 
-	if (x86_add_exclusive(x86_lbr_exclusive_bts))
-		return -EBUSY;
-
 	/*
 	 * BTS leaks kernel addresses even when CPL0 tracing is
 	 * disabled, so disallow intel_bts driver for unprivileged
@@ -571,6 +568,9 @@ static int bts_event_init(struct perf_event *event)
 	    !capable(CAP_SYS_ADMIN))
 		return -EACCES;
 
+	if (x86_add_exclusive(x86_lbr_exclusive_bts))
+		return -EBUSY;
+
 	ret = x86_reserve_hardware();
 	if (ret) {
 		x86_del_exclusive(x86_lbr_exclusive_bts);
Signature · 1 line
2.14.2
#1 lore raw
perf/x86/intel/bts: Fix exclusive event reference leak
Commit-ID:  2eece390bf68ec8f733d7e4a3ba8a5ea350082ae
Gitweb:     https://git.kernel.org/tip/2eece390bf68ec8f733d7e4a3ba8a5ea350082ae
Author:     Alexander Shishkin <[email protected]>
AuthorDate: Mon, 23 Oct 2017 15:35:33 +0300
Committer:  Ingo Molnar <[email protected]>
CommitDate: Tue, 24 Oct 2017 13:19:27 +0200

perf/x86/intel/bts: Fix exclusive event reference leak

Commit:

d2878d642a4ed ("perf/x86/intel/bts: Disallow use by unprivileged users on paranoid systems")

... adds a privilege check in the exactly wrong place in the event init path:
after the 'LBR exclusive' reference has been taken, and doesn't release it in the case of insufficient privileges. After this, nobody in the system gets to use PT or LBR afterwards.

This patch moves the privilege check to where it should have been in the first place.

Cc Linus Torvalds <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Thomas Gleixner <[email protected]>
Fixes d2878d642a4ed ("perf/x86/intel/bts: Disallow use by unprivileged users on paranoid systems")
---
 arch/x86/events/intel/bts.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
arch/x86/events/intel/bts.c +3 -3
index 16076eb..141e07b 100644
@@ -546,9 +546,6 @@ static int bts_event_init(struct perf_event *event)
 	if (event->attr.type != bts_pmu.type)
 		return -ENOENT;
 
-	if (x86_add_exclusive(x86_lbr_exclusive_bts))
-		return -EBUSY;
-
 	/*
 	 * BTS leaks kernel addresses even when CPL0 tracing is
 	 * disabled, so disallow intel_bts driver for unprivileged
@@ -562,6 +559,9 @@ static int bts_event_init(struct perf_event *event)
 	    !capable(CAP_SYS_ADMIN))
 		return -EACCES;
 
+	if (x86_add_exclusive(x86_lbr_exclusive_bts))
+		return -EBUSY;
+
 	ret = x86_reserve_hardware();
 	if (ret) {
 		x86_del_exclusive(x86_lbr_exclusive_bts);