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

bpf: Inherit system settings for CPU security mitigations

Currently, there exists a system-wide setting related to CPU security
mitigations, denoted as 'mitigations='. When set to 'mitigations=off', it
deactivates all optional CPU mitigations. Therefore, if we implement a
system-wide 'mitigations=off' setting, it should inherently bypass Spectre
v1 and Spectre v4 in the BPF subsystem.

Please note that there is also a more specific 'nospectre_v1' setting on
x86 and ppc architectures, though it is not currently exported. For the
time being, let's disregard more fine-grained options.

This idea emerged during our discussion about potential Spectre v1 attacks
with Luis [0].

[0] https://lore.kernel.org/bpf/b4fc15f7-b204-767e-ebb9-fdb4233961fb@iogearbox.net

Signed-off-by: Yafang Shao <laoar.shao@gmail.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Acked-by: Stanislav Fomichev <sdf@google.com>
Acked-by: Song Liu <song@kernel.org>
Acked-by: KP Singh <kpsingh@kernel.org>
Cc: Luis Gerhorst <gerhorst@cs.fau.de>
Link: https://lore.kernel.org/bpf/20231005084123.1338-1-laoar.shao@gmail.com

authored by

Yafang Shao and committed by
Daniel Borkmann
bc5bc309 9c8c3fa3

+2 -2
+2 -2
include/linux/bpf.h
··· 2164 2164 2165 2165 static inline bool bpf_bypass_spec_v1(void) 2166 2166 { 2167 - return perfmon_capable(); 2167 + return perfmon_capable() || cpu_mitigations_off(); 2168 2168 } 2169 2169 2170 2170 static inline bool bpf_bypass_spec_v4(void) 2171 2171 { 2172 - return perfmon_capable(); 2172 + return perfmon_capable() || cpu_mitigations_off(); 2173 2173 } 2174 2174 2175 2175 int bpf_map_new_fd(struct bpf_map *map, int flags);