]> xenbits.xensource.com Git - people/royger/xen-test-framework.git/commitdiff
Unmap the page at 0 to catch errors with NULL pointers
authorAndrew Cooper <andrew.cooper3@citrix.com>
Fri, 8 Jan 2016 17:44:13 +0000 (17:44 +0000)
committerAndrew Cooper <andrew.cooper3@citrix.com>
Fri, 8 Jan 2016 17:46:10 +0000 (17:46 +0000)
Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
arch/x86/hvm_pagetables.S
arch/x86/pv/traps.c
tests/selftest/main.c

index b929e2404696056757c4a7862a91229f3b377623..0e078e02b76a466ec250d36b7b7d50d59dab2fca 100644 (file)
@@ -5,9 +5,20 @@
         .data
         .p2align PAGE_SHIFT
 
-/* Mapping of first 4G of memory in 2M superpages. Uses 4x 4k pages. */
+/* Mapping of first 2M of memory in 4k pages. Uses 1x 4k page. */
+GLOBAL(l1_identmap)
+        .long 0, 0 /* Unmap page at 0 to catch errors with NULL pointers. */
+        .rept L1_PT_ENTRIES - 1
+        .long (((. - l1_identmap) / 8) << (PAGE_ORDER_4K + PAGE_SHIFT)) + \
+              _PAGE_USER + _PAGE_RW + _PAGE_PRESENT
+        .long 0
+        .endr
+
+/* Mappings up to 4G in 2M superpages. Uses 4x 4k pages. */
 GLOBAL(l2_identmap)
-        .rept (4 * L2_PT_ENTRIES)
+        .long l1_identmap + _PAGE_USER + _PAGE_RW + _PAGE_PRESENT
+        .long 0
+        .rept (4 * L2_PT_ENTRIES) - 1
         .long (((. - l2_identmap) / 8) << (PAGE_ORDER_2M + PAGE_SHIFT)) + \
               _PAGE_PSE + _PAGE_USER + _PAGE_RW + _PAGE_PRESENT
         .long 0
index 51c2ec93b3782da4b68dab6a59e2e034699ec338..7f9a1908d260659c10f5cbb1d2d234c9fea1edb5 100644 (file)
@@ -73,6 +73,11 @@ void arch_init_traps(void)
     write_fs(__USER_DS);
     write_gs(__USER_DS);
 
+    /* Unmap page at 0 to catch errors with NULL pointers. */
+    rc = hypercall_update_va_mapping(NULL, 0, 2);
+    if ( rc )
+        panic("Failed to unmap page at NULL: %d\n", rc);
+
 #ifdef __x86_64__
     /*
      * Set the user pagetables (only applicable to 64bit PV).
index 45eb3bc147109072c4874928f186a347434470e0..adae1dea3aeb44a062a5d102db3e95bc218ce439 100644 (file)
@@ -169,6 +169,27 @@ static void test_exec_user(void)
     }
 }
 
+static void test_NULL_unmapped(void)
+{
+    extern unsigned long label_test_NULL_unmapped[];
+    unsigned long tmp;
+
+    printk("Test: NULL unmapped\n");
+
+    xtf_exlog_start();
+
+    asm volatile ("label_test_NULL_unmapped: mov 0, %0; 2:"
+                  _ASM_EXTABLE(label_test_NULL_unmapped, 2b)
+                  : "=q" (tmp) :: "memory");
+
+    if ( check_nr_entries(1) )
+        check_exlog_entry(0, __KERN_CS,
+                          (unsigned long)&label_test_NULL_unmapped,
+                          X86_EXC_PF, 0);
+
+    xtf_exlog_stop();
+}
+
 void test_main(void)
 {
     printk("XTF Selftests\n");
@@ -177,6 +198,7 @@ void test_main(void)
     test_extable();
     test_exlog();
     test_exec_user();
+    test_NULL_unmapped();
 
     xtf_success();
 }