Commit c1034eb0 authored by Alexey Budankov's avatar Alexey Budankov Committed by Arnaldo Carvalho de Melo

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: default avatarAlexey 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.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent a885f3cc
...@@ -65,7 +65,7 @@ static int perf_flag_probe(void) ...@@ -65,7 +65,7 @@ static int perf_flag_probe(void)
return 1; return 1;
} }
WARN_ONCE(err != EINVAL && err != EBUSY, WARN_ONCE(err != EINVAL && err != EBUSY && err != EACCES,
"perf_event_open(..., PERF_FLAG_FD_CLOEXEC) failed with unexpected error %d (%s)\n", "perf_event_open(..., PERF_FLAG_FD_CLOEXEC) failed with unexpected error %d (%s)\n",
err, str_error_r(err, sbuf, sizeof(sbuf))); err, str_error_r(err, sbuf, sizeof(sbuf)));
...@@ -83,7 +83,7 @@ static int perf_flag_probe(void) ...@@ -83,7 +83,7 @@ static int perf_flag_probe(void)
if (fd >= 0) if (fd >= 0)
close(fd); close(fd);
if (WARN_ONCE(fd < 0 && err != EBUSY, if (WARN_ONCE(fd < 0 && err != EBUSY && err != EACCES,
"perf_event_open(..., 0) failed unexpectedly with error %d (%s)\n", "perf_event_open(..., 0) failed unexpectedly with error %d (%s)\n",
err, str_error_r(err, sbuf, sizeof(sbuf)))) err, str_error_r(err, sbuf, sizeof(sbuf))))
return -1; return -1;
......
...@@ -2478,31 +2478,40 @@ int evsel__open_strerror(struct evsel *evsel, struct target *target, ...@@ -2478,31 +2478,40 @@ int evsel__open_strerror(struct evsel *evsel, struct target *target,
int err, char *msg, size_t size) int err, char *msg, size_t size)
{ {
char sbuf[STRERR_BUFSIZE]; char sbuf[STRERR_BUFSIZE];
int printed = 0; int printed = 0, enforced = 0;
switch (err) { switch (err) {
case EPERM: case EPERM:
case EACCES: case EACCES:
printed += scnprintf(msg + printed, size - printed,
"Access to performance monitoring and observability operations is limited.\n");
if (!sysfs__read_int("fs/selinux/enforce", &enforced)) {
if (enforced) {
printed += scnprintf(msg + printed, size - printed,
"Enforced MAC policy settings (SELinux) can limit access to performance\n"
"monitoring and observability operations. Inspect system audit records for\n"
"more perf_event access control information and adjusting the policy.\n");
}
}
if (err == EPERM) if (err == EPERM)
printed = scnprintf(msg, size, printed += scnprintf(msg, size,
"No permission to enable %s event.\n\n", evsel__name(evsel)); "No permission to enable %s event.\n\n", evsel__name(evsel));
return scnprintf(msg + printed, size - printed, return scnprintf(msg + printed, size - printed,
"You may not have permission to collect %sstats.\n\n" "Consider adjusting /proc/sys/kernel/perf_event_paranoid setting to open\n"
"Consider tweaking /proc/sys/kernel/perf_event_paranoid,\n" "access to performance monitoring and observability operations for users\n"
"which controls use of the performance events system by\n" "without CAP_PERFMON or CAP_SYS_ADMIN Linux capability.\n"
"unprivileged users (without CAP_PERFMON or CAP_SYS_ADMIN).\n\n" "perf_event_paranoid setting is %d:\n"
"The current value is %d:\n\n"
" -1: Allow use of (almost) all events by all users\n" " -1: Allow use of (almost) all events by all users\n"
" Ignore mlock limit after perf_event_mlock_kb without CAP_IPC_LOCK\n" " Ignore mlock limit after perf_event_mlock_kb without CAP_IPC_LOCK\n"
">= 0: Disallow ftrace function tracepoint by users without CAP_PERFMON or CAP_SYS_ADMIN\n" ">= 0: Disallow raw and ftrace function tracepoint access\n"
" Disallow raw tracepoint access by users without CAP_SYS_PERFMON or CAP_SYS_ADMIN\n" ">= 1: Disallow CPU event access\n"
">= 1: Disallow CPU event access by users without CAP_PERFMON or CAP_SYS_ADMIN\n" ">= 2: Disallow kernel profiling\n"
">= 2: Disallow kernel profiling by users without CAP_PERFMON or CAP_SYS_ADMIN\n\n" "To make the adjusted perf_event_paranoid setting permanent preserve it\n"
"To make this setting permanent, edit /etc/sysctl.conf too, e.g.:\n\n" "in /etc/sysctl.conf (e.g. kernel.perf_event_paranoid = <setting>)",
" kernel.perf_event_paranoid = -1\n" , perf_event_paranoid());
target->system_wide ? "system-wide " : "",
perf_event_paranoid());
case ENOENT: case ENOENT:
return scnprintf(msg, size, "The %s event is not supported.", evsel__name(evsel)); return scnprintf(msg, size, "The %s event is not supported.", evsel__name(evsel));
case EMFILE: case EMFILE:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment