x86/bugs: RSB mitigation fixes and documentation
Subsystems (6)
Josh Poimboeuf
maintainerv4 cover x86/bugs: RSB mitigation fixes and documentation
v4:
- improve document
- remove C++ comment
- "__write_ibpb" -> "write-ibpb"
- improve commit logs
v3: https://lore.kernel.org/[email protected]
Josh Poimboeuf (6):
x86/bugs: Rename entry_ibpb() to write_ibpb()
x86/bugs: Use SBPB in write_ibpb() if applicable x86/bugs: Fix RSB clearing in indirect_branch_prediction_barrier() x86/bugs: Don't fill RSB on VMEXIT with eIBRS+retpoline x86/bugs: Don't fill RSB on context switch with eIBRS x86/bugs: Add RSB mitigation document
Documentation/admin-guide/hw-vuln/index.rst | 1 + Documentation/admin-guide/hw-vuln/rsb.rst | 268 ++++++++++++++++++++ arch/x86/entry/entry.S | 9 +- arch/x86/include/asm/nospec-branch.h | 12 +- arch/x86/kernel/cpu/bugs.c | 107 +++----- arch/x86/mm/tlb.c | 6 +- 6 files changed, 317 insertions(+), 86 deletions(-) create mode 100644 Documentation/admin-guide/hw-vuln/rsb.rst
Signature · 1 line
2.49.0
Josh Poimboeuf
maintainerPATCH v4 1/6 x86/bugs: Rename entry_ibpb() to write_ibpb()
There's nothing entry-specific about entry_ibpb(). In preparation for calling it from elsewhere, rename it to write_ibpb().
--- arch/x86/entry/entry.S | 7 ++++--- arch/x86/include/asm/nospec-branch.h | 6 +++--- arch/x86/kernel/cpu/bugs.c | 6 +++--- 3 files changed, 10 insertions(+), 9 deletions(-)
arch/x86/entry/entry.S +4 -3
@@ -17,7 +17,8 @@ .pushsection .noinstr.text, "ax" -SYM_FUNC_START(entry_ibpb) +/* Clobbers AX, CX, DX */ +SYM_FUNC_START(write_ibpb) ANNOTATE_NOENDBR movl $MSR_IA32_PRED_CMD, %ecx movl $PRED_CMD_IBPB, %eax
@@ -27,9 +28,9 @@ SYM_FUNC_START(entry_ibpb) /* Make sure IBPB clears return stack preductions too. */ FILL_RETURN_BUFFER %rax, RSB_CLEAR_LOOPS, X86_BUG_IBPB_NO_RET RET -SYM_FUNC_END(entry_ibpb) +SYM_FUNC_END(write_ibpb) /* For KVM */ -EXPORT_SYMBOL_GPL(entry_ibpb); +EXPORT_SYMBOL_GPL(write_ibpb); .popsection
arch/x86/include/asm/nospec-branch.h +3 -3
@@ -269,7 +269,7 @@* typically has NO_MELTDOWN). * * While retbleed_untrain_ret() doesn't clobber anything but requires stack, -* entry_ibpb() will clobber AX, CX, DX. +* write_ibpb() will clobber AX, CX, DX. * * As such, this must be placed after every *SWITCH_TO_KERNEL_CR3 at a point * where we have a stack but before any RET instruction.
@@ -279,7 +279,7 @@VALIDATE_UNRET_END CALL_UNTRAIN_RETALTERNATIVE_2 "" , \ - "call entry_ibpb", \ibpb_feature, \ + "call write_ibpb", \ibpb_feature, \ __stringify(\call_depth_insns), X86_FEATURE_CALL_DEPTH #endif .endm
@@ -368,7 +368,7 @@ extern void srso_return_thunk(void);extern void srso_alias_return_thunk (void );extern void entry_untrain_ret (void ); -extern void entry_ibpb (void ); +extern void write_ibpb (void );#ifdef CONFIG_X86_64 extern void clear_bhb_loop (void );
arch/x86/kernel/cpu/bugs.c +3 -3
@@ -1142,7 +1142,7 @@ static void __init retbleed_select_mitigation(void)setup_clear_cpu_cap (X86_FEATURE_RETHUNK );/* -* There is no need for RSB filling: entry_ibpb() ensures +* There is no need for RSB filling: write_ibpb() ensures * all predictions, including the RSB, are invalidated, * regardless of IBPB implementation. */
@@ -2676,7 +2676,7 @@ static void __init srso_select_mitigation(void)setup_clear_cpu_cap (X86_FEATURE_RETHUNK );/* -* There is no need for RSB filling: entry_ibpb() ensures +* There is no need for RSB filling: write_ibpb() ensures * all predictions, including the RSB, are invalidated, * regardless of IBPB implementation. */
@@ -2701,7 +2701,7 @@ static void __init srso_select_mitigation(void) srso_mitigation =SRSO_MITIGATION_IBPB_ON_VMEXIT ;/* -* There is no need for RSB filling: entry_ibpb() ensures +* There is no need for RSB filling: write_ibpb() ensures * all predictions, including the RSB, are invalidated, * regardless of IBPB implementation. */
Signature · 1 line
2.49.0
[tip: x86/urgent] x86/bugs: Rename entry_ibpb() to write_ibpb()
The following commit has been merged into the x86/urgent branch of tip:
The following commit has been merged into the x86/urgent branch of tip:
Commit-ID: 13235d6d50bba99931c4392c0f813cfae0de3eac Gitweb: https://git.kernel.org/tip/13235d6d50bba99931c4392c0f813cfae0de3eac Author: Josh Poimboeuf <[email protected]> AuthorDate: Tue, 08 Apr 2025 14:47:30 -07:00 Committer: Ingo Molnar <[email protected]> CommitterDate: Wed, 09 Apr 2025 12:41:29 +02:00
x86/bugs: Rename entry_ibpb() to write_ibpb()
There's nothing entry-specific about entry_ibpb(). In preparation for calling it from elsewhere, rename it to write_ibpb().
--- arch/x86/entry/entry.S | 7 ++++--- arch/x86/include/asm/nospec-branch.h | 6 +++--- arch/x86/kernel/cpu/bugs.c | 6 +++--- 3 files changed, 10 insertions(+), 9 deletions(-)
arch/x86/entry/entry.S +4 -3
@@ -17,7 +17,8 @@ .pushsection .noinstr.text, "ax" -SYM_FUNC_START(entry_ibpb) +/* Clobbers AX, CX, DX */ +SYM_FUNC_START(write_ibpb) ANNOTATE_NOENDBR movl $MSR_IA32_PRED_CMD, %ecx movl $PRED_CMD_IBPB, %eax
@@ -27,9 +28,9 @@ SYM_FUNC_START(entry_ibpb) /* Make sure IBPB clears return stack preductions too. */ FILL_RETURN_BUFFER %rax, RSB_CLEAR_LOOPS, X86_BUG_IBPB_NO_RET RET -SYM_FUNC_END(entry_ibpb) +SYM_FUNC_END(write_ibpb) /* For KVM */ -EXPORT_SYMBOL_GPL(entry_ibpb); +EXPORT_SYMBOL_GPL(write_ibpb); .popsection
arch/x86/include/asm/nospec-branch.h +3 -3
@@ -269,7 +269,7 @@* typically has NO_MELTDOWN). * * While retbleed_untrain_ret() doesn't clobber anything but requires stack, -* entry_ibpb() will clobber AX, CX, DX. +* write_ibpb() will clobber AX, CX, DX. * * As such, this must be placed after every *SWITCH_TO_KERNEL_CR3 at a point * where we have a stack but before any RET instruction.
@@ -279,7 +279,7 @@VALIDATE_UNRET_END CALL_UNTRAIN_RETALTERNATIVE_2 "" , \ - "call entry_ibpb", \ibpb_feature, \ + "call write_ibpb", \ibpb_feature, \ __stringify(\call_depth_insns), X86_FEATURE_CALL_DEPTH #endif .endm
@@ -368,7 +368,7 @@ extern void srso_return_thunk(void);extern void srso_alias_return_thunk (void );extern void entry_untrain_ret (void ); -extern void entry_ibpb (void ); +extern void write_ibpb (void );#ifdef CONFIG_X86_64 extern void clear_bhb_loop (void );
arch/x86/kernel/cpu/bugs.c +3 -3
@@ -1142,7 +1142,7 @@ do_cmd_auto:setup_clear_cpu_cap (X86_FEATURE_RETHUNK );/* -* There is no need for RSB filling: entry_ibpb() ensures +* There is no need for RSB filling: write_ibpb() ensures * all predictions, including the RSB, are invalidated, * regardless of IBPB implementation. */
@@ -2676,7 +2676,7 @@ static void __init srso_select_mitigation(void)setup_clear_cpu_cap (X86_FEATURE_RETHUNK );/* -* There is no need for RSB filling: entry_ibpb() ensures +* There is no need for RSB filling: write_ibpb() ensures * all predictions, including the RSB, are invalidated, * regardless of IBPB implementation. */
@@ -2701,7 +2701,7 @@ ibpb_on_vmexit: srso_mitigation =SRSO_MITIGATION_IBPB_ON_VMEXIT ;/* -* There is no need for RSB filling: entry_ibpb() ensures +* There is no need for RSB filling: write_ibpb() ensures * all predictions, including the RSB, are invalidated, * regardless of IBPB implementation. */
Josh Poimboeuf
maintainerPATCH v4 2/6 x86/bugs: Use SBPB in write_ibpb() if applicable
In reply to Josh Poimboeufwrite_ibpb() does IBPB, which (among other things) flushes branch type predictions on AMD. If the CPU has SRSO_NO, or if the SRSO mitigation has been disabled, branch type flushing isn't needed, in which case the lighter-weight SBPB can be used.
The 'x86_pred_cmd' variable already keeps track of whether IBPB or SBPB should be used. Use that instead of hardcoding IBPB.
--- arch/x86/entry/entry.S | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/entry/entry.S +1 -1
@@ -21,7 +21,7 @@ SYM_FUNC_START(write_ibpb) ANNOTATE_NOENDBR movl $MSR_IA32_PRED_CMD, %ecx - movl $PRED_CMD_IBPB, %eax + movl _ASM_RIP(x86_pred_cmd), %eax xorl %edx, %edx wrmsr
Signature · 1 line
2.49.0
[tip: x86/urgent] x86/bugs: Use SBPB in write_ibpb() if applicable
The following commit has been merged into the x86/urgent branch of tip:
The following commit has been merged into the x86/urgent branch of tip:
Commit-ID: fc9fd3f98423367c79e0bd85a9515df26dc1b3cc Gitweb: https://git.kernel.org/tip/fc9fd3f98423367c79e0bd85a9515df26dc1b3cc Author: Josh Poimboeuf <[email protected]> AuthorDate: Tue, 08 Apr 2025 14:47:31 -07:00 Committer: Ingo Molnar <[email protected]> CommitterDate: Wed, 09 Apr 2025 12:41:30 +02:00
x86/bugs: Use SBPB in write_ibpb() if applicable
write_ibpb() does IBPB, which (among other things) flushes branch type predictions on AMD. If the CPU has SRSO_NO, or if the SRSO mitigation has been disabled, branch type flushing isn't needed, in which case the lighter-weight SBPB can be used.
The 'x86_pred_cmd' variable already keeps track of whether IBPB or SBPB should be used. Use that instead of hardcoding IBPB.
--- arch/x86/entry/entry.S | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/entry/entry.S +1 -1
@@ -21,7 +21,7 @@ SYM_FUNC_START(write_ibpb) ANNOTATE_NOENDBR movl $MSR_IA32_PRED_CMD, %ecx - movl $PRED_CMD_IBPB, %eax + movl _ASM_RIP(x86_pred_cmd), %eax xorl %edx, %edx wrmsr
Josh Poimboeuf
maintainerPATCH v4 3/6 x86/bugs: Fix RSB clearing in indirect_branch_prediction_barrier()
In reply to Josh PoimboeufIBPB is expected to clear the RSB. However, if X86_BUG_IBPB_NO_RET is set, that doesn't happen. Make indirect_branch_prediction_barrier() take that into account by calling write_ibpb() which clears RSB on X86_BUG_IBPB_NO_RET:
/* Make sure IBPB clears return stack preductions too. */ FILL_RETURN_BUFFER %rax, RSB_CLEAR_LOOPS, X86_BUG_IBPB_NO_RET
Note that, as of the previous patch, write_ibpb() also reads 'x86_pred_cmd' in order to use SBPB when applicable:
movl _ASM_RIP(x86_pred_cmd), %eax
Therefore that existing behavior in indirect_branch_prediction_barrier() is not lost.
--- arch/x86/include/asm/nospec-branch.h | 6 +++--- arch/x86/kernel/cpu/bugs.c | 1 - 2 files changed, 3 insertions(+), 4 deletions(-)
arch/x86/include/asm/nospec-branch.h +3 -3
@@ -514,11 +514,11 @@ void alternative_msr_write(unsigned int msr, u64 val, unsigned int feature) : "memory"); } -extern u64 x86_pred_cmd; -static inline void indirect_branch_prediction_barrier (void ) { -alternative_msr_write (MSR_IA32_PRED_CMD , x86_pred_cmd,X86_FEATURE_IBPB ); + asm_inline volatile(ALTERNATIVE("", "call write_ibpb", X86_FEATURE_IBPB) + : ASM_CALL_CONSTRAINT + :: "rax", "rcx", "rdx", "memory"); }/* The Intel SPEC CTRL MSR base value cache */
arch/x86/kernel/cpu/bugs.c +0 -1
@@ -59,7 +59,6 @@ DEFINE_PER_CPU(u64, x86_spec_ctrl_current);EXPORT_PER_CPU_SYMBOL_GPL (x86_spec_ctrl_current);u64 x86_pred_cmd__ro_after_init =PRED_CMD_IBPB ; -EXPORT_SYMBOL_GPL (x86_pred_cmd);static u64 __ro_after_init x86_arch_cap_msr;
Signature · 1 line
2.49.0
[tip: x86/urgent] x86/bugs: Fix RSB clearing in indirect_branch_prediction_barrier()
The following commit has been merged into the x86/urgent branch of tip:
The following commit has been merged into the x86/urgent branch of tip:
Commit-ID: b1b19cfcf4656c75088dc06b7499f493e0dec3e5 Gitweb: https://git.kernel.org/tip/b1b19cfcf4656c75088dc06b7499f493e0dec3e5 Author: Josh Poimboeuf <[email protected]> AuthorDate: Tue, 08 Apr 2025 14:47:32 -07:00 Committer: Ingo Molnar <[email protected]> CommitterDate: Wed, 09 Apr 2025 12:41:30 +02:00
x86/bugs: Fix RSB clearing in indirect_branch_prediction_barrier()
IBPB is expected to clear the RSB. However, if X86_BUG_IBPB_NO_RET is set, that doesn't happen. Make indirect_branch_prediction_barrier() take that into account by calling write_ibpb() which clears RSB on X86_BUG_IBPB_NO_RET:
/* Make sure IBPB clears return stack preductions too. */ FILL_RETURN_BUFFER %rax, RSB_CLEAR_LOOPS, X86_BUG_IBPB_NO_RET
Note that, as of the previous patch, write_ibpb() also reads 'x86_pred_cmd' in order to use SBPB when applicable:
movl _ASM_RIP(x86_pred_cmd), %eax
Therefore that existing behavior in indirect_branch_prediction_barrier() is not lost.
--- arch/x86/include/asm/nospec-branch.h | 6 +++--- arch/x86/kernel/cpu/bugs.c | 1 - 2 files changed, 3 insertions(+), 4 deletions(-)
arch/x86/include/asm/nospec-branch.h +3 -3
@@ -514,11 +514,11 @@ void alternative_msr_write(unsigned int msr, u64 val, unsigned int feature) : "memory"); } -extern u64 x86_pred_cmd; -static inline void indirect_branch_prediction_barrier (void ) { -alternative_msr_write (MSR_IA32_PRED_CMD , x86_pred_cmd,X86_FEATURE_IBPB ); + asm_inline volatile(ALTERNATIVE("", "call write_ibpb", X86_FEATURE_IBPB) + : ASM_CALL_CONSTRAINT + :: "rax", "rcx", "rdx", "memory"); }/* The Intel SPEC CTRL MSR base value cache */
arch/x86/kernel/cpu/bugs.c +0 -1
@@ -59,7 +59,6 @@ DEFINE_PER_CPU(u64, x86_spec_ctrl_current);EXPORT_PER_CPU_SYMBOL_GPL (x86_spec_ctrl_current);u64 x86_pred_cmd__ro_after_init =PRED_CMD_IBPB ; -EXPORT_SYMBOL_GPL (x86_pred_cmd);static u64 __ro_after_init x86_arch_cap_msr;
Josh Poimboeuf
maintainerPATCH v4 4/6 x86/bugs: Don't fill RSB on VMEXIT with eIBRS+retpoline
In reply to Josh PoimboeufeIBRS protects against guest->host RSB underflow/poisoning attacks. Adding retpoline to the mix doesn't change that. Retpoline has a balanced CALL/RET anyway.
So the current full RSB filling on VMEXIT with eIBRS+retpoline is overkill. Disable it or do the VMEXIT_LITE mitigation if needed.
--- arch/x86/kernel/cpu/bugs.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
arch/x86/kernel/cpu/bugs.c +4 -4
@@ -1617,20 +1617,20 @@ static void __init spectre_v2_determine_rsb_fill_type_at_vmexit(enum spectre_v2_case SPECTRE_V2_NONE :return ; -case SPECTRE_V2_EIBRS_LFENCE :case SPECTRE_V2_EIBRS : +case SPECTRE_V2_EIBRS_LFENCE : +case SPECTRE_V2_EIBRS_RETPOLINE :if (boot_cpu_has_bug (X86_BUG_EIBRS_PBRSB )) { -setup_force_cpu_cap (X86_FEATURE_RSB_VMEXIT_LITE );pr_info ("Spectre v2 / PBRSB-eIBRS: Retire a single CALL on VMEXIT\n" ); +setup_force_cpu_cap (X86_FEATURE_RSB_VMEXIT_LITE ); }return ; -case SPECTRE_V2_EIBRS_RETPOLINE :case SPECTRE_V2_RETPOLINE :case SPECTRE_V2_LFENCE :case SPECTRE_V2_IBRS : -setup_force_cpu_cap (X86_FEATURE_RSB_VMEXIT );pr_info ("Spectre v2 / SpectreRSB : Filling RSB on VMEXIT\n" ); +setup_force_cpu_cap (X86_FEATURE_RSB_VMEXIT );return ; }
Signature · 1 line
2.49.0
[tip: x86/urgent] x86/bugs: Don't fill RSB on VMEXIT with eIBRS+retpoline
The following commit has been merged into the x86/urgent branch of tip:
The following commit has been merged into the x86/urgent branch of tip:
Commit-ID: 18bae0dfec15b24ec14ca17dc18603372f5f254f Gitweb: https://git.kernel.org/tip/18bae0dfec15b24ec14ca17dc18603372f5f254f Author: Josh Poimboeuf <[email protected]> AuthorDate: Tue, 08 Apr 2025 14:47:33 -07:00 Committer: Ingo Molnar <[email protected]> CommitterDate: Wed, 09 Apr 2025 12:41:55 +02:00
x86/bugs: Don't fill RSB on VMEXIT with eIBRS+retpoline
eIBRS protects against guest->host RSB underflow/poisoning attacks. Adding retpoline to the mix doesn't change that. Retpoline has a balanced CALL/RET anyway.
So the current full RSB filling on VMEXIT with eIBRS+retpoline is overkill. Disable it or do the VMEXIT_LITE mitigation if needed.
--- arch/x86/kernel/cpu/bugs.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
arch/x86/kernel/cpu/bugs.c +4 -4
@@ -1617,20 +1617,20 @@ static void __init spectre_v2_determine_rsb_fill_type_at_vmexit(enum spectre_v2_case SPECTRE_V2_NONE :return ; -case SPECTRE_V2_EIBRS_LFENCE :case SPECTRE_V2_EIBRS : +case SPECTRE_V2_EIBRS_LFENCE : +case SPECTRE_V2_EIBRS_RETPOLINE :if (boot_cpu_has_bug (X86_BUG_EIBRS_PBRSB )) { -setup_force_cpu_cap (X86_FEATURE_RSB_VMEXIT_LITE );pr_info ("Spectre v2 / PBRSB-eIBRS: Retire a single CALL on VMEXIT\n" ); +setup_force_cpu_cap (X86_FEATURE_RSB_VMEXIT_LITE ); }return ; -case SPECTRE_V2_EIBRS_RETPOLINE :case SPECTRE_V2_RETPOLINE :case SPECTRE_V2_LFENCE :case SPECTRE_V2_IBRS : -setup_force_cpu_cap (X86_FEATURE_RSB_VMEXIT );pr_info ("Spectre v2 / SpectreRSB : Filling RSB on VMEXIT\n" ); +setup_force_cpu_cap (X86_FEATURE_RSB_VMEXIT );return ; }
Josh Poimboeuf
maintainerPATCH v4 5/6 x86/bugs: Don't fill RSB on context switch with eIBRS
In reply to Josh PoimboeufUser->user Spectre v2 attacks (including RSB) across context switches are already mitigated by IBPB in cond_mitigation(), if enabled globally or if either the prev or the next task has opted in to protection. RSB filling without IBPB serves no purpose for protecting user space, as indirect branches are still vulnerable.
User->kernel RSB attacks are mitigated by eIBRS. In which case the RSB filling on context switch isn't needed, so remove it.
--- arch/x86/kernel/cpu/bugs.c | 24 ++++++++++++------------ arch/x86/mm/tlb.c | 6 +++--- 2 files changed, 15 insertions(+), 15 deletions(-)
arch/x86/kernel/cpu/bugs.c +12 -12
@@ -1591,7 +1591,7 @@ static void __init spec_ctrl_disable_kernel_rrsba(void) rrsba_disabled = true; } -static void __init spectre_v2_determine_rsb_fill_type_at_vmexit (enum spectre_v2_mitigation mode) +static void __init spectre_v2_select_rsb_mitigation (enum spectre_v2_mitigation mode) {/* * Similar to context switches, there are two types of RSB attacks
@@ -1615,7 +1615,7 @@ static void __init spectre_v2_determine_rsb_fill_type_at_vmexit(enum spectre_v2_*/ switch (mode) {case SPECTRE_V2_NONE : -return ; +break ;case SPECTRE_V2_EIBRS :case SPECTRE_V2_EIBRS_LFENCE :
@@ -1624,18 +1624,21 @@ static void __init spectre_v2_determine_rsb_fill_type_at_vmexit(enum spectre_v2_pr_info ("Spectre v2 / PBRSB-eIBRS: Retire a single CALL on VMEXIT\n" );setup_force_cpu_cap (X86_FEATURE_RSB_VMEXIT_LITE ); } -return ; +break ;case SPECTRE_V2_RETPOLINE :case SPECTRE_V2_LFENCE :case SPECTRE_V2_IBRS : -pr_info ("Spectre v2 / SpectreRSB : Filling RSB on VMEXIT\n" ); +pr_info ("Spectre v2 / SpectreRSB: Filling RSB on context switch and VMEXIT\n" ); +setup_force_cpu_cap (X86_FEATURE_RSB_CTXSW );setup_force_cpu_cap (X86_FEATURE_RSB_VMEXIT ); -return ; - } +break ; -pr_warn_once ("Unknown Spectre v2 mode, disabling RSB mitigation at VM exit" ); -dump_stack (); +default : +pr_warn_once ("Unknown Spectre v2 mode, disabling RSB mitigation\n" ); +dump_stack (); +break ; + } }/*
@@ -1867,10 +1870,7 @@ static void __init spectre_v2_select_mitigation(void)* * FIXME: Is this pointless for retbleed-affected AMD? */ -setup_force_cpu_cap (X86_FEATURE_RSB_CTXSW ); -pr_info ("Spectre v2 / SpectreRSB mitigation: Filling RSB on context switch\n" ); - -spectre_v2_determine_rsb_fill_type_at_vmexit (mode); +spectre_v2_select_rsb_mitigation (mode);/* * Retpoline protects the kernel, but doesn't protect firmware. IBRS
arch/x86/mm/tlb.c +3 -3
@@ -672,9 +672,9 @@ static void cond_mitigation(struct task_struct *next) prev_mm =this_cpu_read (cpu_tlbstate.last_user_mm_spec);/* -* Avoid user/user BTB poisoning by flushing the branch predictor -* when switching between processes. This stops one process from -* doing Spectre-v2 attacks on another. +* Avoid user->user BTB/RSB poisoning by flushing them when switching +* between processes. This stops one process from doing Spectre-v2 +* attacks on another. * * Both, the conditional and the always IBPB mode use the mm * pointer to avoid the IBPB when switching between tasks of the
Signature · 1 line
2.49.0
[tip: x86/urgent] x86/bugs: Don't fill RSB on context switch with eIBRS
The following commit has been merged into the x86/urgent branch of tip:
The following commit has been merged into the x86/urgent branch of tip:
Commit-ID: 27ce8299bc1ec6df8306073785ff82b30b3cc5ee Gitweb: https://git.kernel.org/tip/27ce8299bc1ec6df8306073785ff82b30b3cc5ee Author: Josh Poimboeuf <[email protected]> AuthorDate: Tue, 08 Apr 2025 14:47:34 -07:00 Committer: Ingo Molnar <[email protected]> CommitterDate: Wed, 09 Apr 2025 12:42:09 +02:00
x86/bugs: Don't fill RSB on context switch with eIBRS
User->user Spectre v2 attacks (including RSB) across context switches are already mitigated by IBPB in cond_mitigation(), if enabled globally or if either the prev or the next task has opted in to protection. RSB filling without IBPB serves no purpose for protecting user space, as indirect branches are still vulnerable.
User->kernel RSB attacks are mitigated by eIBRS. In which case the RSB filling on context switch isn't needed, so remove it.
--- arch/x86/kernel/cpu/bugs.c | 24 ++++++++++++------------ arch/x86/mm/tlb.c | 6 +++--- 2 files changed, 15 insertions(+), 15 deletions(-)
arch/x86/kernel/cpu/bugs.c +12 -12
@@ -1591,7 +1591,7 @@ static void __init spec_ctrl_disable_kernel_rrsba(void) rrsba_disabled = true; } -static void __init spectre_v2_determine_rsb_fill_type_at_vmexit (enum spectre_v2_mitigation mode) +static void __init spectre_v2_select_rsb_mitigation (enum spectre_v2_mitigation mode) {/* * Similar to context switches, there are two types of RSB attacks
@@ -1615,7 +1615,7 @@ static void __init spectre_v2_determine_rsb_fill_type_at_vmexit(enum spectre_v2_*/ switch (mode) {case SPECTRE_V2_NONE : -return ; +break ;case SPECTRE_V2_EIBRS :case SPECTRE_V2_EIBRS_LFENCE :
@@ -1624,18 +1624,21 @@ static void __init spectre_v2_determine_rsb_fill_type_at_vmexit(enum spectre_v2_pr_info ("Spectre v2 / PBRSB-eIBRS: Retire a single CALL on VMEXIT\n" );setup_force_cpu_cap (X86_FEATURE_RSB_VMEXIT_LITE ); } -return ; +break ;case SPECTRE_V2_RETPOLINE :case SPECTRE_V2_LFENCE :case SPECTRE_V2_IBRS : -pr_info ("Spectre v2 / SpectreRSB : Filling RSB on VMEXIT\n" ); +pr_info ("Spectre v2 / SpectreRSB: Filling RSB on context switch and VMEXIT\n" ); +setup_force_cpu_cap (X86_FEATURE_RSB_CTXSW );setup_force_cpu_cap (X86_FEATURE_RSB_VMEXIT ); -return ; - } +break ; -pr_warn_once ("Unknown Spectre v2 mode, disabling RSB mitigation at VM exit" ); -dump_stack (); +default : +pr_warn_once ("Unknown Spectre v2 mode, disabling RSB mitigation\n" ); +dump_stack (); +break ; + } }/*
@@ -1867,10 +1870,7 @@ static void __init spectre_v2_select_mitigation(void)* * FIXME: Is this pointless for retbleed-affected AMD? */ -setup_force_cpu_cap (X86_FEATURE_RSB_CTXSW ); -pr_info ("Spectre v2 / SpectreRSB mitigation: Filling RSB on context switch\n" ); - -spectre_v2_determine_rsb_fill_type_at_vmexit (mode); +spectre_v2_select_rsb_mitigation (mode);/* * Retpoline protects the kernel, but doesn't protect firmware. IBRS
arch/x86/mm/tlb.c +3 -3
@@ -667,9 +667,9 @@ static void cond_mitigation(struct task_struct *next) prev_mm =this_cpu_read (cpu_tlbstate.last_user_mm_spec);/* -* Avoid user/user BTB poisoning by flushing the branch predictor -* when switching between processes. This stops one process from -* doing Spectre-v2 attacks on another. +* Avoid user->user BTB/RSB poisoning by flushing them when switching +* between processes. This stops one process from doing Spectre-v2 +* attacks on another. * * Both, the conditional and the always IBPB mode use the mm * pointer to avoid the IBPB when switching between tasks of the
Josh Poimboeuf
maintainerPATCH v4 6/6 x86/bugs: Add RSB mitigation document
In reply to Josh PoimboeufCreate a document to summarize hard-earned knowledge about RSB-related mitigations, with references, and replace the overly verbose yet incomplete comments with a reference to the document.
--- Documentation/admin-guide/hw-vuln/index.rst | 1 + Documentation/admin-guide/hw-vuln/rsb.rst | 268 ++++++++++++++++++++ arch/x86/kernel/cpu/bugs.c | 64 +---- 3 files changed, 282 insertions(+), 51 deletions(-) create mode 100644 Documentation/admin-guide/hw-vuln/rsb.rst
Documentation/admin-guide/hw-vuln/index.rst +1 -0
@@ -22,3 +22,4 @@ are configurable at compile, boot or run time. srso gather_data_sampling reg-file-data-sampling + rsb
Documentation/admin-guide/hw-vuln/rsb.rst new file +268 -0
268 lines not on this page · raw message
arch/x86/kernel/cpu/bugs.c +13 -51
82 lines not on this page · raw message
Signature · 1 line
2.49.0
[tip: x86/urgent] x86/bugs: Add RSB mitigation document
The following commit has been merged into the x86/urgent branch of tip:
The following commit has been merged into the x86/urgent branch of tip:
Commit-ID: 83f6665a49c3d44ad0c08f837d352dd290f5d10b Gitweb: https://git.kernel.org/tip/83f6665a49c3d44ad0c08f837d352dd290f5d10b Author: Josh Poimboeuf <[email protected]> AuthorDate: Tue, 08 Apr 2025 14:47:35 -07:00 Committer: Ingo Molnar <[email protected]> CommitterDate: Wed, 09 Apr 2025 12:42:09 +02:00
x86/bugs: Add RSB mitigation document
Create a document to summarize hard-earned knowledge about RSB-related mitigations, with references, and replace the overly verbose yet incomplete comments with a reference to the document.
--- Documentation/admin-guide/hw-vuln/index.rst | 1 +- Documentation/admin-guide/hw-vuln/rsb.rst | 268 +++++++++++++++++++- arch/x86/kernel/cpu/bugs.c | 64 +---- 3 files changed, 282 insertions(+), 51 deletions(-) create mode 100644 Documentation/admin-guide/hw-vuln/rsb.rst
Documentation/admin-guide/hw-vuln/index.rst +1 -0
@@ -22,3 +22,4 @@ are configurable at compile, boot or run time. srso gather_data_sampling reg-file-data-sampling + rsb
Documentation/admin-guide/hw-vuln/rsb.rst new file +268 -0
268 lines not on this page · raw message
arch/x86/kernel/cpu/bugs.c +13 -51
82 lines not on this page · raw message