@@ -1335,6 +1335,53 @@ static void __init spec_ctrl_disable_kernel_rrsba(void)
13351335 }
13361336}
13371337
1338+ static void __init spectre_v2_determine_rsb_fill_type_at_vmexit (enum spectre_v2_mitigation mode )
1339+ {
1340+ /*
1341+ * Similar to context switches, there are two types of RSB attacks
1342+ * after VM exit:
1343+ *
1344+ * 1) RSB underflow
1345+ *
1346+ * 2) Poisoned RSB entry
1347+ *
1348+ * When retpoline is enabled, both are mitigated by filling/clearing
1349+ * the RSB.
1350+ *
1351+ * When IBRS is enabled, while #1 would be mitigated by the IBRS branch
1352+ * prediction isolation protections, RSB still needs to be cleared
1353+ * because of #2. Note that SMEP provides no protection here, unlike
1354+ * user-space-poisoned RSB entries.
1355+ *
1356+ * eIBRS should protect against RSB poisoning, but if the EIBRS_PBRSB
1357+ * bug is present then a LITE version of RSB protection is required,
1358+ * just a single call needs to retire before a RET is executed.
1359+ */
1360+ switch (mode ) {
1361+ case SPECTRE_V2_NONE :
1362+ return ;
1363+
1364+ case SPECTRE_V2_EIBRS_LFENCE :
1365+ case SPECTRE_V2_EIBRS :
1366+ if (boot_cpu_has_bug (X86_BUG_EIBRS_PBRSB )) {
1367+ setup_force_cpu_cap (X86_FEATURE_RSB_VMEXIT_LITE );
1368+ pr_info ("Spectre v2 / PBRSB-eIBRS: Retire a single CALL on VMEXIT\n" );
1369+ }
1370+ return ;
1371+
1372+ case SPECTRE_V2_EIBRS_RETPOLINE :
1373+ case SPECTRE_V2_RETPOLINE :
1374+ case SPECTRE_V2_LFENCE :
1375+ case SPECTRE_V2_IBRS :
1376+ setup_force_cpu_cap (X86_FEATURE_RSB_VMEXIT );
1377+ pr_info ("Spectre v2 / SpectreRSB : Filling RSB on VMEXIT\n" );
1378+ return ;
1379+ }
1380+
1381+ pr_warn_once ("Unknown Spectre v2 mode, disabling RSB mitigation at VM exit" );
1382+ dump_stack ();
1383+ }
1384+
13381385static void __init spectre_v2_select_mitigation (void )
13391386{
13401387 enum spectre_v2_mitigation_cmd cmd = spectre_v2_parse_cmdline ();
@@ -1485,28 +1532,7 @@ static void __init spectre_v2_select_mitigation(void)
14851532 setup_force_cpu_cap (X86_FEATURE_RSB_CTXSW );
14861533 pr_info ("Spectre v2 / SpectreRSB mitigation: Filling RSB on context switch\n" );
14871534
1488- /*
1489- * Similar to context switches, there are two types of RSB attacks
1490- * after vmexit:
1491- *
1492- * 1) RSB underflow
1493- *
1494- * 2) Poisoned RSB entry
1495- *
1496- * When retpoline is enabled, both are mitigated by filling/clearing
1497- * the RSB.
1498- *
1499- * When IBRS is enabled, while #1 would be mitigated by the IBRS branch
1500- * prediction isolation protections, RSB still needs to be cleared
1501- * because of #2. Note that SMEP provides no protection here, unlike
1502- * user-space-poisoned RSB entries.
1503- *
1504- * eIBRS, on the other hand, has RSB-poisoning protections, so it
1505- * doesn't need RSB clearing after vmexit.
1506- */
1507- if (boot_cpu_has (X86_FEATURE_RETPOLINE ) ||
1508- boot_cpu_has (X86_FEATURE_KERNEL_IBRS ))
1509- setup_force_cpu_cap (X86_FEATURE_RSB_VMEXIT );
1535+ spectre_v2_determine_rsb_fill_type_at_vmexit (mode );
15101536
15111537 /*
15121538 * Retpoline protects the kernel, but doesn't protect firmware. IBRS
@@ -2292,6 +2318,19 @@ static char *ibpb_state(void)
22922318 return "" ;
22932319}
22942320
2321+ static char * pbrsb_eibrs_state (void )
2322+ {
2323+ if (boot_cpu_has_bug (X86_BUG_EIBRS_PBRSB )) {
2324+ if (boot_cpu_has (X86_FEATURE_RSB_VMEXIT_LITE ) ||
2325+ boot_cpu_has (X86_FEATURE_RSB_VMEXIT ))
2326+ return ", PBRSB-eIBRS: SW sequence" ;
2327+ else
2328+ return ", PBRSB-eIBRS: Vulnerable" ;
2329+ } else {
2330+ return ", PBRSB-eIBRS: Not affected" ;
2331+ }
2332+ }
2333+
22952334static ssize_t spectre_v2_show_state (char * buf )
22962335{
22972336 if (spectre_v2_enabled == SPECTRE_V2_LFENCE )
@@ -2304,12 +2343,13 @@ static ssize_t spectre_v2_show_state(char *buf)
23042343 spectre_v2_enabled == SPECTRE_V2_EIBRS_LFENCE )
23052344 return sprintf (buf , "Vulnerable: eIBRS+LFENCE with unprivileged eBPF and SMT\n" );
23062345
2307- return sprintf (buf , "%s%s%s%s%s%s\n" ,
2346+ return sprintf (buf , "%s%s%s%s%s%s%s \n" ,
23082347 spectre_v2_strings [spectre_v2_enabled ],
23092348 ibpb_state (),
23102349 boot_cpu_has (X86_FEATURE_USE_IBRS_FW ) ? ", IBRS_FW" : "" ,
23112350 stibp_state (),
23122351 boot_cpu_has (X86_FEATURE_RSB_CTXSW ) ? ", RSB filling" : "" ,
2352+ pbrsb_eibrs_state (),
23132353 spectre_v2_module_string ());
23142354}
23152355
0 commit comments