Skip to content

Commit eea6d16

Browse files
derklinggregkh
authored andcommitted
x86/cpu/kvm: SRSO: Fix possible missing IBPB on VM-Exit
commit 318e8c3 upstream. 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 <[email protected]> Signed-off-by: Patrick Bellasi <[email protected]> Reviewed-by: Borislav Petkov (AMD) <[email protected]> Cc: [email protected] Signed-off-by: Linus Torvalds <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent a88ca5d commit eea6d16

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
@@ -2582,7 +2582,8 @@ config MITIGATION_IBPB_ENTRY
25822582
depends on CPU_SUP_AMD && X86_64
25832583
default y
25842584
help
2585-
Compile the kernel with support for the retbleed=ibpb mitigation.
2585+
Compile the kernel with support for the retbleed=ibpb and
2586+
spec_rstack_overflow={ibpb,ibpb-vmexit} mitigations.
25862587

25872588
config MITIGATION_IBRS_ENTRY
25882589
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
@@ -1115,6 +1115,8 @@ static void __init retbleed_select_mitigation(void)
11151115

11161116
case RETBLEED_MITIGATION_IBPB:
11171117
setup_force_cpu_cap(X86_FEATURE_ENTRY_IBPB);
1118+
setup_force_cpu_cap(X86_FEATURE_IBPB_ON_VMEXIT);
1119+
mitigate_smt = true;
11181120

11191121
/*
11201122
* IBPB on entry already obviates the need for
@@ -1124,9 +1126,6 @@ static void __init retbleed_select_mitigation(void)
11241126
setup_clear_cpu_cap(X86_FEATURE_UNRET);
11251127
setup_clear_cpu_cap(X86_FEATURE_RETHUNK);
11261128

1127-
setup_force_cpu_cap(X86_FEATURE_IBPB_ON_VMEXIT);
1128-
mitigate_smt = true;
1129-
11301129
/*
11311130
* There is no need for RSB filling: entry_ibpb() ensures
11321131
* all predictions, including the RSB, are invalidated,
@@ -2643,6 +2642,7 @@ static void __init srso_select_mitigation(void)
26432642
if (IS_ENABLED(CONFIG_MITIGATION_IBPB_ENTRY)) {
26442643
if (has_microcode) {
26452644
setup_force_cpu_cap(X86_FEATURE_ENTRY_IBPB);
2645+
setup_force_cpu_cap(X86_FEATURE_IBPB_ON_VMEXIT);
26462646
srso_mitigation = SRSO_MITIGATION_IBPB;
26472647

26482648
/*
@@ -2652,15 +2652,22 @@ static void __init srso_select_mitigation(void)
26522652
*/
26532653
setup_clear_cpu_cap(X86_FEATURE_UNRET);
26542654
setup_clear_cpu_cap(X86_FEATURE_RETHUNK);
2655+
2656+
/*
2657+
* There is no need for RSB filling: entry_ibpb() ensures
2658+
* all predictions, including the RSB, are invalidated,
2659+
* regardless of IBPB implementation.
2660+
*/
2661+
setup_clear_cpu_cap(X86_FEATURE_RSB_VMEXIT);
26552662
}
26562663
} else {
26572664
pr_err("WARNING: kernel not compiled with MITIGATION_IBPB_ENTRY.\n");
26582665
}
26592666
break;
26602667

26612668
case SRSO_CMD_IBPB_ON_VMEXIT:
2662-
if (IS_ENABLED(CONFIG_MITIGATION_SRSO)) {
2663-
if (!boot_cpu_has(X86_FEATURE_ENTRY_IBPB) && has_microcode) {
2669+
if (IS_ENABLED(CONFIG_MITIGATION_IBPB_ENTRY)) {
2670+
if (has_microcode) {
26642671
setup_force_cpu_cap(X86_FEATURE_IBPB_ON_VMEXIT);
26652672
srso_mitigation = SRSO_MITIGATION_IBPB_ON_VMEXIT;
26662673

@@ -2672,8 +2679,8 @@ static void __init srso_select_mitigation(void)
26722679
setup_clear_cpu_cap(X86_FEATURE_RSB_VMEXIT);
26732680
}
26742681
} else {
2675-
pr_err("WARNING: kernel not compiled with MITIGATION_SRSO.\n");
2676-
}
2682+
pr_err("WARNING: kernel not compiled with MITIGATION_IBPB_ENTRY.\n");
2683+
}
26772684
break;
26782685
default:
26792686
break;

0 commit comments

Comments
 (0)