Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

perf tool: Make perf tool aware of SELinux access control

Implement selinux sysfs check to see the system is in enforcing mode and
print warning message with pointer to check audit logs.

Signed-off-by: Alexey Budankov <alexey.budankov@linux.intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: linux-security-module@vger.kernel.org
Cc: selinux@vger.kernel.org
Link: http://lore.kernel.org/lkml/819338ce-d160-4a2f-f1aa-d756a2e7c6fc@linux.intel.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by

Alexey Budankov and committed by
Arnaldo Carvalho de Melo
c1034eb0 a885f3cc

+26 -17
+2 -2
tools/perf/util/cloexec.c
··· 65 65 return 1; 66 66 } 67 67 68 - WARN_ONCE(err != EINVAL && err != EBUSY, 68 + WARN_ONCE(err != EINVAL && err != EBUSY && err != EACCES, 69 69 "perf_event_open(..., PERF_FLAG_FD_CLOEXEC) failed with unexpected error %d (%s)\n", 70 70 err, str_error_r(err, sbuf, sizeof(sbuf))); 71 71 ··· 83 83 if (fd >= 0) 84 84 close(fd); 85 85 86 - if (WARN_ONCE(fd < 0 && err != EBUSY, 86 + if (WARN_ONCE(fd < 0 && err != EBUSY && err != EACCES, 87 87 "perf_event_open(..., 0) failed unexpectedly with error %d (%s)\n", 88 88 err, str_error_r(err, sbuf, sizeof(sbuf)))) 89 89 return -1;
+24 -15
tools/perf/util/evsel.c
··· 2478 2478 int err, char *msg, size_t size) 2479 2479 { 2480 2480 char sbuf[STRERR_BUFSIZE]; 2481 - int printed = 0; 2481 + int printed = 0, enforced = 0; 2482 2482 2483 2483 switch (err) { 2484 2484 case EPERM: 2485 2485 case EACCES: 2486 + printed += scnprintf(msg + printed, size - printed, 2487 + "Access to performance monitoring and observability operations is limited.\n"); 2488 + 2489 + if (!sysfs__read_int("fs/selinux/enforce", &enforced)) { 2490 + if (enforced) { 2491 + printed += scnprintf(msg + printed, size - printed, 2492 + "Enforced MAC policy settings (SELinux) can limit access to performance\n" 2493 + "monitoring and observability operations. Inspect system audit records for\n" 2494 + "more perf_event access control information and adjusting the policy.\n"); 2495 + } 2496 + } 2497 + 2486 2498 if (err == EPERM) 2487 - printed = scnprintf(msg, size, 2499 + printed += scnprintf(msg, size, 2488 2500 "No permission to enable %s event.\n\n", evsel__name(evsel)); 2489 2501 2490 2502 return scnprintf(msg + printed, size - printed, 2491 - "You may not have permission to collect %sstats.\n\n" 2492 - "Consider tweaking /proc/sys/kernel/perf_event_paranoid,\n" 2493 - "which controls use of the performance events system by\n" 2494 - "unprivileged users (without CAP_PERFMON or CAP_SYS_ADMIN).\n\n" 2495 - "The current value is %d:\n\n" 2503 + "Consider adjusting /proc/sys/kernel/perf_event_paranoid setting to open\n" 2504 + "access to performance monitoring and observability operations for users\n" 2505 + "without CAP_PERFMON or CAP_SYS_ADMIN Linux capability.\n" 2506 + "perf_event_paranoid setting is %d:\n" 2496 2507 " -1: Allow use of (almost) all events by all users\n" 2497 2508 " Ignore mlock limit after perf_event_mlock_kb without CAP_IPC_LOCK\n" 2498 - ">= 0: Disallow ftrace function tracepoint by users without CAP_PERFMON or CAP_SYS_ADMIN\n" 2499 - " Disallow raw tracepoint access by users without CAP_SYS_PERFMON or CAP_SYS_ADMIN\n" 2500 - ">= 1: Disallow CPU event access by users without CAP_PERFMON or CAP_SYS_ADMIN\n" 2501 - ">= 2: Disallow kernel profiling by users without CAP_PERFMON or CAP_SYS_ADMIN\n\n" 2502 - "To make this setting permanent, edit /etc/sysctl.conf too, e.g.:\n\n" 2503 - " kernel.perf_event_paranoid = -1\n" , 2504 - target->system_wide ? "system-wide " : "", 2505 - perf_event_paranoid()); 2509 + ">= 0: Disallow raw and ftrace function tracepoint access\n" 2510 + ">= 1: Disallow CPU event access\n" 2511 + ">= 2: Disallow kernel profiling\n" 2512 + "To make the adjusted perf_event_paranoid setting permanent preserve it\n" 2513 + "in /etc/sysctl.conf (e.g. kernel.perf_event_paranoid = <setting>)", 2514 + perf_event_paranoid()); 2506 2515 case ENOENT: 2507 2516 return scnprintf(msg, size, "The %s event is not supported.", evsel__name(evsel)); 2508 2517 case EMFILE: