Skip to contentSkip to conversation

FAILED: patch "[PATCH] arm64: proton-pack: Include unprivileged eBPF status in" failed to apply to 5.4-stable tree

PATCH [email protected] 2 participants 2 messages Mar 9, 2022

Subsystems (2)
lore
Share & tools
lore

[email protected]

author maintainer
#0 lore raw

The patch below does not apply to the 5.4-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.

thanks,

greg k-h

------------------ original commit in Linus's tree ------------------

From 58c9a5060cb7cd529d49c93954cdafe81c1d642a Mon Sep 17 00:00:00 2001
From: James Morse <[email protected]>
Date: Thu, 3 Mar 2022 16:53:56 +0000
Subject: [PATCH] arm64: proton-pack: Include unprivileged eBPF status in
Spectre v2 mitigation reporting

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.

arch/arm64/kernel/proton-pack.c +26 -0
index d3fbff00993d..6d45c63c6454 100644
@@ -18,6 +18,7 @@
  */
 
 #include <linux/arm-smccc.h>
+#include <linux/bpf.h>
 #include <linux/cpu.h>
 #include <linux/device.h>
 #include <linux/nospec.h>
@@ -111,6 +112,15 @@ static const char *get_bhb_affected_string(enum mitigation_state bhb_state)
 	}
 }
 
+static bool _unprivileged_ebpf_enabled(void)
+{
+#ifdef CONFIG_BPF_SYSCALL
+	return !sysctl_unprivileged_bpf_disabled;
+#else
+	return false;
+#endif
+}
+
 ssize_t cpu_show_spectre_v2(struct device *dev, struct device_attribute *attr,
 			    char *buf)
 {
@@ -130,6 +140,9 @@ ssize_t cpu_show_spectre_v2(struct device *dev, struct device_attribute *attr,
 		v2_str = "CSV2";
 		fallthrough;
 	case SPECTRE_MITIGATED:
+		if (bhb_state == SPECTRE_MITIGATED && _unprivileged_ebpf_enabled())
+			return sprintf(buf, "Vulnerable: Unprivileged eBPF enabled\n");
+
 		return sprintf(buf, "Mitigation: %s%s\n", v2_str, bhb_str);
 	case SPECTRE_VULNERABLE:
 		fallthrough;
@@ -1125,3 +1138,16 @@ void __init spectre_bhb_patch_clearbhb(struct alt_instr *alt,
 	*updptr++ = cpu_to_le32(aarch64_insn_gen_nop());
 	*updptr++ = cpu_to_le32(aarch64_insn_gen_nop());
 }
+
+#ifdef CONFIG_BPF_SYSCALL
+#define EBPF_WARN "Unprivileged eBPF is enabled, data leaks possible via Spectre v2 BHB attacks!\n"
+void unpriv_ebpf_notify(int new_state)
+{
+	if (spectre_v2_state == SPECTRE_VULNERABLE ||
+	    spectre_bhb_state != SPECTRE_MITIGATED)
+		return;
+
+	if (!new_state)
+		pr_err("WARNING: %s", EBPF_WARN);
+}
+#endif
#1 lore raw

Hi Greg,

arch/arm64/kernel/proton-pack.c

Quoted 28 lines · On 09/03/2022 12:05, [email protected] wrote:

The patch below does not apply to the 5.4-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.

------------------ original commit in Linus's tree ------------------

From 58c9a5060cb7cd529d49c93954cdafe81c1d642a Mon Sep 17 00:00:00 2001
From: James Morse <[email protected]>
Date: Thu, 3 Mar 2022 16:53:56 +0000
Subject: [PATCH] arm64: proton-pack: Include unprivileged eBPF status in
Spectre v2 mitigation reporting

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.

arch/arm64/kernel/proton-pack.c +0 -0
index d3fbff00993d..6d45c63c6454 100644

Yup, this far back the code lives in cpu_errata.c, as it hadn't been centralised. I'll look at what is involved in backporting the whole lot...

Thanks,

James