This is a note to let you know that I've just added the patch titled x86/bugs: Add AMD retbleed= boot parameter to the 4.19-stable tree which can be found at: http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary The filename of the patch is: x86-bugs-add-amd-retbleed-boot-parameter.patch and it can be found in the queue-4.19 subdirectory. If you, or anyone else, feels it should not be added to the stable tree, please let <stable@xxxxxxxxxxxxxxx> know about it. >From stable-owner@xxxxxxxxxxxxxxx Thu Nov 17 10:21:03 2022 From: Suleiman Souhlal <suleiman@xxxxxxxxxx> Date: Thu, 17 Nov 2022 18:19:28 +0900 Subject: x86/bugs: Add AMD retbleed= boot parameter To: stable@xxxxxxxxxxxxxxx Cc: x86@xxxxxxxxxx, kvm@xxxxxxxxxxxxxxx, bp@xxxxxxxxx, pbonzini@xxxxxxxxxx, peterz@xxxxxxxxxxxxx, jpoimboe@xxxxxxxxxx, cascardo@xxxxxxxxxxxxx, surajjs@xxxxxxxxxx, ssouhlal@xxxxxxxxxxx, suleiman@xxxxxxxxxx Message-ID: <20221117091952.1940850-11-suleiman@xxxxxxxxxx> From: Alexandre Chartre <alexandre.chartre@xxxxxxxxxx> commit 7fbf47c7ce50b38a64576b150e7011ae73d54669 upstream. Add the "retbleed=<value>" boot parameter to select a mitigation for RETBleed. Possible values are "off", "auto" and "unret" (JMP2RET mitigation). The default value is "auto". Currently, "retbleed=auto" will select the unret mitigation on AMD and Hygon and no mitigation on Intel (JMP2RET is not effective on Intel). [peterz: rebase; add hygon] [jpoimboe: cleanups] Signed-off-by: Alexandre Chartre <alexandre.chartre@xxxxxxxxxx> Signed-off-by: Peter Zijlstra (Intel) <peterz@xxxxxxxxxxxxx> Signed-off-by: Borislav Petkov <bp@xxxxxxx> Reviewed-by: Josh Poimboeuf <jpoimboe@xxxxxxxxxx> Signed-off-by: Borislav Petkov <bp@xxxxxxx> [cascardo: this effectively remove the UNRET mitigation as an option, so it has to be complemented by a later pick of the same commit later. This is done in order to pick retbleed_select_mitigation] Signed-off-by: Thadeu Lima de Souza Cascardo <cascardo@xxxxxxxxxxxxx> Signed-off-by: Suleiman Souhlal <suleiman@xxxxxxxxxx> Signed-off-by: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx> --- Documentation/admin-guide/kernel-parameters.txt | 12 +++ arch/x86/kernel/cpu/bugs.c | 74 +++++++++++++++++++++++- 2 files changed, 85 insertions(+), 1 deletion(-) --- a/Documentation/admin-guide/kernel-parameters.txt +++ b/Documentation/admin-guide/kernel-parameters.txt @@ -4132,6 +4132,18 @@ retain_initrd [RAM] Keep initrd memory after extraction + retbleed= [X86] Control mitigation of RETBleed (Arbitrary + Speculative Code Execution with Return Instructions) + vulnerability. + + off - unconditionally disable + auto - automatically select a migitation + + Selecting 'auto' will choose a mitigation method at run + time according to the CPU. + + Not specifying this option is equivalent to retbleed=auto. + rfkill.default_state= 0 "airplane mode". All wifi, bluetooth, wimax, gps, fm, etc. communication is blocked by default. --- a/arch/x86/kernel/cpu/bugs.c +++ b/arch/x86/kernel/cpu/bugs.c @@ -36,6 +36,7 @@ #include "cpu.h" static void __init spectre_v1_select_mitigation(void); +static void __init retbleed_select_mitigation(void); static void __init spectre_v2_select_mitigation(void); static void __init ssb_select_mitigation(void); static void __init l1tf_select_mitigation(void); @@ -111,6 +112,12 @@ void __init check_bugs(void) /* Select the proper CPU mitigations before patching alternatives: */ spectre_v1_select_mitigation(); + retbleed_select_mitigation(); + /* + * spectre_v2_select_mitigation() relies on the state set by + * retbleed_select_mitigation(); specifically the STIBP selection is + * forced for UNRET. + */ spectre_v2_select_mitigation(); ssb_select_mitigation(); l1tf_select_mitigation(); @@ -706,6 +713,71 @@ static int __init nospectre_v1_cmdline(c early_param("nospectre_v1", nospectre_v1_cmdline); #undef pr_fmt +#define pr_fmt(fmt) "RETBleed: " fmt + +enum retbleed_mitigation { + RETBLEED_MITIGATION_NONE, +}; + +enum retbleed_mitigation_cmd { + RETBLEED_CMD_OFF, + RETBLEED_CMD_AUTO, +}; + +const char * const retbleed_strings[] = { + [RETBLEED_MITIGATION_NONE] = "Vulnerable", +}; + +static enum retbleed_mitigation retbleed_mitigation __ro_after_init = + RETBLEED_MITIGATION_NONE; +static enum retbleed_mitigation_cmd retbleed_cmd __ro_after_init = + RETBLEED_CMD_AUTO; + +static int __init retbleed_parse_cmdline(char *str) +{ + if (!str) + return -EINVAL; + + if (!strcmp(str, "off")) + retbleed_cmd = RETBLEED_CMD_OFF; + else if (!strcmp(str, "auto")) + retbleed_cmd = RETBLEED_CMD_AUTO; + else + pr_err("Unknown retbleed option (%s). Defaulting to 'auto'\n", str); + + return 0; +} +early_param("retbleed", retbleed_parse_cmdline); + +#define RETBLEED_UNTRAIN_MSG "WARNING: BTB untrained return thunk mitigation is only effective on AMD/Hygon!\n" +#define RETBLEED_COMPILER_MSG "WARNING: kernel not compiled with RETPOLINE or -mfunction-return capable compiler!\n" + +static void __init retbleed_select_mitigation(void) +{ + if (!boot_cpu_has_bug(X86_BUG_RETBLEED) || cpu_mitigations_off()) + return; + + switch (retbleed_cmd) { + case RETBLEED_CMD_OFF: + return; + + case RETBLEED_CMD_AUTO: + default: + if (!boot_cpu_has_bug(X86_BUG_RETBLEED)) + break; + + break; + } + + switch (retbleed_mitigation) { + default: + break; + } + + pr_info("%s\n", retbleed_strings[retbleed_mitigation]); +} + +#undef pr_fmt #define pr_fmt(fmt) "Spectre V2 : " fmt static enum spectre_v2_mitigation spectre_v2_enabled __ro_after_init = @@ -1901,7 +1973,7 @@ static ssize_t srbds_show_state(char *bu static ssize_t retbleed_show_state(char *buf) { - return sprintf(buf, "Vulnerable\n"); + return sprintf(buf, "%s\n", retbleed_strings[retbleed_mitigation]); } static ssize_t cpu_show_common(struct device *dev, struct device_attribute *attr, Patches currently in stable-queue which might be from stable-owner@xxxxxxxxxxxxxxx are queue-4.19/x86-speculation-disable-rrsba-behavior.patch queue-4.19/revert-x86-speculation-add-rsb-vm-exit-protections.patch queue-4.19/kvm-vmx-fix-ibrs-handling-after-vmexit.patch queue-4.19/kvm-vmx-prevent-guest-rsb-poisoning-attacks-with-eibrs.patch queue-4.19/x86-cpufeature-add-facility-to-check-for-min-microcode-revisions.patch queue-4.19/x86-bugs-keep-a-per-cpu-ia32_spec_ctrl-value.patch queue-4.19/x86-cpu-amd-enumerate-btc_no.patch queue-4.19/x86-speculation-fix-firmware-entry-spec_ctrl-handling.patch queue-4.19/x86-speculation-add-spectre_v2-ibrs-option-to-support-kernel-ibrs.patch queue-4.19/x86-cpu-add-consistent-cpu-match-macros.patch queue-4.19/x86-speculation-remove-x86_spec_ctrl_mask.patch queue-4.19/x86-bugs-add-cannon-lake-to-retbleed-affected-cpu-list.patch queue-4.19/x86-bugs-warn-when-ibrs-mitigation-is-selected-on-enhanced-ibrs-parts.patch queue-4.19/x86-speculation-fill-rsb-on-vmexit-for-ibrs.patch queue-4.19/x86-cpu-add-a-steppings-field-to-struct-x86_cpu_id.patch queue-4.19/x86-common-stamp-out-the-stepping-madness.patch queue-4.19/x86-bugs-split-spectre_v2_select_mitigation-and-spectre_v2_user_select_mitigation.patch queue-4.19/x86-bugs-report-intel-retbleed-vulnerability.patch queue-4.19/x86-speculation-change-fill_return_buffer-to-work-with-objtool.patch queue-4.19/x86-cpufeatures-move-retpoline-flags-to-word-11.patch queue-4.19/x86-speculation-fix-spec_ctrl-write-on-smt-state-change.patch queue-4.19/x86-bugs-optimize-spec_ctrl-msr-writes.patch queue-4.19/x86-bugs-report-amd-retbleed-vulnerability.patch queue-4.19/x86-speculation-fix-rsb-filling-with-config_retpoline-n.patch queue-4.19/x86-cpufeature-fix-various-quality-problems-in-the-asm-cpu_device_hd.h-header.patch queue-4.19/intel_idle-disable-ibrs-during-long-idle.patch queue-4.19/x86-speculation-use-declare_per_cpu-for-x86_spec_ctrl_current.patch queue-4.19/x86-entry-remove-skip_r11rcx.patch queue-4.19/x86-speculation-use-cached-host-spec_ctrl-value-for-guest-entry-exit.patch queue-4.19/x86-devicetable-move-x86-specific-macro-out-of-generic-code.patch queue-4.19/x86-bugs-add-amd-retbleed-boot-parameter.patch queue-4.19/x86-entry-add-kernel-ibrs-implementation.patch queue-4.19/revert-x86-cpu-add-a-steppings-field-to-struct-x86_cpu_id.patch queue-4.19/x86-speculation-add-rsb-vm-exit-protections.patch