Skip to content

Commit 27ce829

Browse files
jpoimboeIngo Molnar
authored andcommitted
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. Suggested-by: Pawan Gupta <pawan.kumar.gupta@linux.intel.com> Signed-off-by: Josh Poimboeuf <jpoimboe@kernel.org> Signed-off-by: Ingo Molnar <mingo@kernel.org> Reviewed-by: Pawan Gupta <pawan.kumar.gupta@linux.intel.com> Reviewed-by: Amit Shah <amit.shah@amd.com> Reviewed-by: Nikolay Borisov <nik.borisov@suse.com> Link: https://lore.kernel.org/r/98cdefe42180358efebf78e3b80752850c7a3e1b.1744148254.git.jpoimboe@kernel.org
1 parent 18bae0d commit 27ce829

File tree

2 files changed

+15
-15
lines changed

2 files changed

+15
-15
lines changed

arch/x86/kernel/cpu/bugs.c

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1591,7 +1591,7 @@ static void __init spec_ctrl_disable_kernel_rrsba(void)
15911591
rrsba_disabled = true;
15921592
}
15931593

1594-
static void __init spectre_v2_determine_rsb_fill_type_at_vmexit(enum spectre_v2_mitigation mode)
1594+
static void __init spectre_v2_select_rsb_mitigation(enum spectre_v2_mitigation mode)
15951595
{
15961596
/*
15971597
* 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_
16151615
*/
16161616
switch (mode) {
16171617
case SPECTRE_V2_NONE:
1618-
return;
1618+
break;
16191619

16201620
case SPECTRE_V2_EIBRS:
16211621
case SPECTRE_V2_EIBRS_LFENCE:
@@ -1624,18 +1624,21 @@ static void __init spectre_v2_determine_rsb_fill_type_at_vmexit(enum spectre_v2_
16241624
pr_info("Spectre v2 / PBRSB-eIBRS: Retire a single CALL on VMEXIT\n");
16251625
setup_force_cpu_cap(X86_FEATURE_RSB_VMEXIT_LITE);
16261626
}
1627-
return;
1627+
break;
16281628

16291629
case SPECTRE_V2_RETPOLINE:
16301630
case SPECTRE_V2_LFENCE:
16311631
case SPECTRE_V2_IBRS:
1632-
pr_info("Spectre v2 / SpectreRSB : Filling RSB on VMEXIT\n");
1632+
pr_info("Spectre v2 / SpectreRSB: Filling RSB on context switch and VMEXIT\n");
1633+
setup_force_cpu_cap(X86_FEATURE_RSB_CTXSW);
16331634
setup_force_cpu_cap(X86_FEATURE_RSB_VMEXIT);
1634-
return;
1635-
}
1635+
break;
16361636

1637-
pr_warn_once("Unknown Spectre v2 mode, disabling RSB mitigation at VM exit");
1638-
dump_stack();
1637+
default:
1638+
pr_warn_once("Unknown Spectre v2 mode, disabling RSB mitigation\n");
1639+
dump_stack();
1640+
break;
1641+
}
16391642
}
16401643

16411644
/*
@@ -1867,10 +1870,7 @@ static void __init spectre_v2_select_mitigation(void)
18671870
*
18681871
* FIXME: Is this pointless for retbleed-affected AMD?
18691872
*/
1870-
setup_force_cpu_cap(X86_FEATURE_RSB_CTXSW);
1871-
pr_info("Spectre v2 / SpectreRSB mitigation: Filling RSB on context switch\n");
1872-
1873-
spectre_v2_determine_rsb_fill_type_at_vmexit(mode);
1873+
spectre_v2_select_rsb_mitigation(mode);
18741874

18751875
/*
18761876
* Retpoline protects the kernel, but doesn't protect firmware. IBRS

arch/x86/mm/tlb.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -667,9 +667,9 @@ static void cond_mitigation(struct task_struct *next)
667667
prev_mm = this_cpu_read(cpu_tlbstate.last_user_mm_spec);
668668

669669
/*
670-
* Avoid user/user BTB poisoning by flushing the branch predictor
671-
* when switching between processes. This stops one process from
672-
* doing Spectre-v2 attacks on another.
670+
* Avoid user->user BTB/RSB poisoning by flushing them when switching
671+
* between processes. This stops one process from doing Spectre-v2
672+
* attacks on another.
673673
*
674674
* Both, the conditional and the always IBPB mode use the mm
675675
* pointer to avoid the IBPB when switching between tasks of the

0 commit comments

Comments
 (0)