arm64: Mitigate Spectre v1 in the BPF interpreter
Subsystems (6)
PATCH 1/1 arm64: Mitigate Spectre v1 in the BPF interpreter
The BPF verifier can accept programs with unsafe speculative paths by inserting BPF_NOSPEC instructions instead of rejecting them. It relies on those instructions to prevent execution of the unsafe paths.
The arm64 JIT implements BPF_NOSPEC with a speculation barrier, but the interpreter calls barrier_nospec(), which falls back to a no-op on arm64. Programs executed by the interpreter therefore lack the Spectre-v1 barriers assumed by the verifier. Contrary to the code comment, kernel-wide SSBD does not provide this protection, since it mitigates Spectre v4 rather than Spectre v1.
Rename spec_bar() to barrier_nospec() so that the interpreter and other callers receive SB if supported, or DSB NSH followed by ISB otherwise.
Defining barrier_nospec() would also add barriers to the generic copy_from_user() and copy_from_user_iter() paths. These are unnecessary on arm64: its uaccess primitives mask user pointers so that they cannot address kernel memory even when an access_ok() check is mispredicted.
Introduce user_access_may_speculate_kernel_addr(), defaulting to true, and have arm64 return false. Then update the uaccess sites to call barrier_nospec() conditionally on the macro.
--- arch/arm64/include/asm/barrier.h | 6 +++--- arch/arm64/include/asm/uaccess.h | 3 +++ arch/arm64/kernel/proton-pack.c | 2 +- include/linux/uaccess.h | 7 ++++++- kernel/bpf/core.c | 9 +-------- lib/iov_iter.c | 3 ++- 6 files changed, 16 insertions(+), 14 deletions(-)
arch/arm64/include/asm/barrier.h +3 -3
@@ -40,9 +40,9 @@*/ #define dgh () asm volatile("hint #6" : : : "memory") -#define spec_bar () asm volatile(ALTERNATIVE("dsb nsh\nisb\n", \ - SB_BARRIER_INSN"nop\n", \ - ARM64_HAS_SB)) +#define barrier_nospec () asm volatile(ALTERNATIVE("dsb nsh\nisb\n", \ + SB_BARRIER_INSN"nop\n", \ + ARM64_HAS_SB) : : : "memory")#define gsb_ack () asm volatile(GSB_ACK_BARRIER_INSN : : : "memory")#define gsb_sys () asm volatile(GSB_SYS_BARRIER_INSN : : : "memory")
arch/arm64/include/asm/uaccess.h +3 -0
@@ -174,6 +174,9 @@ static inline void __user *__uaccess_mask_ptr(const void __user *ptr)return safe_ptr; } +/* __uaccess_mask_ptr() prevents speculative accesses to kernel addresses. */ +#define user_access_may_speculate_kernel_addr () false +/* * The "__xxx" versions of the user access functions do not verify the address * space - it must have been done previously with a separate "access_ok()"
arch/arm64/kernel/proton-pack.c +1 -1
@@ -559,7 +559,7 @@ static enum mitigation_state spectre_v4_enable_hw_mitigation(void)* could mis-speculate branches and bypass a conditional barrier. */ if (IS_ENABLED (CONFIG_ARM64_ERRATUM_3194386 )) -spec_bar (); +barrier_nospec ();return SPECTRE_MITIGATED ; }
include/linux/uaccess.h +6 -1
@@ -50,6 +50,10 @@#define mask_user_address (src) (src)#endif +#ifndef user_access_may_speculate_kernel_addr +#define user_access_may_speculate_kernel_addr () true +#endif +/* * Architectures should provide two primitives (raw_copy_{to,from}_user()) * and get rid of their private instances of copy_{to,from}_user() and
@@ -179,7 +183,8 @@ _inline_copy_from_user(void *to, const void __user *from, unsigned long n)* lead to nasty side effects *after* the copy is * finished: */ -barrier_nospec (); +if (user_access_may_speculate_kernel_addr ()) +barrier_nospec (); }instrument_copy_from_user_before (to, from, n); res =raw_copy_from_user (to, from, n);
kernel/bpf/core.c +1 -8
@@ -2250,14 +2250,7 @@ static u64 ___bpf_prog_run(u64 *regs, const struct bpf_insn *insn)/* ST, STX and LDX*/ ST_NOSPEC:/* Speculation barrier for mitigating Speculative Store Bypass, -* Bounds-Check Bypass and Type Confusion. In case of arm64, we -* rely on the firmware mitigation as controlled via the ssbd -* kernel parameter. Whenever the mitigation is enabled, it -* works for all of the kernel code with no need to provide any -* additional instructions here. In case of x86, we use 'lfence' -* insn for mitigation. We reuse preexisting logic from Spectre -* v1 mitigation that happens to produce the required code on -* x86 for v4 as well. +* Bounds-Check Bypass and Type Confusion. */ barrier_nospec ();CONT ;
lib/iov_iter.c +2 -1
@@ -60,7 +60,8 @@ size_t copy_from_user_iter(void __user *iter_from, size_t progress,* lead to nasty side effects *after* the copy is * finished: */ -barrier_nospec (); +if (user_access_may_speculate_kernel_addr ()) +barrier_nospec (); } to += progress;instrument_copy_from_user_before (to, iter_from, len);
--
2.43.0
[email protected]
AI reviewThank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Low] bpf: non-standard multi-line comment style in ___bpf_prog_run() --
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [Low] bpf: non-standard multi-line comment style in ___bpf_prog_run() --
commit ac6a06b7dc1000d82907323434c2003bed5a8873
Author: Ryan Roberts <[email protected]>
arm64: Mitigate Spectre v1 in the BPF interpreter
This commit renames spec_bar() to barrier_nospec() on arm64 so that the BPF interpreter emits a speculation barrier for BPF_NOSPEC, while avoiding unnecessary barriers in uaccess paths where user pointers are already masked.
Quoted 8 lines
kernel/bpf/core.c +0
-0@@ -2251,14 +2251,7 @@ static u64 ___bpf_prog_run(u64 *regs, const struct bpf_insn *insn)/* ST, STX and LDX*/ ST_NOSPEC:/* Speculation barrier for mitigating Speculative Store Bypass,
kernel/bpf/core.c static u64 ___bpf_prog_run(u64 *regs, const struct bpf_insn *insn) · line 2255
Quoted 10 lines
kernel/bpf/core.c +1
-8-* Bounds-Check Bypass and Type Confusion. In case of arm64, we -* rely on the firmware mitigation as controlled via the ssbd -* kernel parameter. Whenever the mitigation is enabled, it -* works for all of the kernel code with no need to provide any -* additional instructions here. In case of x86, we use 'lfence' -* insn for mitigation. We reuse preexisting logic from Spectre -* v1 mitigation that happens to produce the required code on -* x86 for v4 as well. +* Bounds-Check Bypass and Type Confusion. */
[Severity: Low]
This isn't a bug, but BPF code uses the multi-line comment style where the opening /* goes on its own line with the comment text starting on the next line.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Quoted 29 lines · On 17/11/2026 17:34, [email protected] wrote:
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [Low] bpf: non-standard multi-line comment style in___bpf_prog_run()--commit
ac6a06b7dc1000d82907323434c2003bed5a8873
Author: Ryan Roberts <[email protected]>arm64: Mitigate Spectre v1 in the BPF interpreter
This commit renames
spec_bar()tobarrier_nospec()on arm64 so that the BPF interpreter emits a speculation barrier forBPF_NOSPEC, while avoiding unnecessary barriers in uaccess paths where user pointers are already masked.Quoted 15 lines
kernel/bpf/core.c +0
-7@@ -2251,14 +2251,7 @@ static u64 ___bpf_prog_run(u64 *regs, const struct bpf_insn *insn)/* ST, STX and LDX*/ ST_NOSPEC:/* Speculation barrier for mitigating Speculative Store Bypass, -* Bounds-Check Bypass and Type Confusion. In case of arm64, we -* rely on the firmware mitigation as controlled via the ssbd -* kernel parameter. Whenever the mitigation is enabled, it -* works for all of the kernel code with no need to provide any -* additional instructions here. In case of x86, we use 'lfence' -* insn for mitigation. We reuse preexisting logic from Spectre -* v1 mitigation that happens to produce the required code on
Quoted 8 lines
kernel/bpf/core.c static u64 ___bpf_prog_run(u64 *regs, const struct bpf_insn *insn) · line 2254
Quoted 3 lines
kernel/bpf/core.c +1
-1-* x86 for v4 as well. +* Bounds-Check Bypass and Type Confusion. */ [Severity: Low]
This isn't a bug, but BPF code uses the multi-line comment style where the opening /* goes on its own line with the comment text starting on the next line.
All other multi-line comments in this file use this more compact style; I was trying to be consistent.
Thanks,
Ryan
Quoted 19 lines · Ryan Roberts
The BPF verifier can accept programs with unsafe speculative paths by inserting
BPF_NOSPECinstructions instead of rejecting them. It relies on those instructions to prevent execution of the unsafe paths.The arm64 JIT implements
BPF_NOSPECwith a speculation barrier, but the interpreter callsbarrier_nospec(), which falls back to a no-op on arm64. Programs executed by the interpreter therefore lack the Spectre-v1 barriers assumed by the verifier. Contrary to the code comment, kernel-wide SSBD does not provide this protection, since it mitigates Spectre v4 rather than Spectre v1.Rename
spec_bar()tobarrier_nospec()so that the interpreter and other callers receive SB if supported, or DSB NSH followed by ISB otherwise.Defining
barrier_nospec()would also add barriers to the genericcopy_from_user()andcopy_from_user_iter()paths. These are unnecessary on arm64: its uaccess primitives mask user pointers so that they cannot address kernel memory even when anaccess_ok()check is mispredicted.
Quoted 7 lines
Introduce
user_access_may_speculate_kernel_addr(), defaulting to true, and have arm64 return false. Then update the uaccess sites to callbarrier_nospec()conditionally on the macro.Fixes d6f1c85f2253 ("bpf: Fall back to nospec for Spectre v1")Signed-off-by Ryan Roberts <[email protected]>
Thanks! Tested that this prevents the attack (just recovery of OOB value, did not aim for real secret) on Cavium ThunderX2 (no FEAT_SB) as expected.
Quoted 112 lines
--- arch/arm64/include/asm/barrier.h | 6 +++--- arch/arm64/include/asm/uaccess.h | 3 +++ arch/arm64/kernel/proton-pack.c | 2 +- include/linux/uaccess.h | 7 ++++++- kernel/bpf/core.c | 9 +-------- lib/iov_iter.c | 3 ++- 6 files changed, 16 insertions(+), 14 deletions(-)arch/arm64/include/asm/barrier.h +3
-3@@ -40,9 +40,9 @@*/ #define dgh () asm volatile("hint #6" : : : "memory") -#define spec_bar () asm volatile(ALTERNATIVE("dsb nsh\nisb\n", \ - SB_BARRIER_INSN"nop\n", \ - ARM64_HAS_SB)) +#define barrier_nospec () asm volatile(ALTERNATIVE("dsb nsh\nisb\n", \ + SB_BARRIER_INSN"nop\n", \ + ARM64_HAS_SB) : : : "memory")#define gsb_ack () asm volatile(GSB_ACK_BARRIER_INSN : : : "memory")#define gsb_sys () asm volatile(GSB_SYS_BARRIER_INSN : : : "memory")arch/arm64/include/asm/uaccess.h +3
-0@@ -174,6 +174,9 @@ static inline void __user *__uaccess_mask_ptr(const void __user *ptr)return safe_ptr; } +/* __uaccess_mask_ptr() prevents speculative accesses to kernel addresses. */ +#define user_access_may_speculate_kernel_addr () false +/* * The "__xxx" versions of the user access functions do not verify the address * space - it must have been done previously with a separate "access_ok()" arch/arm64/kernel/proton-pack.c +1
-1@@ -559,7 +559,7 @@ static enum mitigation_state spectre_v4_enable_hw_mitigation(void)* could mis-speculate branches and bypass a conditional barrier. */ if (IS_ENABLED (CONFIG_ARM64_ERRATUM_3194386 )) -spec_bar (); +barrier_nospec ();return SPECTRE_MITIGATED ; }include/linux/uaccess.h +6
-1@@ -50,6 +50,10 @@#define mask_user_address (src) (src)#endif +#ifndef user_access_may_speculate_kernel_addr +#define user_access_may_speculate_kernel_addr () true +#endif +/* * Architectures should provide two primitives (raw_copy_{to,from}_user()) * and get rid of their private instances of copy_{to,from}_user() and @@ -179,7 +183,8 @@ _inline_copy_from_user(void *to, const void __user *from, unsigned long n)* lead to nasty side effects *after* the copy is * finished: */ -barrier_nospec (); +if (user_access_may_speculate_kernel_addr ()) +barrier_nospec (); }instrument_copy_from_user_before (to, from, n); res =raw_copy_from_user (to, from, n);kernel/bpf/core.c +1
-8@@ -2250,14 +2250,7 @@ static u64 ___bpf_prog_run(u64 *regs, const struct bpf_insn *insn)/* ST, STX and LDX*/ ST_NOSPEC:/* Speculation barrier for mitigating Speculative Store Bypass, -* Bounds-Check Bypass and Type Confusion. In case of arm64, we -* rely on the firmware mitigation as controlled via the ssbd -* kernel parameter. Whenever the mitigation is enabled, it -* works for all of the kernel code with no need to provide any -* additional instructions here. In case of x86, we use 'lfence' -* insn for mitigation. We reuse preexisting logic from Spectre -* v1 mitigation that happens to produce the required code on -* x86 for v4 as well. +* Bounds-Check Bypass and Type Confusion. */ barrier_nospec ();CONT ;lib/iov_iter.c +2
-1@@ -60,7 +60,8 @@ size_t copy_from_user_iter(void __user *iter_from, size_t progress,* lead to nasty side effects *after* the copy is * finished: */ -barrier_nospec (); +if (user_access_may_speculate_kernel_addr ()) +barrier_nospec (); } to += progress;instrument_copy_from_user_before (to, iter_from, len);
Quoted 6 lines · Ryan Roberts
The arm64 JIT implements
BPF_NOSPECwith a speculation barrier, but the interpreter callsbarrier_nospec(), which falls back to a no-op on arm64. Programs executed by the interpreter therefore lack the Spectre-v1 barriers assumed by the verifier. Contrary to the code comment, kernel-wide SSBD does not provide this protection, since it mitigates Spectre v4 rather than Spectre v1.
Nack.
In bpf-next arm64 has no interpreter when the JIT is built.
Catalin Marinas
maintainerQuoted 10 lines · Alexei Starovoitov
Quoted 6 lines · Ryan Roberts
The arm64 JIT implements
BPF_NOSPECwith a speculation barrier, but the interpreter callsbarrier_nospec(), which falls back to a no-op on arm64. Programs executed by the interpreter therefore lack the Spectre-v1 barriers assumed by the verifier. Contrary to the code comment, kernel-wide SSBD does not provide this protection, since it mitigates Spectre v4 rather than Spectre v1.Nack.
In bpf-next arm64 has no interpreter when the JIT is built.
And what about current mainline/stable or when one disables BPF_JIT explicitly? Should we force BPF_JIT=y as well when ALWAYS_ON=y?
Signature · 1 line
Catalin
Quoted 9 lines · Catalin Marinas
Quoted 8 lines · Alexei Starovoitov
Quoted 6 lines · Ryan Roberts
The arm64 JIT implements
BPF_NOSPECwith a speculation barrier, but the interpreter callsbarrier_nospec(), which falls back to a no-op on arm64. Programs executed by the interpreter therefore lack the Spectre-v1 barriers assumed by the verifier. Contrary to the code comment, kernel-wide SSBD does not provide this protection, since it mitigates Spectre v4 rather than Spectre v1.
Quoted 5 lines
Quoted 2 lines
Nack.
In bpf-next arm64 has no interpreter when the JIT is built.And what about current mainline/stable or when one disables
BPF_JITexplicitly? Should we force BPF_JIT=y as well when ALWAYS_ON=y?
Anyone who didn't have BPF_JIT_ALWAYS_ON=y were exposed to speculation attacks forever. The security hole was wide open. We've been saying it forever. At the next merge window we will say
"you cannot make wrong choice anymore".
Quoted 13 lines · Alexei Starovoitov
Quoted 12 lines · Catalin Marinas
Quoted 10 lines · Alexei Starovoitov
Quoted 6 lines · Ryan Roberts
The arm64 JIT implements
BPF_NOSPECwith a speculation barrier, but the interpreter callsbarrier_nospec(), which falls back to a no-op on arm64. Programs executed by the interpreter therefore lack the Spectre-v1 barriers assumed by the verifier. Contrary to the code comment, kernel-wide SSBD does not provide this protection, since it mitigates Spectre v4 rather than Spectre v1.Nack.
In bpf-next arm64 has no interpreter when the JIT is built.
Quoted 7 lines
Quoted 2 lines
And what about current mainline/stable or when one disables
BPF_JITexplicitly? Should we force BPF_JIT=y as well when ALWAYS_ON=y?Anyone who didn't have BPF_JIT_ALWAYS_ON=y were exposed to speculation attacks forever. The security hole was wide open. We've been saying it forever. At the next merge window we will say
"you cannot make wrong choice anymore".
I view this patch as a fix to arm64, not as a fix to BPF. I haven't changed any BPF code - I've only removed an out of date comment in BPF code, which assumed the code path was for Spectre v4 only. But that's not true since Commit dff883d9e93a ("bpf, arm64, powerpc: Change nospec to include v1 barrier").
arm64 was previously nop'ing barrier_nospec() despite seemingly needing it in the same situation as x86. I think this is orthogonal to whether or not the BPF interpreter permits speculation attacks in other places?
Looking at bpf-next, it is still possible to deselect BPF_JIT when building. If this is such a security issue, shouldn't we disallow that on arm64, or at the every least make it an EXPERT option?
Thanks,
Ryan
Quoted 4 lines · Ryan Roberts
I view this patch as a fix to arm64, not as a fix to BPF. I haven't changed any BPF code - I've only removed an out of date comment in BPF code, which assumed the code path was for Spectre v4 only. But that's not true since Commit
dff883d9e93a("bpf, arm64, powerpc: Change nospec to include v1 barrier").
Fair enough, but the arm64 part of that comment is stale. The verifier relies on nospec for v1 since
commit d6f1c85f2253 ("bpf: Fall back to nospec for Spectre v1").
Quoted 3 lines
arm64 was previously nop'ing
barrier_nospec()despite seemingly needing it in the same situation as x86. I think this is orthogonal to whether or not the BPF interpreter permits speculation attacks in other places?
Not quite. In the interpreter the barrier sits behind an indirect branch:
goto *jumptable[insn->code];
arm64 has no retpoline, and the prog can train this branch. With a wrong target the CPU skips ST_NOSPEC and runs the next insn. So the interpreter is still not safe.
Yet you're arguing that you're making bpf interpreter a viable option on arm64. That's just not fair to users.
Say it in the commit log that you're fixing one tiny issue and leaving giant security hole in place.
With that I'm no longer nacking it.
Quoted 3 lines
Looking at bpf-next, it is still possible to deselect
BPF_JITwhen building. If this is such a security issue, shouldn't we disallow that on arm64, or at the every least make it an EXPERT option?
Yeah. Good point. Let's disallow it on arm64 and x86-64.
I'm thinking to push something like this
kernel/bpf/Kconfig +3 -2
@@ -26,8 +26,8 @@ config HAVE_EBPF_JIT_KASAN config ARCH_WANT_DEFAULT_BPF_JIT bool -# Used by archs to tell that kernels that were compiled with BPF JIT support -# have no BPF interpreter. +# Used by archs to tell that kernels with the bpf() system call have the +# BPF JIT compiler and no BPF interpreter. config ARCH_WANT_BPF_JIT_ALWAYS_ON bool
@@ -36,6 +36,7 @@ menu "BPF subsystem" config BPF_SYSCALL bool "Enable bpf() system call" select BPF + select BPF_JIT if ARCH_WANT_BPF_JIT_ALWAYS_ON select IRQ_WORK select NEED_TASKS_RCU select TASKS_TRACE_RCU
Quoted 16 lines · Alexei Starovoitov
Quoted 4 lines · Ryan Roberts
I view this patch as a fix to arm64, not as a fix to BPF. I haven't changed any BPF code - I've only removed an out of date comment in BPF code, which assumed the code path was for Spectre v4 only. But that's not true since Commit
dff883d9e93a("bpf, arm64, powerpc: Change nospec to include v1 barrier").Fair enough, but the arm64 part of that comment is stale. The verifier relies on nospec for v1 since
commitd6f1c85f2253("bpf: Fall back to nospec for Spectre v1").Quoted 3 lines
arm64 was previously nop'ing
barrier_nospec()despite seemingly needing it in the same situation as x86. I think this is orthogonal to whether or not the BPF interpreter permits speculation attacks in other places?Not quite. In the interpreter the barrier sits behind an indirect branch:
Quoted 7 lines
goto *jumptable[insn->code];arm64 has no retpoline, and the prog can train this branch. With a wrong target the CPU skips
ST_NOSPECand runs the next insn. So the interpreter is still not safe.
Yet you're arguing that you're making bpf interpreter a viable option on arm64. That's just not fair to users.
I'm not saying that at all. I wasn't aware that it previously considered unviable.
I noticed this particular issue while doing manual code inspection while working on something else. I sent the patch to close what I perceived to be a bug to try to be a good citizen.
Quoted 3 lines
Say it in the commit log that you're fixing one tiny issue and leaving giant security hole in place.
With that I'm no longer nacking it.
Happy to fix up the commit log as you suggest.
Quoted 25 lines
Quoted 4 lines
Looking at bpf-next, it is still possible to deselect
BPF_JITwhen building. If this is such a security issue, shouldn't we disallow that on arm64, or at the every least make it an EXPERT option?Yeah. Good point. Let's disallow it on arm64 and x86-64.
I'm thinking to push something like this
kernel/bpf/Kconfig +2
-2@@ -26,8 +26,8 @@ config HAVE_EBPF_JIT_KASAN config ARCH_WANT_DEFAULT_BPF_JIT bool -# Used by archs to tell that kernels that were compiled with BPF JIT support -# have no BPF interpreter. +# Used by archs to tell that kernels with the bpf() system call have the +# BPF JIT compiler and no BPF interpreter. config ARCH_WANT_BPF_JIT_ALWAYS_ON bool
kernel/bpf/Kconfig menu "BPF subsystem" · line 42
Quoted 7 lines
kernel/bpf/Kconfig +1
-0@@ -36,6 +36,7 @@ menu "BPF subsystem" config BPF_SYSCALL bool "Enable bpf() system call" select BPF + select BPF_JIT if ARCH_WANT_BPF_JIT_ALWAYS_ON select IRQ_WORK select NEED_TASKS_RCU select TASKS_TRACE_RCU
Seems reasonable as long as we're sure that there are no users that rely on the interpreter on arm64 for some reason?
Would you propose that this is something that should be backported? If so, I'll drop this patch. Otherwise, I'll send a v2 with a more cautious commit log.
Thanks,
Ryan
Catalin Marinas
maintainerQuoted 24 lines · Ryan Roberts
Quoted 23 lines · Alexei Starovoitov
Quoted 4 lines · Ryan Roberts
I view this patch as a fix to arm64, not as a fix to BPF. I haven't changed any BPF code - I've only removed an out of date comment in BPF code, which assumed the code path was for Spectre v4 only. But that's not true since Commit
dff883d9e93a("bpf, arm64, powerpc: Change nospec to include v1 barrier").Fair enough, but the arm64 part of that comment is stale. The verifier relies on nospec for v1 since
commitd6f1c85f2253("bpf: Fall back to nospec for Spectre v1").Quoted 3 lines
arm64 was previously nop'ing
barrier_nospec()despite seemingly needing it in the same situation as x86. I think this is orthogonal to whether or not the BPF interpreter permits speculation attacks in other places?Not quite. In the interpreter the barrier sits behind an indirect branch:
goto *jumptable[insn->code];arm64 has no retpoline, and the prog can train this branch. With a wrong target the CPU skips
ST_NOSPECand runs the next insn. So the interpreter is still not safe.
Yet you're arguing that you're making bpf interpreter a viable option on arm64. That's just not fair to users.
[...]
Quoted 5 lines
Quoted 3 lines
Say it in the commit log that you're fixing one tiny issue and leaving giant security hole in place.
With that I'm no longer nacking it.Happy to fix up the commit log as you suggest.
This patch closes the Spectre v1 hole in the interpreter but, as per Alexei's point, we are still left open to Spectre v2, even with CSV2. CSV2 only isolates branch prediction between contexts and here the predictor could be trained from within the BPF program itself (in theory, not sure if this has been demonstrated on arm64 though). Training it this way is harder but I wonder whether it's worth patching the kernel for v1 or just recommend that people disable unprivileged, interpreted BPF (that's Arm's official recommendation anyway). Would we give the wrong impression that such configuration is safe?
If Alexei makes the Kconfig change to force JIT always on, I'd be inclined to drop this patch.
Signature · 1 line
Catalin
Quoted 44 lines · Catalin Marinas
Quoted 24 lines · Ryan Roberts
Quoted 23 lines · Alexei Starovoitov
Quoted 4 lines · Ryan Roberts
I view this patch as a fix to arm64, not as a fix to BPF. I haven't changed any BPF code - I've only removed an out of date comment in BPF code, which assumed the code path was for Spectre v4 only. But that's not true since Commit
dff883d9e93a("bpf, arm64, powerpc: Change nospec to include v1 barrier").Fair enough, but the arm64 part of that comment is stale. The verifier relies on nospec for v1 since
commitd6f1c85f2253("bpf: Fall back to nospec for Spectre v1").Quoted 3 lines
arm64 was previously nop'ing
barrier_nospec()despite seemingly needing it in the same situation as x86. I think this is orthogonal to whether or not the BPF interpreter permits speculation attacks in other places?Not quite. In the interpreter the barrier sits behind an indirect branch:
goto *jumptable[insn->code];arm64 has no retpoline, and the prog can train this branch. With a wrong target the CPU skips
ST_NOSPECand runs the next insn. So the interpreter is still not safe.
Yet you're arguing that you're making bpf interpreter a viable option on arm64. That's just not fair to users.[...]
Quoted 5 lines
Quoted 3 lines
Say it in the commit log that you're fixing one tiny issue and leaving giant security hole in place.
With that I'm no longer nacking it.Happy to fix up the commit log as you suggest.
This patch closes the Spectre v1 hole in the interpreter but, as per Alexei's point, we are still left open to Spectre v2, even with CSV2. CSV2 only isolates branch prediction between contexts and here the predictor could be trained from within the BPF program itself (in theory, not sure if this has been demonstrated on arm64 though). Training it this way is harder but I wonder whether it's worth patching the kernel for v1 or just recommend that people disable unprivileged, interpreted BPF (that's Arm's official recommendation anyway). Would we give the wrong impression that such configuration is safe?
Quoted 2 lines
If Alexei makes the
Kconfigchange to force JIT always on, I'd be inclined to drop this patch.
Works for me.
Quoted 5 lines · Ryan Roberts
Quoted 3 lines
If Alexei makes the
Kconfigchange to force JIT always on, I'd be inclined to drop this patch.Works for me.
kconfig change was applied to bpf-next.