]> xenbits.xensource.com Git - people/andrewcoop/xen-test-framework.git/commitdiff
Alter selftest to test the SMEP/SMAP safety of exec_user()
authorAndrew Cooper <andrew.cooper3@citrix.com>
Thu, 2 Mar 2017 18:01:00 +0000 (18:01 +0000)
committerAndrew Cooper <andrew.cooper3@citrix.com>
Mon, 6 Mar 2017 10:55:41 +0000 (10:55 +0000)
Drop the test_wants_user_mappings setting and place test_exec_user_cpl3() in
.text.user.  Enable CR4.{SMEP,SMAP} whenever available.

While adding __section(s) to compiler.h, take the opportunity to clean it up.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
include/xtf/compiler.h
tests/selftest/main.c

index 1ab7fb91d20ccfb0f750b4d95806da295a94ab26..9875b50960a0a6c586fe1dbf89bf5850eb2eaa08 100644 (file)
@@ -2,8 +2,12 @@
 #define XTF_COMPILER_H
 
 #define __aligned(x)          __attribute__((__aligned__(x)))
+#define __noreturn            __attribute__((__noreturn__))
 #define __packed              __attribute__((__packed__))
+#define __printf(f, v)        __attribute__((__format__(__printf__, f, v)))
+#define __section(s)          __attribute__((__section__(s)))
 #define __used                __attribute__((__used__))
+#define __weak                __attribute__((__weak__))
 
 #ifndef __noinline /* Avoid conflicting with cdefs.h */
 #define __noinline            __attribute__((__noinline__))
 #define __always_inline       __attribute__((__always_inline__))
 #endif
 
-#define __weak                __attribute__((weak))
-
-#define __noreturn            __attribute__((__noreturn__))
 #define unreachable()         __builtin_unreachable()
-
-#define __printf(f, v)        __attribute__((__format__(__printf__, f, v)))
-
 #define barrier()             __asm__ __volatile__ ("" ::: "memory")
 
+/* Convenience wrappers. */
+#define __user_text           __section(".text.user")
+
 #endif /* XTF_COMPILER_H */
 
 /*
index 749de61c361464485042dce1efcfc1b42e889466..0926731329c6256541b5148a5a0fc95b2d945e9c 100644 (file)
@@ -17,8 +17,6 @@
 
 const char test_title[] = "XTF Selftests";
 
-bool test_wants_user_mappings = true;
-
 static void test_int3_breakpoint(void)
 {
     printk("Test: int3 breakpoint\n");
@@ -147,7 +145,7 @@ enum {
     USER_bad_cs,
 };
 
-static unsigned long test_exec_user_cpl3(void)
+static unsigned long __user_text test_exec_user_cpl3(void)
 {
     return ((read_cs() & 3) == 3) ? USER_seen : USER_bad_cs;
 }
@@ -293,6 +291,23 @@ static void test_custom_idte(void)
 
 void test_main(void)
 {
+    /*
+     * Wherever possible, enable SMEP and SMAP to test the safety of the
+     * exec_user infrastructure.
+     */
+    if ( IS_DEFINED(CONFIG_HVM) )
+    {
+        unsigned long cr4 = read_cr4(), ocr4 = cr4;
+
+        if ( cpu_has_smep )
+            cr4 |= X86_CR4_SMEP;
+        if ( cpu_has_smap )
+            cr4 |= X86_CR4_SMAP;
+
+        if ( cr4 != ocr4 )
+            write_cr4(cr4);
+    }
+
     test_int3_breakpoint();
     test_extable();
     test_exlog();