Skip to content

Commit 72c70f4

Browse files
leitaobp3tk0v
authored andcommitted
x86/bugs: Add a separate config for Spectre V2
Currently, the CONFIG_SPECULATION_MITIGATIONS is halfway populated, where some mitigations have entries in Kconfig, and they could be modified, while others mitigations do not have Kconfig entries, and could not be controlled at build time. Create an entry for the Spectre V2 CPU mitigation under CONFIG_SPECULATION_MITIGATIONS. This allow users to enable or disable it at compilation time. Signed-off-by: Breno Leitao <[email protected]> Signed-off-by: Borislav Petkov (AMD) <[email protected]> Acked-by: Josh Poimboeuf <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent a0b02e3 commit 72c70f4

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

arch/x86/Kconfig

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2716,6 +2716,18 @@ config MITIGATION_SPECTRE_V1
27162716
memory access bounds check.
27172717
See also <file:Documentation/admin-guide/hw-vuln/spectre.rst>
27182718

2719+
config MITIGATION_SPECTRE_V2
2720+
bool "Mitigate SPECTRE V2 hardware bug"
2721+
default y
2722+
help
2723+
Enable mitigation for Spectre V2 (Branch Target Injection). Spectre
2724+
V2 is a class of side channel attacks that takes advantage of
2725+
indirect branch predictors inside the processor. In Spectre variant 2
2726+
attacks, the attacker can steer speculative indirect branches in the
2727+
victim to gadget code by poisoning the branch target buffer of a CPU
2728+
used for predicting indirect branch addresses.
2729+
See also <file:Documentation/admin-guide/hw-vuln/spectre.rst>
2730+
27192731
config MITIGATION_SRBDS
27202732
bool "Mitigate Special Register Buffer Data Sampling (SRBDS) hardware bug"
27212733
depends on CPU_SUP_INTEL

arch/x86/kernel/cpu/bugs.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1452,17 +1452,18 @@ static void __init spec_v2_print_cond(const char *reason, bool secure)
14521452

14531453
static enum spectre_v2_mitigation_cmd __init spectre_v2_parse_cmdline(void)
14541454
{
1455-
enum spectre_v2_mitigation_cmd cmd = SPECTRE_V2_CMD_AUTO;
1455+
enum spectre_v2_mitigation_cmd cmd;
14561456
char arg[20];
14571457
int ret, i;
14581458

1459+
cmd = IS_ENABLED(CONFIG_MITIGATION_SPECTRE_V2) ? SPECTRE_V2_CMD_AUTO : SPECTRE_V2_CMD_NONE;
14591460
if (cmdline_find_option_bool(boot_command_line, "nospectre_v2") ||
14601461
cpu_mitigations_off())
14611462
return SPECTRE_V2_CMD_NONE;
14621463

14631464
ret = cmdline_find_option(boot_command_line, "spectre_v2", arg, sizeof(arg));
14641465
if (ret < 0)
1465-
return SPECTRE_V2_CMD_AUTO;
1466+
return cmd;
14661467

14671468
for (i = 0; i < ARRAY_SIZE(mitigation_options); i++) {
14681469
if (!match_option(arg, ret, mitigation_options[i].option))
@@ -1472,8 +1473,8 @@ static enum spectre_v2_mitigation_cmd __init spectre_v2_parse_cmdline(void)
14721473
}
14731474

14741475
if (i >= ARRAY_SIZE(mitigation_options)) {
1475-
pr_err("unknown option (%s). Switching to AUTO select\n", arg);
1476-
return SPECTRE_V2_CMD_AUTO;
1476+
pr_err("unknown option (%s). Switching to default mode\n", arg);
1477+
return cmd;
14771478
}
14781479

14791480
if ((cmd == SPECTRE_V2_CMD_RETPOLINE ||

0 commit comments

Comments
 (0)