Skip to content

Commit b65b87e

Browse files
James Morsegregkh
authored andcommitted
arm64: proton-pack: Include unprivileged eBPF status in Spectre v2 mitigation reporting
commit 58c9a50 upstream. The mitigations for Spectre-BHB are only applied when an exception is taken from user-space. The mitigation status is reported via the spectre_v2 sysfs vulnerabilities file. When unprivileged eBPF is enabled the mitigation in the exception vectors can be avoided by an eBPF program. When unprivileged eBPF is enabled, print a warning and report vulnerable via the sysfs vulnerabilities file. Acked-by: Catalin Marinas <catalin.marinas@arm.com> Signed-off-by: James Morse <james.morse@arm.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 551717c commit b65b87e

1 file changed

Lines changed: 26 additions & 0 deletions

File tree

arch/arm64/kernel/proton-pack.c

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
*/
1919

2020
#include <linux/arm-smccc.h>
21+
#include <linux/bpf.h>
2122
#include <linux/cpu.h>
2223
#include <linux/device.h>
2324
#include <linux/nospec.h>
@@ -110,6 +111,15 @@ static const char *get_bhb_affected_string(enum mitigation_state bhb_state)
110111
}
111112
}
112113

114+
static bool _unprivileged_ebpf_enabled(void)
115+
{
116+
#ifdef CONFIG_BPF_SYSCALL
117+
return !sysctl_unprivileged_bpf_disabled;
118+
#else
119+
return false;
120+
#endif
121+
}
122+
113123
ssize_t cpu_show_spectre_v2(struct device *dev, struct device_attribute *attr,
114124
char *buf)
115125
{
@@ -129,6 +139,9 @@ ssize_t cpu_show_spectre_v2(struct device *dev, struct device_attribute *attr,
129139
v2_str = "CSV2";
130140
fallthrough;
131141
case SPECTRE_MITIGATED:
142+
if (bhb_state == SPECTRE_MITIGATED && _unprivileged_ebpf_enabled())
143+
return sprintf(buf, "Vulnerable: Unprivileged eBPF enabled\n");
144+
132145
return sprintf(buf, "Mitigation: %s%s\n", v2_str, bhb_str);
133146
case SPECTRE_VULNERABLE:
134147
fallthrough;
@@ -1108,3 +1121,16 @@ void noinstr spectre_bhb_patch_loop_iter(struct alt_instr *alt,
11081121
AARCH64_INSN_MOVEWIDE_ZERO);
11091122
*updptr++ = cpu_to_le32(insn);
11101123
}
1124+
1125+
#ifdef CONFIG_BPF_SYSCALL
1126+
#define EBPF_WARN "Unprivileged eBPF is enabled, data leaks possible via Spectre v2 BHB attacks!\n"
1127+
void unpriv_ebpf_notify(int new_state)
1128+
{
1129+
if (spectre_v2_state == SPECTRE_VULNERABLE ||
1130+
spectre_bhb_state != SPECTRE_MITIGATED)
1131+
return;
1132+
1133+
if (!new_state)
1134+
pr_err("WARNING: %s", EBPF_WARN);
1135+
}
1136+
#endif

0 commit comments

Comments
 (0)