Skip to content

Commit 79c8091

Browse files
bp3tk0vgregkh
authored andcommitted
x86/srso: Add IBPB
Upstream commit: 233d6f6 Add the option to mitigate using IBPB on a kernel entry. Pull in the Retbleed alternative so that the IBPB call from there can be used. Also, if Retbleed mitigation is done using IBPB, the same mitigation can and must be used here. Signed-off-by: Borislav Petkov (AMD) <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 98f6288 commit 79c8091

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

arch/x86/include/asm/nospec-branch.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,8 @@
185185
* where we have a stack but before any RET instruction.
186186
*/
187187
.macro UNTRAIN_RET
188-
#if defined(CONFIG_CPU_UNRET_ENTRY) || defined(CONFIG_CPU_IBPB_ENTRY)
188+
#if defined(CONFIG_CPU_UNRET_ENTRY) || defined(CONFIG_CPU_IBPB_ENTRY) || \
189+
defined(CONFIG_CPU_SRSO)
189190
ANNOTATE_UNRET_END
190191
ALTERNATIVE_2 "", \
191192
CALL_ZEN_UNTRAIN_RET, X86_FEATURE_UNRET, \

arch/x86/kernel/cpu/bugs.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2315,18 +2315,21 @@ enum srso_mitigation {
23152315
SRSO_MITIGATION_NONE,
23162316
SRSO_MITIGATION_MICROCODE,
23172317
SRSO_MITIGATION_SAFE_RET,
2318+
SRSO_MITIGATION_IBPB,
23182319
};
23192320

23202321
enum srso_mitigation_cmd {
23212322
SRSO_CMD_OFF,
23222323
SRSO_CMD_MICROCODE,
23232324
SRSO_CMD_SAFE_RET,
2325+
SRSO_CMD_IBPB,
23242326
};
23252327

23262328
static const char * const srso_strings[] = {
23272329
[SRSO_MITIGATION_NONE] = "Vulnerable",
23282330
[SRSO_MITIGATION_MICROCODE] = "Mitigation: microcode",
23292331
[SRSO_MITIGATION_SAFE_RET] = "Mitigation: safe RET",
2332+
[SRSO_MITIGATION_IBPB] = "Mitigation: IBPB",
23302333
};
23312334

23322335
static enum srso_mitigation srso_mitigation __ro_after_init = SRSO_MITIGATION_NONE;
@@ -2343,6 +2346,8 @@ static int __init srso_parse_cmdline(char *str)
23432346
srso_cmd = SRSO_CMD_MICROCODE;
23442347
else if (!strcmp(str, "safe-ret"))
23452348
srso_cmd = SRSO_CMD_SAFE_RET;
2349+
else if (!strcmp(str, "ibpb"))
2350+
srso_cmd = SRSO_CMD_IBPB;
23462351
else
23472352
pr_err("Ignoring unknown SRSO option (%s).", str);
23482353

@@ -2384,6 +2389,14 @@ static void __init srso_select_mitigation(void)
23842389
setup_force_cpu_cap(X86_FEATURE_SRSO_NO);
23852390
}
23862391

2392+
if (retbleed_mitigation == RETBLEED_MITIGATION_IBPB) {
2393+
if (has_microcode) {
2394+
pr_err("Retbleed IBPB mitigation enabled, using same for SRSO\n");
2395+
srso_mitigation = SRSO_MITIGATION_IBPB;
2396+
goto pred_cmd;
2397+
}
2398+
}
2399+
23872400
switch (srso_cmd) {
23882401
case SRSO_CMD_OFF:
23892402
return;
@@ -2408,6 +2421,16 @@ static void __init srso_select_mitigation(void)
24082421
}
24092422
break;
24102423

2424+
case SRSO_CMD_IBPB:
2425+
if (IS_ENABLED(CONFIG_CPU_IBPB_ENTRY)) {
2426+
if (has_microcode) {
2427+
setup_force_cpu_cap(X86_FEATURE_ENTRY_IBPB);
2428+
srso_mitigation = SRSO_MITIGATION_IBPB;
2429+
}
2430+
} else {
2431+
pr_err("WARNING: kernel not compiled with CPU_IBPB_ENTRY.\n");
2432+
goto pred_cmd;
2433+
}
24112434
default:
24122435
break;
24132436
}

0 commit comments

Comments
 (0)