From: "Jan Beulich" Subject: [PATCH] x86-64: refine the XSA-9 fix Date: Wed, 13 Jun 2012 11:04:27 +0100 Message-ID: <4FD881CB0200007800089ADB@nat28.tlf.novell.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=__Part210FBBBB.0__=" Return-path: List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: xen-devel List-Id: xen-devel@lists.xenproject.org This is a MIME message. If you are reading this text, you may want to consider changing to a mail reader or gateway that understands how to properly handle MIME multipart messages. --=__Part210FBBBB.0__= Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Our product management wasn't happy with the "solution" for XSA-9, and demanded that customer systems must continue to boot. Rather than having our and perhaps other distros carry non-trivial patches, allow for more fine grained control (panic on boot, deny guest creation, or merely warn) by means of a single line change. Signed-off-by: Jan Beulich --- a/xen/arch/x86/cpu/amd.c +++ b/xen/arch/x86/cpu/amd.c @@ -32,8 +32,11 @@ static char opt_famrev[14]; string_param("cpuid_mask_cpu", opt_famrev); =20 -static bool_t opt_allow_unsafe; +#ifdef __x86_64__ +/* 1 =3D allow, 0 =3D don't allow guest creation, -1 =3D don't allow boot = */ +s8 __read_mostly opt_allow_unsafe =3D -1; boolean_param("allow_unsafe", opt_allow_unsafe); +#endif =20 static inline void wrmsr_amd(unsigned int index, unsigned int lo,=20 unsigned int hi) @@ -496,10 +499,19 @@ static void __devinit init_amd(struct cp clear_bit(X86_FEATURE_MWAIT, c->x86_capability); =20 #ifdef __x86_64__ - if (cpu_has_amd_erratum(c, AMD_ERRATUM_121) && !opt_allow_unsafe) + if (!cpu_has_amd_erratum(c, AMD_ERRATUM_121)) + opt_allow_unsafe =3D 1; + else if (opt_allow_unsafe < 0) panic("Xen will not boot on this CPU for security = reasons.\n" "Pass \"allow_unsafe\" if you're trusting all your" " (PV) guest kernels.\n"); + else if (!opt_allow_unsafe && c =3D=3D &boot_cpu_data) + printk(KERN_WARNING + "*** Xen will not allow creation of DomU-s on" + " this CPU for security reasons. ***\n" + KERN_WARNING + "*** Pass \"allow_unsafe\" if you're trusting" + " all your (PV) guest kernels. ***\n"); =20 /* AMD CPUs do not support SYSENTER outside of legacy mode. */ clear_bit(X86_FEATURE_SEP, c->x86_capability); --- a/xen/arch/x86/domain.c +++ b/xen/arch/x86/domain.c @@ -55,6 +55,7 @@ #include #include #include +#include #include #include #ifdef CONFIG_COMPAT @@ -531,6 +532,20 @@ int arch_domain_create(struct domain *d, =20 #else /* __x86_64__ */ =20 + if ( d->domain_id && !is_idle_domain(d) && + cpu_has_amd_erratum(&boot_cpu_data, AMD_ERRATUM_121) ) + { + if ( !opt_allow_unsafe ) + { + printk(XENLOG_G_ERR "Xen does not allow DomU creation on this = CPU" + " for security reasons.\n"); + return -EPERM; + } + printk(XENLOG_G_WARNING + "Dom%d may compromise security on this CPU.\n", + d->domain_id); + } + BUILD_BUG_ON(PDPT_L2_ENTRIES * sizeof(*d->arch.mm_perdomain_pt_pages) !=3D PAGE_SIZE); pg =3D alloc_domheap_page(NULL, MEMF_node(domain_to_node(d))); --- a/xen/include/asm-x86/amd.h +++ b/xen/include/asm-x86/amd.h @@ -147,6 +147,8 @@ struct cpuinfo_x86; int cpu_has_amd_erratum(const struct cpuinfo_x86 *, int, ...); =20 #ifdef __x86_64__ +extern s8 opt_allow_unsafe; + void fam10h_check_enable_mmcfg(void); void check_enable_amd_mmconf_dmi(void); #endif --=__Part210FBBBB.0__= Content-Type: text/plain; name="x86_64-allow-unsafe-adjust.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="x86_64-allow-unsafe-adjust.patch" x86-64: refine the XSA-9 fix=0A=0AOur product management wasn't happy with = the "solution" for XSA-9, and=0Ademanded that customer systems must = continue to boot. Rather than=0Ahaving our and perhaps other distros carry = non-trivial patches, allow=0Afor more fine grained control (panic on boot, = deny guest creation, or=0Amerely warn) by means of a single line change.=0A= =0ASigned-off-by: Jan Beulich =0A=0A--- a/xen/arch/x86/c= pu/amd.c=0A+++ b/xen/arch/x86/cpu/amd.c=0A@@ -32,8 +32,11 @@=0A static = char opt_famrev[14];=0A string_param("cpuid_mask_cpu", opt_famrev);=0A = =0A-static bool_t opt_allow_unsafe;=0A+#ifdef __x86_64__=0A+/* 1 =3D = allow, 0 =3D don't allow guest creation, -1 =3D don't allow boot */=0A+s8 = __read_mostly opt_allow_unsafe =3D -1;=0A boolean_param("allow_unsafe", = opt_allow_unsafe);=0A+#endif=0A =0A static inline void wrmsr_amd(unsigned = int index, unsigned int lo, =0A unsigned int hi)=0A@@ = -496,10 +499,19 @@ static void __devinit init_amd(struct cp=0A = clear_bit(X86_FEATURE_MWAIT, c->x86_capability);=0A =0A #ifdef __x86_64__= =0A- if (cpu_has_amd_erratum(c, AMD_ERRATUM_121) && !opt_allow_unsafe)= =0A+ if (!cpu_has_amd_erratum(c, AMD_ERRATUM_121))=0A+ = opt_allow_unsafe =3D 1;=0A+ else if (opt_allow_unsafe < 0)=0A = panic("Xen will not boot on this CPU for security reasons.\n"=0A = "Pass \"allow_unsafe\" if you're trusting all your"=0A = " (PV) guest kernels.\n");=0A+ else if (!opt_allow_unsafe && c = =3D=3D &boot_cpu_data)=0A+ printk(KERN_WARNING=0A+ = "*** Xen will not allow creation of DomU-s on"=0A+ " = this CPU for security reasons. ***\n"=0A+ KERN_WARNING= =0A+ "*** Pass \"allow_unsafe\" if you're trusting"=0A+ = " all your (PV) guest kernels. ***\n");=0A =0A /* AMD = CPUs do not support SYSENTER outside of legacy mode. */=0A clear_bit(X= 86_FEATURE_SEP, c->x86_capability);=0A--- a/xen/arch/x86/domain.c=0A+++ = b/xen/arch/x86/domain.c=0A@@ -55,6 +55,7 @@=0A #include =0A = #include =0A #include =0A+#include =0A = #include =0A #include =0A #ifdef CONFIG_COMPAT=0A@= @ -531,6 +532,20 @@ int arch_domain_create(struct domain *d,=0A =0A #else = /* __x86_64__ */=0A =0A+ if ( d->domain_id && !is_idle_domain(d) &&=0A+ = cpu_has_amd_erratum(&boot_cpu_data, AMD_ERRATUM_121) )=0A+ = {=0A+ if ( !opt_allow_unsafe )=0A+ {=0A+ = printk(XENLOG_G_ERR "Xen does not allow DomU creation on this CPU"=0A+ = " for security reasons.\n");=0A+ return -EPERM;=0A= + }=0A+ printk(XENLOG_G_WARNING=0A+ "Dom%d may = compromise security on this CPU.\n",=0A+ d->domain_id);=0A+ = }=0A+=0A BUILD_BUG_ON(PDPT_L2_ENTRIES * sizeof(*d->arch.mm_perdomain_= pt_pages)=0A !=3D PAGE_SIZE);=0A pg =3D alloc_domheap_= page(NULL, MEMF_node(domain_to_node(d)));=0A--- a/xen/include/asm-x86/amd.h= =0A+++ b/xen/include/asm-x86/amd.h=0A@@ -147,6 +147,8 @@ struct cpuinfo_x86= ;=0A int cpu_has_amd_erratum(const struct cpuinfo_x86 *, int, ...);=0A =0A = #ifdef __x86_64__=0A+extern s8 opt_allow_unsafe;=0A+=0A void fam10h_check_e= nable_mmcfg(void);=0A void check_enable_amd_mmconf_dmi(void);=0A #endif=0A --=__Part210FBBBB.0__= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Xen-devel mailing list Xen-devel@lists.xen.org http://lists.xen.org/xen-devel --=__Part210FBBBB.0__=--