Newer Linux kernels have a sysfs tunable /proc/sys/kernel/perf_event_paranoid
which allows the user to adjust the available functionality of perf_events
for non-root users, with higher numbers being more secure (offering correspondingly less functionality):
From the kernel documenation we have the following behavior for the various values:
perf_event_paranoid:
Controls use of the performance events system by unprivileged users (without CAP_SYS_ADMIN). The default value is 2.
-1: Allow use of (almost) all events by all users Ignore mlock limit after perf_event_mlock_kb without CAP_IPC_LOCK
>=0: Disallow ftrace function tracepoint by users without CAP_SYS_ADMIN Disallow raw tracepoint access by users without CAP_SYS_ADMIN
>=1: Disallow CPU event access by users without CAP_SYS_ADMIN
>=2: Disallow kernel profiling by users without CAP_SYS_ADMIN
I have 1
in my perf_event_paranoid
file which should "Disallow CPU event access" - but what does that mean exactly?
A plain reading would imply no access to CPU performance counter events (such as Intel PMU events), but it seems I can access those just fine. For example:
$ perf stat sleep 1
Performance counter stats for 'sleep 1':
0.408734 task-clock (msec) # 0.000 CPUs utilized
1 context-switches # 0.002 M/sec
0 cpu-migrations # 0.000 K/sec
57 page-faults # 0.139 M/sec
1,050,362 cycles # 2.570 GHz
769,135 instructions # 0.73 insn per cycle
152,661 branches # 373.497 M/sec
6,942 branch-misses # 4.55% of all branches
1.000830821 seconds time elapsed
Here, many of the events are CPU PMU events (cycles
, instructions
, branches
, branch-misses
, cache-misses
).
If these aren't the CPU events being referred to, what are they?
uops_issued.any
? – Satiableocperf stat -e uops_issued.any sleep 1
also works. – Barbabra2
prevents kernel profiling, and indeed any kernel CPU events (:k
suffix) return zero when using 2. Since 2 is supposed to be strictly more secure than 1, it implies that user mode events are allowed in 1 and 2, and kernel mode events in 1 (indeed,:k
works when using 1), so "CPU events" must mean something narrower or different than plain PMU events... – Barbabra1
, but probably it tries to defend against directly timing other users' processes, leaving only hyperthreading timing side-channels. – Satiable