x86-64: don't allow non-canonical addresses to be set for any callback
authorJan Beulich <jbeulich@suse.com>
Mon, 18 Jun 2012 15:02:01 +0000 (17:02 +0200)
committerJan Beulich <jbeulich@suse.com>
Mon, 18 Jun 2012 15:02:01 +0000 (17:02 +0200)
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 <jbeulich@suse.com>
Acked-by: Keir Fraser <keir@xen.org>
xen/arch/x86/domain.c
xen/arch/x86/domctl.c
xen/arch/x86/traps.c

index ac3b6b8b5b8747682c9237b92ed6dceb1a43b61b..5bba4b9f5c675adae3c4d3ce7064814fbb6f1e12 100644 (file)
@@ -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
 
             for ( i = 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);
+            }
 
             /* LDT safety checks. */
             if ( ((c.nat->ldt_base & (PAGE_SIZE-1)) != 0) ||
index 498eb578b0541a1ced2670422bd66d3fe3270ac8..135ea6eca0ae2e8da34c1dd114232d0a40c4d329 100644 (file)
@@ -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      =
                     evc->sysenter_callback_cs;
index d4fdf64e1d9c217d5164eb67f7ea408c2571f0d1..2264583f14d626634582c3631c00cb97cc833010 100644 (file)
@@ -3581,6 +3581,9 @@ long register_guest_nmi_callback(unsigned long address)
     struct domain *d = v->domain;
     struct trap_info *t = &v->arch.pv_vcpu.trap_ctxt[TRAP_nmi];
 
+    if ( !is_canonical_address(address) )
+        return -EINVAL;
+
     t->vector  = TRAP_nmi;
     t->flags   = 0;
     t->cs      = (is_pv_32on64_domain(d) ?
@@ -3708,6 +3711,9 @@ long do_set_trap_table(XEN_GUEST_HANDLE(const_trap_info_t) traps)
         if ( cur.address == 0 )
             break;
 
+        if ( !is_canonical_address(cur.address) )
+            return -EINVAL;
+
         fixup_guest_code_selector(curr->domain, cur.cs);
 
         memcpy(&dst[cur.vector], &cur, sizeof(cur));