]> xenbits.xensource.com Git - xen.git/commitdiff
x86/boot: Sanitise PKRU on boot
authorAndrew Cooper <andrew.cooper3@citrix.com>
Tue, 10 Jan 2023 10:57:21 +0000 (10:57 +0000)
committerAndrew Cooper <andrew.cooper3@citrix.com>
Fri, 20 Jan 2023 19:39:32 +0000 (19:39 +0000)
While the reset value of the register is 0, it might not be after kexec/etc.
If PKEY0.{WD,AD} have leaked in from an earlier context, construction of a PV
dom0 will explode.

Sequencing wise, this must come after setting CR4.PKE, and before we touch any
user mappings.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
xen/arch/x86/cpu/common.c
xen/arch/x86/include/asm/cpufeature.h
xen/arch/x86/setup.c

index 0412dbc915e51a518c4541e50c9690b6afcb79bb..fe92f29c2dc6a854d3b2e8de1650909a38ff39e4 100644 (file)
@@ -936,6 +936,9 @@ void cpu_init(void)
        write_debugreg(6, X86_DR6_DEFAULT);
        write_debugreg(7, X86_DR7_DEFAULT);
 
+       if (cpu_has_pku)
+               wrpkru(0);
+
        /*
         * If the platform is performing a Secure Launch via SKINIT, GIF is
         * clear to prevent external interrupts interfering with Secure
index a3ad9ebee4e9ab288da703b36d61cb5c2c123ef2..044cfd9f882d6c328d451341b2e5e1a55f744738 100644 (file)
 
 /* CPUID level 0x00000007:0.ecx */
 #define cpu_has_avx512_vbmi     boot_cpu_has(X86_FEATURE_AVX512_VBMI)
+#define cpu_has_pku             boot_cpu_has(X86_FEATURE_PKU)
 #define cpu_has_avx512_vbmi2    boot_cpu_has(X86_FEATURE_AVX512_VBMI2)
 #define cpu_has_gfni            boot_cpu_has(X86_FEATURE_GFNI)
 #define cpu_has_vaes            boot_cpu_has(X86_FEATURE_VAES)
index 566422600d945405c7c8b645d095c44f9377f5f3..6deadcf74763a2797df29dce178e325621d00161 100644 (file)
@@ -1798,7 +1798,7 @@ void __init noreturn __start_xen(unsigned long mbi_p)
     if ( boot_cpu_has(X86_FEATURE_FSGSBASE) )
         set_in_cr4(X86_CR4_FSGSBASE);
 
-    if ( boot_cpu_has(X86_FEATURE_PKU) )
+    if ( cpu_has_pku )
         set_in_cr4(X86_CR4_PKE);
 
     if ( opt_invpcid && cpu_has_invpcid )