From: "Jan Beulich" Subject: [PATCH] x86-64: don't allow non-canonical addresses to be set for any callback Date: Wed, 13 Jun 2012 11:02:27 +0100 Message-ID: <4FD881530200007800089ACB@nat28.tlf.novell.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=__PartB9972323.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. --=__PartB9972323.0__= Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Rather than deferring the detection of these to the point where they get actually used (the fix for XSA-7, 25480:76eaf5966c05, causing a #GP to be raised by IRET, which invokes the guest's [fragile] fail-safe callback), don't even allow such to be set. Signed-off-by: Jan Beulich --- a/xen/arch/x86/domain.c +++ b/xen/arch/x86/domain.c @@ -736,6 +736,14 @@ int arch_set_info_guest( { if ( !compat ) { +#ifdef __x86_64__ + if ( !is_canonical_address(c.nat->user_regs.eip) || + !is_canonical_address(c.nat->event_callback_eip) || + !is_canonical_address(c.nat->syscall_callback_eip) || + !is_canonical_address(c.nat->failsafe_callback_eip) ) + return -EINVAL; +#endif + fixup_guest_stack_selector(d, c.nat->user_regs.ss); fixup_guest_stack_selector(d, c.nat->kernel_ss); fixup_guest_code_selector(d, c.nat->user_regs.cs); @@ -745,7 +753,11 @@ int arch_set_info_guest( #endif =20 for ( i =3D 0; i < 256; i++ ) + { + if ( !is_canonical_address(c.nat->trap_ctxt[i].address) ) + return -EINVAL; fixup_guest_code_selector(d, c.nat->trap_ctxt[i].cs); + } =20 /* LDT safety checks. */ if ( ((c.nat->ldt_base & (PAGE_SIZE-1)) !=3D 0) || --- a/xen/arch/x86/domctl.c +++ b/xen/arch/x86/domctl.c @@ -1033,6 +1033,9 @@ long arch_do_domctl( #ifdef __x86_64__ if ( !is_hvm_domain(d) ) { + if ( !is_canonical_address(evc->sysenter_callback_eip) || + !is_canonical_address(evc->syscall32_callback_eip) ) + goto ext_vcpucontext_out; fixup_guest_code_selector(d, evc->sysenter_callback_cs); v->arch.pv_vcpu.sysenter_callback_cs =3D evc->sysenter_callback_cs; --- a/xen/arch/x86/traps.c +++ b/xen/arch/x86/traps.c @@ -3581,6 +3581,9 @@ long register_guest_nmi_callback(unsigne struct domain *d =3D v->domain; struct trap_info *t =3D &v->arch.pv_vcpu.trap_ctxt[TRAP_nmi]; =20 + if ( !is_canonical_address(address) ) + return -EINVAL; + t->vector =3D TRAP_nmi; t->flags =3D 0; t->cs =3D (is_pv_32on64_domain(d) ? @@ -3708,6 +3711,9 @@ long do_set_trap_table(XEN_GUEST_HANDLE( if ( cur.address =3D=3D 0 ) break; =20 + if ( !is_canonical_address(cur.address) ) + return -EINVAL; + fixup_guest_code_selector(curr->domain, cur.cs); =20 memcpy(&dst[cur.vector], &cur, sizeof(cur)); --=__PartB9972323.0__= Content-Type: text/plain; name="x86_64-canonical-checks.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="x86_64-canonical-checks.patch" x86-64: don't allow non-canonical addresses to be set for any callback=0A= =0ARather than deferring the detection of these to the point where = they=0Aget actually used (the fix for XSA-7, 25480:76eaf5966c05, causing a = #GP=0Ato be raised by IRET, which invokes the guest's [fragile] = fail-safe=0Acallback), don't even allow such to be set.=0A=0ASigned-off-by:= Jan Beulich =0A=0A--- a/xen/arch/x86/domain.c=0A+++ = b/xen/arch/x86/domain.c=0A@@ -736,6 +736,14 @@ int arch_set_info_guest(=0A = {=0A if ( !compat )=0A {=0A+#ifdef __x86_64__=0A+ = if ( !is_canonical_address(c.nat->user_regs.eip) ||=0A+ = !is_canonical_address(c.nat->event_callback_eip) ||=0A+ = !is_canonical_address(c.nat->syscall_callback_eip) ||=0A+ = !is_canonical_address(c.nat->failsafe_callback_eip) )=0A+ = return -EINVAL;=0A+#endif=0A+=0A fixup_guest_stack_selector(d, = c.nat->user_regs.ss);=0A fixup_guest_stack_selector(d, = c.nat->kernel_ss);=0A fixup_guest_code_selector(d, c.nat->user_= regs.cs);=0A@@ -745,7 +753,11 @@ int arch_set_info_guest(=0A #endif=0A =0A = for ( i =3D 0; i < 256; i++ )=0A+ {=0A+ = if ( !is_canonical_address(c.nat->trap_ctxt[i].address) )=0A+ = return -EINVAL;=0A fixup_guest_code_selector(d, = c.nat->trap_ctxt[i].cs);=0A+ }=0A =0A /* LDT safety = checks. */=0A if ( ((c.nat->ldt_base & (PAGE_SIZE-1)) !=3D 0) = ||=0A--- a/xen/arch/x86/domctl.c=0A+++ b/xen/arch/x86/domctl.c=0A@@ = -1033,6 +1033,9 @@ long arch_do_domctl(=0A #ifdef __x86_64__=0A = if ( !is_hvm_domain(d) )=0A {=0A+ if ( = !is_canonical_address(evc->sysenter_callback_eip) ||=0A+ = !is_canonical_address(evc->syscall32_callback_eip) )=0A+ = goto ext_vcpucontext_out;=0A fixup_guest_code_selector(d= , evc->sysenter_callback_cs);=0A v->arch.pv_vcpu.sysenter_c= allback_cs =3D=0A evc->sysenter_callback_cs;=0A---= a/xen/arch/x86/traps.c=0A+++ b/xen/arch/x86/traps.c=0A@@ -3581,6 +3581,9 = @@ long register_guest_nmi_callback(unsigne=0A struct domain *d =3D = v->domain;=0A struct trap_info *t =3D &v->arch.pv_vcpu.trap_ctxt[TRAP_n= mi];=0A =0A+ if ( !is_canonical_address(address) )=0A+ return = -EINVAL;=0A+=0A t->vector =3D TRAP_nmi;=0A t->flags =3D 0;=0A = t->cs =3D (is_pv_32on64_domain(d) ?=0A@@ -3708,6 +3711,9 @@ long = do_set_trap_table(XEN_GUEST_HANDLE(=0A if ( cur.address =3D=3D 0 = )=0A break;=0A =0A+ if ( !is_canonical_address(cur.addre= ss) )=0A+ return -EINVAL;=0A+=0A fixup_guest_code_select= or(curr->domain, cur.cs);=0A =0A memcpy(&dst[cur.vector], &cur, = sizeof(cur));=0A --=__PartB9972323.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 --=__PartB9972323.0__=--