This is a note to let you know that I've just added the patch titled x86/bugs: Fix the SRSO mitigation on Zen3/4 to the 5.15-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-fix-the-srso-mitigation-on-zen3-4.patch and it can be found in the queue-5.15 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+bounces-36110-greg=kroah.com@xxxxxxxxxxxxxxx Fri Apr 5 16:05:43 2024 From: Borislav Petkov <bp@xxxxxxxxx> Date: Fri, 5 Apr 2024 16:04:32 +0200 Subject: x86/bugs: Fix the SRSO mitigation on Zen3/4 To: gregkh@xxxxxxxxxxxxxxxxxxx Cc: mingo@xxxxxxxxxx, torvalds@xxxxxxxxxxxxxxxxxxxx, stable@xxxxxxxxxxxxxxx Message-ID: <20240405140432.GAZhAE8CuUO6vwOyKK@fat_crate.local> Content-Disposition: inline From: "Borislav Petkov (AMD)" <bp@xxxxxxxxx> Commit 4535e1a4174c4111d92c5a9a21e542d232e0fcaa upstream. The original version of the mitigation would patch in the calls to the untraining routines directly. That is, the alternative() in UNTRAIN_RET will patch in the CALL to srso_alias_untrain_ret() directly. However, even if commit e7c25c441e9e ("x86/cpu: Cleanup the untrain mess") meant well in trying to clean up the situation, due to micro- architectural reasons, the untraining routine srso_alias_untrain_ret() must be the target of a CALL instruction and not of a JMP instruction as it is done now. Reshuffle the alternative macros to accomplish that. Fixes: e7c25c441e9e ("x86/cpu: Cleanup the untrain mess") Signed-off-by: Borislav Petkov (AMD) <bp@xxxxxxxxx> Reviewed-by: Ingo Molnar <mingo@xxxxxxxxxx> Cc: stable@xxxxxxxxxx Signed-off-by: Linus Torvalds <torvalds@xxxxxxxxxxxxxxxxxxxx> Signed-off-by: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx> --- arch/x86/include/asm/asm-prototypes.h | 1 + arch/x86/include/asm/nospec-branch.h | 20 ++++++++++++++------ arch/x86/lib/retpoline.S | 4 +--- 3 files changed, 16 insertions(+), 9 deletions(-) --- a/arch/x86/include/asm/asm-prototypes.h +++ b/arch/x86/include/asm/asm-prototypes.h @@ -12,6 +12,7 @@ #include <asm/special_insns.h> #include <asm/preempt.h> #include <asm/asm.h> +#include <asm/nospec-branch.h> #ifndef CONFIG_X86_CMPXCHG64 extern void cmpxchg8b_emu(void); --- a/arch/x86/include/asm/nospec-branch.h +++ b/arch/x86/include/asm/nospec-branch.h @@ -155,11 +155,20 @@ .Lskip_rsb_\@: .endm +/* + * The CALL to srso_alias_untrain_ret() must be patched in directly at + * the spot where untraining must be done, ie., srso_alias_untrain_ret() + * must be the target of a CALL instruction instead of indirectly + * jumping to a wrapper which then calls it. Therefore, this macro is + * called outside of __UNTRAIN_RET below, for the time being, before the + * kernel can support nested alternatives with arbitrary nesting. + */ +.macro CALL_UNTRAIN_RET #ifdef CONFIG_CPU_UNRET_ENTRY -#define CALL_UNTRAIN_RET "call entry_untrain_ret" -#else -#define CALL_UNTRAIN_RET "" + ALTERNATIVE_2 "", "call entry_untrain_ret", X86_FEATURE_UNRET, \ + "call srso_alias_untrain_ret", X86_FEATURE_SRSO_ALIAS #endif +.endm /* * Mitigate RETBleed for AMD/Hygon Zen uarch. Requires KERNEL CR3 because the @@ -176,9 +185,8 @@ #if defined(CONFIG_CPU_UNRET_ENTRY) || defined(CONFIG_CPU_IBPB_ENTRY) || \ defined(CONFIG_CPU_SRSO) ANNOTATE_UNRET_END - ALTERNATIVE_2 "", \ - CALL_UNTRAIN_RET, X86_FEATURE_UNRET, \ - "call entry_ibpb", X86_FEATURE_ENTRY_IBPB + CALL_UNTRAIN_RET + ALTERNATIVE "", "call entry_ibpb", X86_FEATURE_ENTRY_IBPB #endif .endm --- a/arch/x86/lib/retpoline.S +++ b/arch/x86/lib/retpoline.S @@ -249,9 +249,7 @@ SYM_CODE_START(srso_return_thunk) SYM_CODE_END(srso_return_thunk) SYM_FUNC_START(entry_untrain_ret) - ALTERNATIVE_2 "jmp retbleed_untrain_ret", \ - "jmp srso_untrain_ret", X86_FEATURE_SRSO, \ - "jmp srso_alias_untrain_ret", X86_FEATURE_SRSO_ALIAS + ALTERNATIVE "jmp retbleed_untrain_ret", "jmp srso_untrain_ret", X86_FEATURE_SRSO SYM_FUNC_END(entry_untrain_ret) __EXPORT_THUNK(entry_untrain_ret) Patches currently in stable-queue which might be from kroah.com@xxxxxxxxxxxxxxx are queue-5.15/x86-rfds-mitigate-register-file-data-sampling-rfds.patch queue-5.15/vfio-pci-create-persistent-intx-handler.patch queue-5.15/x86-entry_32-add-verw-just-before-userspace-transition.patch queue-5.15/vfio-fsl-mc-block-calling-interrupt-handler-without-trigger.patch queue-5.15/x86-bugs-add-asm-helpers-for-executing-verw.patch queue-5.15/x86-asm-differentiate-between-code-and-function-alignment.patch queue-5.15/vfio-pci-disable-auto-enable-of-exclusive-intx-irq.patch queue-5.15/x86-bugs-fix-the-srso-mitigation-on-zen3-4.patch queue-5.15/x86-retpoline-do-the-necessary-fixup-to-the-zen3-4-srso-return-thunk-for-srso.patch queue-5.15/vfio-pci-lock-external-intx-masking-ops.patch queue-5.15/x86-alternatives-teach-text_poke_bp-to-patch-jcc.d32-instructions.patch queue-5.15/vfio-introduce-interface-to-flush-virqfd-inject-workqueue.patch queue-5.15/kvm-x86-export-rfds_no-and-rfds_clear-to-guests.patch queue-5.15/x86-asm-add-_asm_rip-macro-for-x86-64-rip-suffix.patch queue-5.15/x86-entry_64-add-verw-just-before-userspace-transition.patch queue-5.15/x86-alternatives-introduce-int3_emulate_jcc.patch queue-5.15/x86-mmio-disable-kvm-mitigation-when-x86_feature_clear_cpu_buf-is-set.patch queue-5.15/x86-bugs-use-alternative-instead-of-mds_user_clear-static-key.patch queue-5.15/documentation-hw-vuln-add-documentation-for-rfds.patch queue-5.15/kvm-vmx-use-bt-jnc-i.e.-eflags.cf-to-select-vmresume-vs.-vmlaunch.patch queue-5.15/mm-migrate-set-swap-entry-values-of-thp-tail-pages-properly.patch queue-5.15/kvm-vmx-move-verw-closer-to-vmentry-for-mds-mitigation.patch queue-5.15/arch-introduce-config_function_alignment.patch queue-5.15/x86-static_call-add-support-for-jcc-tail-calls.patch queue-5.15/vfio-platform-create-persistent-irq-handlers.patch