Skip to content

Commit

Permalink
bpf: Inherit system settings for CPU security mitigations
Browse files Browse the repository at this point in the history
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/[email protected]

Signed-off-by: Yafang Shao <[email protected]>
Signed-off-by: Daniel Borkmann <[email protected]>
Acked-by: Stanislav Fomichev <[email protected]>
Acked-by: Song Liu <[email protected]>
Acked-by: KP Singh <[email protected]>
Cc: Luis Gerhorst <[email protected]>
Link: https://lore.kernel.org/bpf/[email protected]
  • Loading branch information
laoar authored and borkmann committed Oct 6, 2023
1 parent 9c8c3fa commit bc5bc30
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions include/linux/bpf.h
Original file line number Diff line number Diff line change
Expand Up @@ -2164,12 +2164,12 @@ static inline bool bpf_allow_uninit_stack(void)

static inline bool bpf_bypass_spec_v1(void)
{
return perfmon_capable();
return perfmon_capable() || cpu_mitigations_off();
}

static inline bool bpf_bypass_spec_v4(void)
{
return perfmon_capable();
return perfmon_capable() || cpu_mitigations_off();
}

int bpf_map_new_fd(struct bpf_map *map, int flags);
Expand Down

0 comments on commit bc5bc30

Please sign in to comment.