Skip to contentSkip to conversation

Xen Security Advisory 97 (CVE-2014-5146, CVE-2014-5149) - Long latency virtual-mmu operations are not preemptible

PATCH Xen.org security team 1 participant 1 message Aug 12, 2014

lore
Share & tools
lore
#0 lore raw

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Xen Security Advisory CVE-2014-5146,CVE-2014-5149 / XSA-97
version 3

Long latency virtual-mmu operations are not preemptible

UPDATES IN VERSION 3
====================

Public release.

ISSUE DESCRIPTION
=================

Some MMU virtualization operations on HVM guests must process every page assigned to a guest. For larger guests, this can tie up a vcpu for a significant amount of time, as the operations are not preemptible.

For guests using Hardware Assisted Paging (HAP, see below) this is CVE-2014-5146. For guests not using HAP this is CVE-2014-5149.

IMPACT
======

A malicious HVM guest with a large allocation of shadow/p2m RAM can mount a denial of service attack affecting the whole system.

VULNERABLE SYSTEMS
==================

ARM systems are not vulnerable.

All x86 Xen versions are vulnerable.

The vulnerability is only exposed to HVM guests.

In the default configuration, the vulnerability is only exposed to large guests (guests assigned more than 128Gbytes of memory).

MITIGATION
==========

Running only PV guests, or only smaller guests will avoid this problem.

Since the vulnerability actually depends on the guest's shadow memory, if you are overriding the default allocation (which is about 0.5% of guest RAM) by using the "shadow_memory=" VM configuration file option, you should adjust your idea of a 'smaller' guest accordingly.

CREDITS
=======

This issue was discovered by Jan Beulich.

RESOLUTION
==========

For HAP-enabled guests, the attached patch resolves ths issue.

HAP (Hardware Assisted Paging, aka nested paging) is enabled by default if the system is suitably capable. The VM configuration file can disable or enable HAP explicitly by setting "hap=0" or "hap=1". HAP can also be globally disabled by specifying "hap=off" on the hypervisor command line.

There is no resolution for guests using shadow pagetables (i.e., not using HAP) at this time.

xsa97-hap-unstable.patch                             xen-unstable
xsa97-hap-4.4.patch                                  Xen 4.4.x
xsa97-hap-4.3.patch                                  Xen 4.3.x
xsa97-hap-4.2-prereq.patch, xsa97-hap-4.2.patch      Xen 4.2.x
$ sha256sum xsa97*.patch
c9e0e9f136db1b976ea371be10430598a7f21b4a33b4849f2081566657ff5da1  xsa97-hap-4.2.patch
c525a99263eed6f93fad685ae9dad1ae10c8930345ec52659211541640797bb5  xsa97-hap-4.2-prereq.patch
cfab6521221a5058a0dfbb6d59c3c4cd0e7f4239bb6cbee2723de22c33caafda  xsa97-hap-4.3.patch
138511f2fd8362366e09dda18443387886ec4397eecc1a2f6a7e85643bd415e8  xsa97-hap-4.4.patch
58c56daa01f20be0317700d383dfbba8de35695bd38a9860c0c0463181d76351  xsa97-hap-unstable.patch
$
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.12 (GNU/Linux)

iQEcBAEBAgAGBQJT6hBmAAoJEIP+FMlX6CvZ8sgIAIqtUEu6CS5+H3enavmmLhuh PGLCqQOBVWn99+m6bMqk+WvZOkW9CLxiX6+78XsheJlmUFBtHc3rG53wR0voo6Vr BXyU3XY2n4aEh1klstS3gq/J37L86fEi2a+MaAePbPZ4qdWvFh3zDhRrLTQ/TDvK 0tfze9fF6K24Ab7jAcstF2gn+NhrrS3L3pvvgD/P5T1LR8HrEsyyhTlf7c34T5cp RnSM19CUqAVAJeyN6WI2meZ3C+nvxLiNRUEQQikf4yCKqGxevzjBLAbXlcw4ELnF 9rG7Yd1aRJh4pQkViFDIdB3x8Xb9HuT7kFsQ7kBZc3an9JkbxxTGQd82XjODM1Q= =A/Ph
-----END PGP SIGNATURE-----

x86/paging: make log-dirty operations preemptible

Both the freeing and the inspection of the bitmap get done in (nested) loops which - besides having a rather high iteration count in general, albeit that would be covered by XSA-77 - have the number of non-trivial iterations they need to perform (indirectly) controllable by both the guest they are for and any domain controlling the guest (including the one running qemu for it).

This is XSA-97.

xen/arch/x86/domain.c +3 -1
@@ -2136,7 +2136,9 @@ int domain_relinquish_resources(struct d
         pci_release_devices(d);
 
         /* Tear down paging-assistance stuff. */
-        paging_teardown(d);
+        ret = paging_teardown(d);
+        if ( ret )
+            return ret;
 
         /* Drop the in-use references to page-table bases. */
         for_each_vcpu ( d, v )
xen/arch/x86/domctl.c +3 -0
@@ -66,6 +66,9 @@ long arch_do_domctl(
                                 &domctl->u.shadow_op,
                                 guest_handle_cast(u_domctl, void));
             rcu_unlock_domain(d);
+            if ( ret == -EAGAIN )
+                return hypercall_create_continuation(__HYPERVISOR_domctl,
+                                                     "h", u_domctl);
             copy_to_guest(u_domctl, domctl, 1);
         } 
     }
xen/arch/x86/mm/hap/hap.c +1 -2
@@ -678,8 +678,7 @@ int hap_domctl(struct domain *d, xen_dom
         paging_unlock(d);
         if ( preempted )
             /* Not finished.  Set up to re-run the call. */
-            rc = hypercall_create_continuation(__HYPERVISOR_domctl, "h",
-                                               u_domctl);
+            rc = -EAGAIN;
         else
             /* Finished.  Return the new allocation */
             sc->mb = hap_get_allocation(d);
xen/arch/x86/mm/paging.c +163 -36

342 lines not on this page · raw message

xen/arch/x86/mm/shadow/common.c +1 -2
@@ -3829,8 +3829,7 @@ int shadow_domctl(struct domain *d, 
         paging_unlock(d);
         if ( preempted )
             /* Not finished.  Set up to re-run the call. */
-            rc = hypercall_create_continuation(
-                __HYPERVISOR_domctl, "h", u_domctl);
+            rc = -EAGAIN;
         else 
             /* Finished.  Return the new allocation */
             sc->mb = shadow_get_allocation(d);
xen/common/domain.c +0 -1
@@ -479,7 +479,6 @@ int domain_kill(struct domain *d)
         rc = domain_relinquish_resources(d);
         if ( rc != 0 )
         {
-            BUG_ON(rc != -EAGAIN);
             break;
         }
         if ( sched_move_domain(d, cpupool0) )
xen/include/asm-x86/domain.h +14 -0
@@ -193,6 +193,20 @@ struct paging_domain {
     struct hap_domain       hap;
     /* log dirty support */
     struct log_dirty_domain log_dirty;
+
+    /* preemption handling */
+    struct {
+        struct vcpu *vcpu;
+        unsigned int op;
+        union {
+            struct {
+                unsigned long done:PADDR_BITS - PAGE_SHIFT;
+                unsigned long i4:PAGETABLE_ORDER;
+                unsigned long i3:PAGETABLE_ORDER;
+            } log_dirty;
+        };
+    } preempt;
+
     /* alloc/free pages from the pool for paging-assistance structures
      * (used by p2m and log-dirty code for their tries) */
     struct page_info * (*alloc_page)(struct domain *d);
xen/include/asm-x86/paging.h +1 -7
@@ -141,9 +141,6 @@ struct paging_mode {
 /*****************************************************************************
  * Log dirty code */
 
-/* free log dirty bitmap resource */
-void paging_free_log_dirty_bitmap(struct domain *d);
-
 /* get the dirty bitmap for a specific range of pfns */
 void paging_log_dirty_range(struct domain *d,
                             unsigned long begin_pfn,
@@ -153,9 +150,6 @@ void paging_log_dirty_range(struct domai
 /* enable log dirty */
 int paging_log_dirty_enable(struct domain *d);
 
-/* disable log dirty */
-int paging_log_dirty_disable(struct domain *d);
-
 /* log dirty initialization */
 void paging_log_dirty_init(struct domain *d,
                            int  (*enable_log_dirty)(struct domain *d),
@@ -218,7 +212,7 @@ int paging_domctl(struct domain *d, xen_
                   XEN_GUEST_HANDLE(void) u_domctl);
 
 /* Call when destroying a domain */
-void paging_teardown(struct domain *d);
+int paging_teardown(struct domain *d);
 
 /* Call once all of the references to the domain have gone away */
 void paging_final_teardown(struct domain *d);

x86/mm/hap: Adjust vram tracking to play nicely with log-dirty.

The previous code assumed the guest would be in one of three mutually exclusive modes for bookkeeping dirty pages: (1) shadow, (2) hap utilizing the log dirty bitmap to support functionality such as live migrate, (3) hap utilizing the log dirty bitmap to track dirty vram pages.
Races arose when a guest attempted to track dirty vram while performing live migrate. (The dispatch table managed by paging_log_dirty_init() might change in the middle of a log dirty or a vram tracking function.)

This change allows hap log dirty and hap vram tracking to be concurrent. Vram tracking no longer uses the log dirty bitmap. Instead it detects dirty vram pages by examining their p2m type. The log dirty bitmap is only used by the log dirty code. Because the two operations use different mechanisms, they are no longer mutually exclusive.

Minor whitespace changes to conform with coding style

master commit: fd91a2a662bc59677e0f217423a7a155d5465886 master date: 2012-12-13 12:10:14 +0000

xen/arch/x86/mm/hap/hap.c +78 -107

223 lines not on this page · raw message

xen/arch/x86/mm/paging.c +26 -145

183 lines not on this page · raw message

xen/include/asm-x86/config.h +1 -0
@@ -17,6 +17,7 @@
 
 #define BYTES_PER_LONG (1 << LONG_BYTEORDER)
 #define BITS_PER_LONG (BYTES_PER_LONG << 3)
+#define BITS_PER_BYTE 8
 
 #define CONFIG_X86 1
 #define CONFIG_X86_HT 1
xen/include/asm-x86/paging.h +4 -4
@@ -145,10 +145,10 @@ struct paging_mode {
 void paging_free_log_dirty_bitmap(struct domain *d);
 
 /* get the dirty bitmap for a specific range of pfns */
-int paging_log_dirty_range(struct domain *d,
-                           unsigned long begin_pfn,
-                           unsigned long nr,
-                           XEN_GUEST_HANDLE_64(uint8) dirty_bitmap);
+void paging_log_dirty_range(struct domain *d,
+                            unsigned long begin_pfn,
+                            unsigned long nr,
+                            uint8_t *dirty_bitmap);
 
 /* enable log dirty */
 int paging_log_dirty_enable(struct domain *d);

x86/paging: make log-dirty operations preemptible

Both the freeing and the inspection of the bitmap get done in (nested) loops which - besides having a rather high iteration count in general, albeit that would be covered by XSA-77 - have the number of non-trivial iterations they need to perform (indirectly) controllable by both the guest they are for and any domain controlling the guest (including the one running qemu for it).

This is XSA-97.

xen/arch/x86/domain.c +3 -1
@@ -1867,7 +1867,9 @@ int domain_relinquish_resources(struct d
         pci_release_devices(d);
 
         /* Tear down paging-assistance stuff. */
-        paging_teardown(d);
+        ret = paging_teardown(d);
+        if ( ret )
+            return ret;
 
         /* Drop the in-use references to page-table bases. */
         for_each_vcpu ( d, v )
xen/arch/x86/domctl.c +3 -0
@@ -61,6 +61,9 @@ long arch_do_domctl(
         ret = paging_domctl(d,
                             &domctl->u.shadow_op,
                             guest_handle_cast(u_domctl, void));
+        if ( ret == -EAGAIN )
+            return hypercall_create_continuation(__HYPERVISOR_domctl,
+                                                 "h", u_domctl);
         copyback = 1;
     }
     break;
xen/arch/x86/mm/hap/hap.c +1 -2
@@ -565,8 +565,7 @@ int hap_domctl(struct domain *d, xen_dom
         paging_unlock(d);
         if ( preempted )
             /* Not finished.  Set up to re-run the call. */
-            rc = hypercall_create_continuation(__HYPERVISOR_domctl, "h",
-                                               u_domctl);
+            rc = -EAGAIN;
         else
             /* Finished.  Return the new allocation */
             sc->mb = hap_get_allocation(d);
xen/arch/x86/mm/paging.c +163 -36

342 lines not on this page · raw message

xen/arch/x86/mm/shadow/common.c +1 -2
@@ -3706,8 +3706,7 @@ int shadow_domctl(struct domain *d, 
         paging_unlock(d);
         if ( preempted )
             /* Not finished.  Set up to re-run the call. */
-            rc = hypercall_create_continuation(
-                __HYPERVISOR_domctl, "h", u_domctl);
+            rc = -EAGAIN;
         else 
             /* Finished.  Return the new allocation */
             sc->mb = shadow_get_allocation(d);
xen/common/domain.c +0 -1
@@ -527,7 +527,6 @@ int domain_kill(struct domain *d)
         rc = domain_relinquish_resources(d);
         if ( rc != 0 )
         {
-            BUG_ON(rc != -EAGAIN);
             break;
         }
         if ( sched_move_domain(d, cpupool0) )
xen/include/asm-x86/domain.h +14 -0
@@ -186,6 +186,20 @@ struct paging_domain {
     struct hap_domain       hap;
     /* log dirty support */
     struct log_dirty_domain log_dirty;
+
+    /* preemption handling */
+    struct {
+        struct vcpu *vcpu;
+        unsigned int op;
+        union {
+            struct {
+                unsigned long done:PADDR_BITS - PAGE_SHIFT;
+                unsigned long i4:PAGETABLE_ORDER;
+                unsigned long i3:PAGETABLE_ORDER;
+            } log_dirty;
+        };
+    } preempt;
+
     /* alloc/free pages from the pool for paging-assistance structures
      * (used by p2m and log-dirty code for their tries) */
     struct page_info * (*alloc_page)(struct domain *d);
xen/include/asm-x86/paging.h +1 -7
@@ -133,9 +133,6 @@ struct paging_mode {
 /*****************************************************************************
  * Log dirty code */
 
-/* free log dirty bitmap resource */
-void paging_free_log_dirty_bitmap(struct domain *d);
-
 /* get the dirty bitmap for a specific range of pfns */
 void paging_log_dirty_range(struct domain *d,
                             unsigned long begin_pfn,
@@ -145,9 +142,6 @@ void paging_log_dirty_range(struct domai
 /* enable log dirty */
 int paging_log_dirty_enable(struct domain *d);
 
-/* disable log dirty */
-int paging_log_dirty_disable(struct domain *d);
-
 /* log dirty initialization */
 void paging_log_dirty_init(struct domain *d,
                            int  (*enable_log_dirty)(struct domain *d),
@@ -206,7 +200,7 @@ int paging_domctl(struct domain *d, xen_
                   XEN_GUEST_HANDLE_PARAM(void) u_domctl);
 
 /* Call when destroying a domain */
-void paging_teardown(struct domain *d);
+int paging_teardown(struct domain *d);
 
 /* Call once all of the references to the domain have gone away */
 void paging_final_teardown(struct domain *d);

x86/paging: make log-dirty operations preemptible

Both the freeing and the inspection of the bitmap get done in (nested) loops which - besides having a rather high iteration count in general, albeit that would be covered by XSA-77 - have the number of non-trivial iterations they need to perform (indirectly) controllable by both the guest they are for and any domain controlling the guest (including the one running qemu for it).

This is XSA-97.

xen/arch/x86/domain.c +3 -1
@@ -1915,7 +1915,9 @@ int domain_relinquish_resources(struct d
         pci_release_devices(d);
 
         /* Tear down paging-assistance stuff. */
-        paging_teardown(d);
+        ret = paging_teardown(d);
+        if ( ret )
+            return ret;
 
         /* Drop the in-use references to page-table bases. */
         for_each_vcpu ( d, v )
xen/arch/x86/domctl.c +3 -0
@@ -61,6 +61,9 @@ long arch_do_domctl(
         ret = paging_domctl(d,
                             &domctl->u.shadow_op,
                             guest_handle_cast(u_domctl, void));
+        if ( ret == -EAGAIN )
+            return hypercall_create_continuation(__HYPERVISOR_domctl,
+                                                 "h", u_domctl);
         copyback = 1;
     }
     break;
xen/arch/x86/mm/hap/hap.c +1 -2
@@ -572,8 +572,7 @@ int hap_domctl(struct domain *d, xen_dom
         paging_unlock(d);
         if ( preempted )
             /* Not finished.  Set up to re-run the call. */
-            rc = hypercall_create_continuation(__HYPERVISOR_domctl, "h",
-                                               u_domctl);
+            rc = -EAGAIN;
         else
             /* Finished.  Return the new allocation */
             sc->mb = hap_get_allocation(d);
xen/arch/x86/mm/paging.c +163 -36

342 lines not on this page · raw message

xen/arch/x86/mm/shadow/common.c +1 -2
@@ -3706,8 +3706,7 @@ int shadow_domctl(struct domain *d, 
         paging_unlock(d);
         if ( preempted )
             /* Not finished.  Set up to re-run the call. */
-            rc = hypercall_create_continuation(
-                __HYPERVISOR_domctl, "h", u_domctl);
+            rc = -EAGAIN;
         else 
             /* Finished.  Return the new allocation */
             sc->mb = shadow_get_allocation(d);
xen/common/domain.c +0 -1
@@ -536,7 +536,6 @@ int domain_kill(struct domain *d)
         rc = domain_relinquish_resources(d);
         if ( rc != 0 )
         {
-            BUG_ON(rc != -EAGAIN);
             break;
         }
         if ( sched_move_domain(d, cpupool0) )
xen/include/asm-x86/domain.h +14 -0
@@ -186,6 +186,20 @@ struct paging_domain {
     struct hap_domain       hap;
     /* log dirty support */
     struct log_dirty_domain log_dirty;
+
+    /* preemption handling */
+    struct {
+        struct vcpu *vcpu;
+        unsigned int op;
+        union {
+            struct {
+                unsigned long done:PADDR_BITS - PAGE_SHIFT;
+                unsigned long i4:PAGETABLE_ORDER;
+                unsigned long i3:PAGETABLE_ORDER;
+            } log_dirty;
+        };
+    } preempt;
+
     /* alloc/free pages from the pool for paging-assistance structures
      * (used by p2m and log-dirty code for their tries) */
     struct page_info * (*alloc_page)(struct domain *d);
xen/include/asm-x86/paging.h +1 -7
@@ -133,9 +133,6 @@ struct paging_mode {
 /*****************************************************************************
  * Log dirty code */
 
-/* free log dirty bitmap resource */
-void paging_free_log_dirty_bitmap(struct domain *d);
-
 /* get the dirty bitmap for a specific range of pfns */
 void paging_log_dirty_range(struct domain *d,
                             unsigned long begin_pfn,
@@ -145,9 +142,6 @@ void paging_log_dirty_range(struct domai
 /* enable log dirty */
 int paging_log_dirty_enable(struct domain *d, bool_t log_global);
 
-/* disable log dirty */
-int paging_log_dirty_disable(struct domain *d);
-
 /* log dirty initialization */
 void paging_log_dirty_init(struct domain *d,
                            int  (*enable_log_dirty)(struct domain *d,
@@ -207,7 +201,7 @@ int paging_domctl(struct domain *d, xen_
                   XEN_GUEST_HANDLE_PARAM(void) u_domctl);
 
 /* Call when destroying a domain */
-void paging_teardown(struct domain *d);
+int paging_teardown(struct domain *d);
 
 /* Call once all of the references to the domain have gone away */
 void paging_final_teardown(struct domain *d);

x86/paging: make log-dirty operations preemptible

Both the freeing and the inspection of the bitmap get done in (nested) loops which - besides having a rather high iteration count in general, albeit that would be covered by XSA-77 - have the number of non-trivial iterations they need to perform (indirectly) controllable by both the guest they are for and any domain controlling the guest (including the one running qemu for it).

This is XSA-97.

xen/arch/x86/domain.c +3 -1
@@ -1907,7 +1907,9 @@ int domain_relinquish_resources(struct d
         pci_release_devices(d);
 
         /* Tear down paging-assistance stuff. */
-        paging_teardown(d);
+        ret = paging_teardown(d);
+        if ( ret )
+            return ret;
 
         /* Drop the in-use references to page-table bases. */
         for_each_vcpu ( d, v )
xen/arch/x86/domctl.c +3 -0
@@ -64,6 +64,9 @@ long arch_do_domctl(
         ret = paging_domctl(d,
                             &domctl->u.shadow_op,
                             guest_handle_cast(u_domctl, void));
+        if ( ret == -ERESTART )
+            return hypercall_create_continuation(__HYPERVISOR_domctl,
+                                                 "h", u_domctl);
         copyback = 1;
     }
     break;
xen/arch/x86/mm/hap/hap.c +1 -2
@@ -582,8 +582,7 @@ int hap_domctl(struct domain *d, xen_dom
         paging_unlock(d);
         if ( preempted )
             /* Not finished.  Set up to re-run the call. */
-            rc = hypercall_create_continuation(__HYPERVISOR_domctl, "h",
-                                               u_domctl);
+            rc = -ERESTART;
         else
             /* Finished.  Return the new allocation */
             sc->mb = hap_get_allocation(d);
xen/arch/x86/mm/paging.c +162 -36

341 lines not on this page · raw message

xen/arch/x86/mm/shadow/common.c +1 -2
@@ -3705,8 +3705,7 @@ int shadow_domctl(struct domain *d, 
         paging_unlock(d);
         if ( preempted )
             /* Not finished.  Set up to re-run the call. */
-            rc = hypercall_create_continuation(
-                __HYPERVISOR_domctl, "h", u_domctl);
+            rc = -ERESTART;
         else 
             /* Finished.  Return the new allocation */
             sc->mb = shadow_get_allocation(d);
xen/common/domain.c +0 -1
@@ -611,7 +611,6 @@ int domain_kill(struct domain *d)
         {
             if ( rc == -ERESTART )
                 rc = -EAGAIN;
-            BUG_ON(rc != -EAGAIN);
             break;
         }
         if ( sched_move_domain(d, cpupool0) )
xen/include/asm-x86/domain.h +14 -0
@@ -186,6 +186,20 @@ struct paging_domain {
     struct hap_domain       hap;
     /* log dirty support */
     struct log_dirty_domain log_dirty;
+
+    /* preemption handling */
+    struct {
+        struct vcpu *vcpu;
+        unsigned int op;
+        union {
+            struct {
+                unsigned long done:PADDR_BITS - PAGE_SHIFT;
+                unsigned long i4:PAGETABLE_ORDER;
+                unsigned long i3:PAGETABLE_ORDER;
+            } log_dirty;
+        };
+    } preempt;
+
     /* alloc/free pages from the pool for paging-assistance structures
      * (used by p2m and log-dirty code for their tries) */
     struct page_info * (*alloc_page)(struct domain *d);
xen/include/asm-x86/paging.h +1 -7
@@ -132,9 +132,6 @@ struct paging_mode {
 /*****************************************************************************
  * Log dirty code */
 
-/* free log dirty bitmap resource */
-void paging_free_log_dirty_bitmap(struct domain *d);
-
 /* get the dirty bitmap for a specific range of pfns */
 void paging_log_dirty_range(struct domain *d,
                             unsigned long begin_pfn,
@@ -144,9 +141,6 @@ void paging_log_dirty_range(struct domai
 /* enable log dirty */
 int paging_log_dirty_enable(struct domain *d, bool_t log_global);
 
-/* disable log dirty */
-int paging_log_dirty_disable(struct domain *d);
-
 /* log dirty initialization */
 void paging_log_dirty_init(struct domain *d,
                            int  (*enable_log_dirty)(struct domain *d,
@@ -206,7 +200,7 @@ int paging_domctl(struct domain *d, xen_
                   XEN_GUEST_HANDLE_PARAM(void) u_domctl);
 
 /* Call when destroying a domain */
-void paging_teardown(struct domain *d);
+int paging_teardown(struct domain *d);
 
 /* Call once all of the references to the domain have gone away */
 void paging_final_teardown(struct domain *d);

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel