]> xenbits.xensource.com Git - xen.git/commitdiff
x86/grant: disallow misaligned PTEs
authorAndrew Cooper <andrew.cooper3@citrix.com>
Tue, 15 Aug 2017 13:33:09 +0000 (15:33 +0200)
committerJan Beulich <jbeulich@suse.com>
Tue, 15 Aug 2017 13:33:09 +0000 (15:33 +0200)
Pagetable entries must be aligned to function correctly.  Disallow attempts
from the guest to have a grant PTE created at a misaligned address, which
would result in corruption of the L1 table with largely-guest-controlled
values.

This is CVE-2017-12137 / XSA-227.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
master commit: ce442926c2530da9376199dcc769436376ad2386
master date: 2017-08-15 15:06:45 +0200

xen/arch/x86/mm.c
xen/include/xen/config.h

index 70bf52f60a141e2788c79e678fd3bc3a54369d53..70dfec5af1842afd1ef251b84378a27fae1369bb 100644 (file)
@@ -3781,6 +3781,9 @@ static int create_grant_pte_mapping(
     l1_pgentry_t ol1e;
     struct domain *d = v->domain;
 
+    if ( !IS_ALIGNED(pte_addr, sizeof(nl1e)) )
+        return GNTST_general_error;
+
     adjust_guest_l1e(nl1e, d);
 
     gmfn = pte_addr >> PAGE_SHIFT;
@@ -3838,6 +3841,16 @@ static int destroy_grant_pte_mapping(
     struct page_info *page;
     l1_pgentry_t ol1e;
 
+    /*
+     * addr comes from Xen's active_entry tracking so isn't guest controlled,
+     * but it had still better be PTE-aligned.
+     */
+    if ( !IS_ALIGNED(addr, sizeof(ol1e)) )
+    {
+        ASSERT_UNREACHABLE();
+        return GNTST_general_error;
+    }
+
     gmfn = addr >> PAGE_SHIFT;
     page = get_page_from_gfn(d, gmfn, NULL, P2M_ALLOC);
 
index 7bef8a648df2db5115ace93d4488492c30eca3ec..a3aa1d483231f3042574025656d089e0e9ad3ea8 100644 (file)
@@ -82,6 +82,8 @@
 
 #endif /* !__ASSEMBLY__ */
 
+#define IS_ALIGNED(val, align) (((val) & ((align) - 1)) == 0)
+
 #define __STR(...) #__VA_ARGS__
 #define STR(...) __STR(__VA_ARGS__)