Skip to content

Commit b0c8fdc

Browse files
dhowellsJames Morris
authored andcommitted
lockdown: Lock down perf when in confidentiality mode
Disallow the use of certain perf facilities that might allow userspace to access kernel data. Signed-off-by: David Howells <[email protected]> Signed-off-by: Matthew Garrett <[email protected]> Reviewed-by: Kees Cook <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Ingo Molnar <[email protected]> Cc: Arnaldo Carvalho de Melo <[email protected]> Signed-off-by: James Morris <[email protected]>
1 parent 9d1f8be commit b0c8fdc

File tree

3 files changed

+9
-0
lines changed

3 files changed

+9
-0
lines changed

include/linux/security.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ enum lockdown_reason {
119119
LOCKDOWN_KCORE,
120120
LOCKDOWN_KPROBES,
121121
LOCKDOWN_BPF_READ,
122+
LOCKDOWN_PERF,
122123
LOCKDOWN_CONFIDENTIALITY_MAX,
123124
};
124125

kernel/events/core.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10798,6 +10798,13 @@ SYSCALL_DEFINE5(perf_event_open,
1079810798
perf_paranoid_kernel() && !capable(CAP_SYS_ADMIN))
1079910799
return -EACCES;
1080010800

10801+
err = security_locked_down(LOCKDOWN_PERF);
10802+
if (err && (attr.sample_type & PERF_SAMPLE_REGS_INTR))
10803+
/* REGS_INTR can leak data, lockdown must prevent this */
10804+
return err;
10805+
10806+
err = 0;
10807+
1080110808
/*
1080210809
* In cgroup mode, the pid argument is used to pass the fd
1080310810
* opened to the cgroup directory in cgroupfs. The cpu argument

security/lockdown/lockdown.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ static char *lockdown_reasons[LOCKDOWN_CONFIDENTIALITY_MAX+1] = {
3434
[LOCKDOWN_KCORE] = "/proc/kcore access",
3535
[LOCKDOWN_KPROBES] = "use of kprobes",
3636
[LOCKDOWN_BPF_READ] = "use of bpf to read kernel RAM",
37+
[LOCKDOWN_PERF] = "unsafe use of perf",
3738
[LOCKDOWN_CONFIDENTIALITY_MAX] = "confidentiality",
3839
};
3940

0 commit comments

Comments
 (0)