aboutsummaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
Diffstat (limited to 'tools')
-rw-r--r--tools/testing/selftests/x86/protection_keys.c21
1 files changed, 17 insertions, 4 deletions
diff --git a/tools/testing/selftests/x86/protection_keys.c b/tools/testing/selftests/x86/protection_keys.c
index 7d95acd2aec3..083ebd51b44e 100644
--- a/tools/testing/selftests/x86/protection_keys.c
+++ b/tools/testing/selftests/x86/protection_keys.c
@@ -1253,12 +1253,9 @@ void test_ptrace_of_child(int *ptr, u16 pkey)
1253 free(plain_ptr_unaligned); 1253 free(plain_ptr_unaligned);
1254} 1254}
1255 1255
1256void test_executing_on_unreadable_memory(int *ptr, u16 pkey) 1256void *get_pointer_to_instructions(void)
1257{ 1257{
1258 void *p1; 1258 void *p1;
1259 int scratch;
1260 int ptr_contents;
1261 int ret;
1262 1259
1263 p1 = ALIGN_PTR_UP(&lots_o_noops_around_write, PAGE_SIZE); 1260 p1 = ALIGN_PTR_UP(&lots_o_noops_around_write, PAGE_SIZE);
1264 dprintf3("&lots_o_noops: %p\n", &lots_o_noops_around_write); 1261 dprintf3("&lots_o_noops: %p\n", &lots_o_noops_around_write);
@@ -1268,7 +1265,23 @@ void test_executing_on_unreadable_memory(int *ptr, u16 pkey)
1268 /* Point 'p1' at the *second* page of the function: */ 1265 /* Point 'p1' at the *second* page of the function: */
1269 p1 += PAGE_SIZE; 1266 p1 += PAGE_SIZE;
1270 1267
1268 /*
1269 * Try to ensure we fault this in on next touch to ensure
1270 * we get an instruction fault as opposed to a data one
1271 */
1271 madvise(p1, PAGE_SIZE, MADV_DONTNEED); 1272 madvise(p1, PAGE_SIZE, MADV_DONTNEED);
1273
1274 return p1;
1275}
1276
1277void test_executing_on_unreadable_memory(int *ptr, u16 pkey)
1278{
1279 void *p1;
1280 int scratch;
1281 int ptr_contents;
1282 int ret;
1283
1284 p1 = get_pointer_to_instructions();
1272 lots_o_noops_around_write(&scratch); 1285 lots_o_noops_around_write(&scratch);
1273 ptr_contents = read_ptr(p1); 1286 ptr_contents = read_ptr(p1);
1274 dprintf2("ptr (%p) contents@%d: %x\n", p1, __LINE__, ptr_contents); 1287 dprintf2("ptr (%p) contents@%d: %x\n", p1, __LINE__, ptr_contents);