Skip to content

Commit 1af036e

Browse files
committed
x86/cpu/kvm: SRSO: Fix possible missing IBPB on VM-Exit
JIRA: https://issues.redhat.com/browse/RHEL-88224 commit 318e8c3 Author: Patrick Bellasi <derkling@google.com> Date: Wed, 5 Feb 2025 14:04:41 +0000 x86/cpu/kvm: SRSO: Fix possible missing IBPB on VM-Exit In [1] the meaning of the synthetic IBPB flags has been redefined for a better separation of concerns: - ENTRY_IBPB -- issue IBPB on entry only - IBPB_ON_VMEXIT -- issue IBPB on VM-Exit only and the Retbleed mitigations have been updated to match this new semantics. Commit [2] was merged shortly before [1], and their interaction was not handled properly. This resulted in IBPB not being triggered on VM-Exit in all SRSO mitigation configs requesting an IBPB there. Specifically, an IBPB on VM-Exit is triggered only when X86_FEATURE_IBPB_ON_VMEXIT is set. However: - X86_FEATURE_IBPB_ON_VMEXIT is not set for "spec_rstack_overflow=ibpb", because before [1] having X86_FEATURE_ENTRY_IBPB was enough. Hence, an IBPB is triggered on entry but the expected IBPB on VM-exit is not. - X86_FEATURE_IBPB_ON_VMEXIT is not set also when "spec_rstack_overflow=ibpb-vmexit" if X86_FEATURE_ENTRY_IBPB is already set. That's because before [1] this was effectively redundant. Hence, e.g. a "retbleed=ibpb spec_rstack_overflow=bpb-vmexit" config mistakenly reports the machine still vulnerable to SRSO, despite an IBPB being triggered both on entry and VM-Exit, because of the Retbleed selected mitigation config. - UNTRAIN_RET_VM won't still actually do anything unless CONFIG_MITIGATION_IBPB_ENTRY is set. For "spec_rstack_overflow=ibpb", enable IBPB on both entry and VM-Exit and clear X86_FEATURE_RSB_VMEXIT which is made superfluous by X86_FEATURE_IBPB_ON_VMEXIT. This effectively makes this mitigation option similar to the one for 'retbleed=ibpb', thus re-order the code for the RETBLEED_MITIGATION_IBPB option to be less confusing by having all features enabling before the disabling of the not needed ones. For "spec_rstack_overflow=ibpb-vmexit", guard this mitigation setting with CONFIG_MITIGATION_IBPB_ENTRY to ensure UNTRAIN_RET_VM sequence is effectively compiled in. Drop instead the CONFIG_MITIGATION_SRSO guard, since none of the SRSO compile cruft is required in this configuration. Also, check only that the required microcode is present to effectively enabled the IBPB on VM-Exit. Finally, update the KConfig description for CONFIG_MITIGATION_IBPB_ENTRY to list also all SRSO config settings enabled by this guard. Fixes: 864bcaa ("x86/cpu/kvm: Provide UNTRAIN_RET_VM") [1] Fixes: d893832 ("x86/srso: Add IBPB on VMEXIT") [2] Reported-by: Yosry Ahmed <yosryahmed@google.com> Signed-off-by: Patrick Bellasi <derkling@google.com> Reviewed-by: Borislav Petkov (AMD) <bp@alien8.de> Cc: stable@kernel.org Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Waiman Long <longman@redhat.com>
1 parent 91103d0 commit 1af036e

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

arch/x86/Kconfig

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2560,7 +2560,8 @@ config MITIGATION_IBPB_ENTRY
25602560
depends on CPU_SUP_AMD && X86_64
25612561
default y
25622562
help
2563-
Compile the kernel with support for the retbleed=ibpb mitigation.
2563+
Compile the kernel with support for the retbleed=ibpb and
2564+
spec_rstack_overflow={ibpb,ibpb-vmexit} mitigations.
25642565

25652566
config MITIGATION_IBRS_ENTRY
25662567
bool "Enable IBRS on kernel entry"

arch/x86/kernel/cpu/bugs.c

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1122,6 +1122,8 @@ static void __init retbleed_select_mitigation(void)
11221122

11231123
case RETBLEED_MITIGATION_IBPB:
11241124
setup_force_cpu_cap(X86_FEATURE_ENTRY_IBPB);
1125+
setup_force_cpu_cap(X86_FEATURE_IBPB_ON_VMEXIT);
1126+
mitigate_smt = true;
11251127

11261128
/*
11271129
* IBPB on entry already obviates the need for
@@ -1131,9 +1133,6 @@ static void __init retbleed_select_mitigation(void)
11311133
setup_clear_cpu_cap(X86_FEATURE_UNRET);
11321134
setup_clear_cpu_cap(X86_FEATURE_RETHUNK);
11331135

1134-
setup_force_cpu_cap(X86_FEATURE_IBPB_ON_VMEXIT);
1135-
mitigate_smt = true;
1136-
11371136
/*
11381137
* There is no need for RSB filling: entry_ibpb() ensures
11391138
* all predictions, including the RSB, are invalidated,
@@ -2731,6 +2730,7 @@ static void __init srso_select_mitigation(void)
27312730
if (IS_ENABLED(CONFIG_MITIGATION_IBPB_ENTRY)) {
27322731
if (has_microcode) {
27332732
setup_force_cpu_cap(X86_FEATURE_ENTRY_IBPB);
2733+
setup_force_cpu_cap(X86_FEATURE_IBPB_ON_VMEXIT);
27342734
srso_mitigation = SRSO_MITIGATION_IBPB;
27352735

27362736
/*
@@ -2740,6 +2740,13 @@ static void __init srso_select_mitigation(void)
27402740
*/
27412741
setup_clear_cpu_cap(X86_FEATURE_UNRET);
27422742
setup_clear_cpu_cap(X86_FEATURE_RETHUNK);
2743+
2744+
/*
2745+
* There is no need for RSB filling: entry_ibpb() ensures
2746+
* all predictions, including the RSB, are invalidated,
2747+
* regardless of IBPB implementation.
2748+
*/
2749+
setup_clear_cpu_cap(X86_FEATURE_RSB_VMEXIT);
27432750
}
27442751
} else {
27452752
pr_err("WARNING: kernel not compiled with MITIGATION_IBPB_ENTRY.\n");
@@ -2748,8 +2755,8 @@ static void __init srso_select_mitigation(void)
27482755

27492756
ibpb_on_vmexit:
27502757
case SRSO_CMD_IBPB_ON_VMEXIT:
2751-
if (IS_ENABLED(CONFIG_MITIGATION_SRSO)) {
2752-
if (!boot_cpu_has(X86_FEATURE_ENTRY_IBPB) && has_microcode) {
2758+
if (IS_ENABLED(CONFIG_MITIGATION_IBPB_ENTRY)) {
2759+
if (has_microcode) {
27532760
setup_force_cpu_cap(X86_FEATURE_IBPB_ON_VMEXIT);
27542761
srso_mitigation = SRSO_MITIGATION_IBPB_ON_VMEXIT;
27552762

@@ -2761,8 +2768,8 @@ static void __init srso_select_mitigation(void)
27612768
setup_clear_cpu_cap(X86_FEATURE_RSB_VMEXIT);
27622769
}
27632770
} else {
2764-
pr_err("WARNING: kernel not compiled with MITIGATION_SRSO.\n");
2765-
}
2771+
pr_err("WARNING: kernel not compiled with MITIGATION_IBPB_ENTRY.\n");
2772+
}
27662773
break;
27672774
default:
27682775
break;

0 commit comments

Comments
 (0)