]> git.proxmox.com Git - mirror_ubuntu-kernels.git/commitdiff
ARM: include unprivileged BPF status in Spectre V2 reporting
authorRussell King (Oracle) <rmk+kernel@armlinux.org.uk>
Mon, 7 Mar 2022 19:28:32 +0000 (19:28 +0000)
committerRussell King (Oracle) <rmk+kernel@armlinux.org.uk>
Tue, 8 Mar 2022 14:46:08 +0000 (14:46 +0000)
The mitigations for Spectre-BHB are only applied when an exception
is taken, but when unprivileged BPF is enabled, userspace can
load BPF programs that can be used to exploit the problem.

When unprivileged BPF is enabled, report the vulnerable status via
the spectre_v2 sysfs file.

Signed-off-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>
arch/arm/kernel/spectre.c

index ade967f18d069219b285fa345e916991e32794dd..e7fea962d632cca4d90eeca2c762f276e87cbddc 100644 (file)
@@ -1,9 +1,19 @@
 // SPDX-License-Identifier: GPL-2.0-only
+#include <linux/bpf.h>
 #include <linux/cpu.h>
 #include <linux/device.h>
 
 #include <asm/spectre.h>
 
+static bool _unprivileged_ebpf_enabled(void)
+{
+#ifdef CONFIG_BPF_SYSCALL
+       return !sysctl_unprivileged_bpf_disabled;
+#else
+       return false
+#endif
+}
+
 ssize_t cpu_show_spectre_v1(struct device *dev, struct device_attribute *attr,
                            char *buf)
 {
@@ -31,6 +41,9 @@ ssize_t cpu_show_spectre_v2(struct device *dev, struct device_attribute *attr,
        if (spectre_v2_state != SPECTRE_MITIGATED)
                return sprintf(buf, "%s\n", "Vulnerable");
 
+       if (_unprivileged_ebpf_enabled())
+               return sprintf(buf, "Vulnerable: Unprivileged eBPF enabled\n");
+
        switch (spectre_v2_methods) {
        case SPECTRE_V2_METHOD_BPIALL:
                method = "Branch predictor hardening";