Skip to content

Commit 7cc23cd

Browse files
Peter Zijlstraingomolnar
authored andcommitted
perf/x86/intel/lbr: Demand proper privileges for PERF_SAMPLE_BRANCH_KERNEL
We should always have proper privileges when requesting kernel data. Signed-off-by: Peter Zijlstra <a.p.zijlstra@chello.nl> Cc: <stable@kernel.org> Cc: Andi Kleen <ak@linux.intel.com> Cc: eranian@google.com Link: http://lkml.kernel.org/r/20130503121256.230745028@chello.nl [ Fix build error reported by fengguang.wu@intel.com, propagate error code back. ] Signed-off-by: Ingo Molnar <mingo@kernel.org> Link: http://lkml.kernel.org/n/tip-v0x9ky3ahzr6nm3c6ilwrili@git.kernel.org
1 parent 6e15eb3 commit 7cc23cd

1 file changed

Lines changed: 10 additions & 3 deletions

File tree

‎arch/x86/kernel/cpu/perf_event_intel_lbr.c‎

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -310,16 +310,19 @@ void intel_pmu_lbr_read(void)
310310
* - in case there is no HW filter
311311
* - in case the HW filter has errata or limitations
312312
*/
313-
static void intel_pmu_setup_sw_lbr_filter(struct perf_event *event)
313+
static int intel_pmu_setup_sw_lbr_filter(struct perf_event *event)
314314
{
315315
u64 br_type = event->attr.branch_sample_type;
316316
int mask = 0;
317317

318318
if (br_type & PERF_SAMPLE_BRANCH_USER)
319319
mask |= X86_BR_USER;
320320

321-
if (br_type & PERF_SAMPLE_BRANCH_KERNEL)
321+
if (br_type & PERF_SAMPLE_BRANCH_KERNEL) {
322+
if (perf_paranoid_kernel() && !capable(CAP_SYS_ADMIN))
323+
return -EACCES;
322324
mask |= X86_BR_KERNEL;
325+
}
323326

324327
/* we ignore BRANCH_HV here */
325328

@@ -339,6 +342,8 @@ static void intel_pmu_setup_sw_lbr_filter(struct perf_event *event)
339342
* be used by fixup code for some CPU
340343
*/
341344
event->hw.branch_reg.reg = mask;
345+
346+
return 0;
342347
}
343348

344349
/*
@@ -386,7 +391,9 @@ int intel_pmu_setup_lbr_filter(struct perf_event *event)
386391
/*
387392
* setup SW LBR filter
388393
*/
389-
intel_pmu_setup_sw_lbr_filter(event);
394+
ret = intel_pmu_setup_sw_lbr_filter(event);
395+
if (ret)
396+
return ret;
390397

391398
/*
392399
* setup HW LBR filter, if any

0 commit comments

Comments
 (0)