From: Andrew Cooper Date: Thu, 2 Mar 2017 18:01:00 +0000 (+0000) Subject: Alter selftest to test the SMEP/SMAP safety of exec_user() X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=4d06734fbb48879be65bab9fefda51dcb253541c;p=people%2Fandrewcoop%2Fxen-test-framework.git Alter selftest to test the SMEP/SMAP safety of exec_user() 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 --- diff --git a/include/xtf/compiler.h b/include/xtf/compiler.h index 1ab7fb9..9875b50 100644 --- a/include/xtf/compiler.h +++ b/include/xtf/compiler.h @@ -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__)) @@ -13,15 +17,12 @@ #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 */ /* diff --git a/tests/selftest/main.c b/tests/selftest/main.c index 749de61..0926731 100644 --- a/tests/selftest/main.c +++ b/tests/selftest/main.c @@ -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();