Re: [PATCH] efi/x86: use naked RET on mixed mode call wrapper

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Mon, Jul 18, 2022 at 01:41:37PM +0200, Peter Zijlstra wrote:
> diff --git a/arch/x86/include/asm/nospec-branch.h b/arch/x86/include/asm/nospec-branch.h
> index 10a3bfc1eb23..f934dcdb7c0d 100644
> --- a/arch/x86/include/asm/nospec-branch.h
> +++ b/arch/x86/include/asm/nospec-branch.h
> @@ -297,6 +297,8 @@ do {									\
>  	alternative_msr_write(MSR_IA32_SPEC_CTRL,			\
>  			      spec_ctrl_current() | SPEC_CTRL_IBRS,	\
>  			      X86_FEATURE_USE_IBRS_FW);			\
> +	altnerative_msr_write(MSR_IA32_PRED_CMD, PRED_CMD_IBPB,		\
> +			      X86_FEATURE_USE_IBPB_FW);			\
>  } while (0)

So I'm being told we need to untrain on return from EFI to protect the
kernel from it. Ontop of yours.

Asm looks correct but lemme run it through the test builds first...

---
diff --git a/arch/x86/include/asm/nospec-branch.h b/arch/x86/include/asm/nospec-branch.h
index 38a3e86e665e..e58f18555022 100644
--- a/arch/x86/include/asm/nospec-branch.h
+++ b/arch/x86/include/asm/nospec-branch.h
@@ -62,6 +62,12 @@
 	dec	reg;				\
 	jnz	771b;
 
+#ifdef CONFIG_CPU_UNRET_ENTRY
+#define CALL_ZEN_UNTRAIN_RET	"call zen_untrain_ret"
+#else
+#define CALL_ZEN_UNTRAIN_RET	""
+#endif
+
 #ifdef __ASSEMBLY__
 
 /*
@@ -128,12 +134,6 @@
 .Lskip_rsb_\@:
 .endm
 
-#ifdef CONFIG_CPU_UNRET_ENTRY
-#define CALL_ZEN_UNTRAIN_RET	"call zen_untrain_ret"
-#else
-#define CALL_ZEN_UNTRAIN_RET	""
-#endif
-
 /*
  * Mitigate RETBleed for AMD/Hygon Zen uarch. Requires KERNEL CR3 because the
  * return thunk isn't mapped into the userspace tables (then again, AMD
@@ -169,6 +169,16 @@ extern void __x86_return_thunk(void);
 extern void zen_untrain_ret(void);
 extern void entry_ibpb(void);
 
+#if defined(CONFIG_CPU_UNRET_ENTRY) || defined(CONFIG_CPU_IBPB_ENTRY)
+# define UNTRAIN_RET						\
+	asm volatile(ALTERNATIVE_2(ANNOTATE_RETPOLINE_SAFE "nop", \
+		     CALL_ZEN_UNTRAIN_RET, X86_FEATURE_UNRET,	\
+		     "call entry_ibpb", X86_FEATURE_ENTRY_IBPB)	\
+		     ::)
+#else
+# define UNTRAIN_RET
+#endif
+
 #ifdef CONFIG_RETPOLINE
 
 #define GEN(reg) \
@@ -306,6 +316,7 @@ do {									\
 	alternative_msr_write(MSR_IA32_SPEC_CTRL,			\
 			      spec_ctrl_current(),			\
 			      X86_FEATURE_USE_IBRS_FW);			\
+	UNTRAIN_RET;							\
 	preempt_enable();						\
 } while (0)
 

-- 
Regards/Gruss,
    Boris.

SUSE Software Solutions Germany GmbH
GF: Ivo Totev, Andrew Myers, Andrew McDonald, Martje Boudien Moerman
(HRB 36809, AG Nürnberg)



[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux OMAP]     [Linux MIPS]     [ECOS]     [Asterisk Internet PBX]     [Linux API]

  Powered by Linux