lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <1440426780-27227-6-git-send-email-alexander.shishkin@linux.intel.com>
Date:	Mon, 24 Aug 2015 17:32:59 +0300
From:	Alexander Shishkin <alexander.shishkin@...ux.intel.com>
To:	Peter Zijlstra <a.p.zijlstra@...llo.nl>,
	Ingo Molnar <mingo@...hat.com>
Cc:	linux-kernel@...r.kernel.org, adrian.hunter@...el.com,
	Arnaldo Carvalho de Melo <acme@...radead.org>,
	Vince Weaver <vince@...ter.net>,
	Stephane Eranian <eranian@...gle.com>,
	Johannes Berg <johannes@...solutions.net>,
	Alexander Shishkin <alexander.shishkin@...ux.intel.com>
Subject: [PATCH v2 5/6] perf/x86/intel/pt: Use extended error reporting in event initialization

Event attribute validation is one of the biggest sources of EINVALs around
perf_event_open() syscall. This patch annotates error checks with extended
error reporting macros to provide the user with more details on what they
are doing wrong.

Signed-off-by: Alexander Shishkin <alexander.shishkin@...ux.intel.com>
---
 arch/x86/kernel/cpu/perf_event_intel_pt.c | 29 +++++++++++++++++------------
 1 file changed, 17 insertions(+), 12 deletions(-)

diff --git a/arch/x86/kernel/cpu/perf_event_intel_pt.c b/arch/x86/kernel/cpu/perf_event_intel_pt.c
index 4216928344..9a09c89928 100644
--- a/arch/x86/kernel/cpu/perf_event_intel_pt.c
+++ b/arch/x86/kernel/cpu/perf_event_intel_pt.c
@@ -18,6 +18,8 @@
 
 #undef DEBUG
 
+#define PERF_MODNAME	"perf/x86/intel/pt"
+
 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
 
 #include <linux/types.h>
@@ -198,29 +200,29 @@ fail:
 			RTIT_CTL_CYC_PSB	| \
 			RTIT_CTL_MTC)
 
-static bool pt_event_valid(struct perf_event *event)
+static int pt_event_valid(struct perf_event *event)
 {
 	u64 config = event->attr.config;
 	u64 allowed, requested;
 
 	if ((config & PT_CONFIG_MASK) != config)
-		return false;
+		return perf_err(-EINVAL, "PT config: disallowed bits");
 
 	if (config & RTIT_CTL_CYC_PSB) {
 		if (!pt_cap_get(PT_CAP_psb_cyc))
-			return false;
+			return perf_err(-EINVAL, "PT config: PSB/CYC not supported");
 
 		allowed = pt_cap_get(PT_CAP_psb_periods);
 		requested = (config & RTIT_CTL_PSB_FREQ) >>
 			RTIT_CTL_PSB_FREQ_OFFSET;
 		if (requested && (!(allowed & BIT(requested))))
-			return false;
+			return perf_err(-EINVAL, "PT config: unsupported PSB period");
 
 		allowed = pt_cap_get(PT_CAP_cycle_thresholds);
 		requested = (config & RTIT_CTL_CYC_THRESH) >>
 			RTIT_CTL_CYC_THRESH_OFFSET;
 		if (requested && (!(allowed & BIT(requested))))
-			return false;
+			return perf_err(-EINVAL, "PT config: unsupported CYC threshold");
 	}
 
 	if (config & RTIT_CTL_MTC) {
@@ -232,20 +234,20 @@ static bool pt_event_valid(struct perf_event *event)
 		 * CPUID is 0 will #GP, so better safe than sorry.
 		 */
 		if (!pt_cap_get(PT_CAP_mtc))
-			return false;
+			return perf_err(-EINVAL, "PT config: MTC not supported");
 
 		allowed = pt_cap_get(PT_CAP_mtc_periods);
 		if (!allowed)
-			return false;
+			return perf_err(-EINVAL, "PT config: MTC periods not supported");
 
 		requested = (config & RTIT_CTL_MTC_RANGE) >>
 			RTIT_CTL_MTC_RANGE_OFFSET;
 
 		if (!(allowed & BIT(requested)))
-			return false;
+			return perf_err(-EINVAL, "PT config: unsupported MTC period");
 	}
 
-	return true;
+	return 0;
 }
 
 /*
@@ -1111,14 +1113,17 @@ static void pt_event_destroy(struct perf_event *event)
 
 static int pt_event_init(struct perf_event *event)
 {
+	int err;
+
 	if (event->attr.type != pt_pmu.pmu.type)
 		return -ENOENT;
 
-	if (!pt_event_valid(event))
-		return -EINVAL;
+	err = pt_event_valid(event);
+	if (err)
+		return err;
 
 	if (x86_add_exclusive(x86_lbr_exclusive_pt))
-		return -EBUSY;
+		return perf_err(-EBUSY, "PT conflicts with active events");
 
 	event->destroy = pt_event_destroy;
 
-- 
2.5.0

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ