Skip to content

Commit aac416f

Browse files
keesgregkh
authored andcommitted
lkdtm: flush icache and report actions
Some CPUs explicitly need to have their icache flushed after making executable code copies for the memory region execution tests. Additionally, report the specific address targets being used so that debugging non-crash failures is easier. Signed-off-by: Kees Cook <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent feac6e2 commit aac416f

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

drivers/misc/lkdtm.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,12 @@ static void execute_location(void *dst)
329329
{
330330
void (*func)(void) = dst;
331331

332+
pr_info("attempting ok execution at %p\n", do_nothing);
333+
do_nothing();
334+
332335
memcpy(dst, do_nothing, EXEC_SIZE);
336+
flush_icache_range((unsigned long)dst, (unsigned long)dst + EXEC_SIZE);
337+
pr_info("attempting bad execution at %p\n", func);
333338
func();
334339
}
335340

@@ -338,8 +343,13 @@ static void execute_user_location(void *dst)
338343
/* Intentionally crossing kernel/user memory boundary. */
339344
void (*func)(void) = dst;
340345

346+
pr_info("attempting ok execution at %p\n", do_nothing);
347+
do_nothing();
348+
341349
if (copy_to_user((void __user *)dst, do_nothing, EXEC_SIZE))
342350
return;
351+
flush_icache_range((unsigned long)dst, (unsigned long)dst + EXEC_SIZE);
352+
pr_info("attempting bad execution at %p\n", func);
343353
func();
344354
}
345355

@@ -464,8 +474,12 @@ static void lkdtm_do_action(enum ctype which)
464474
}
465475

466476
ptr = (unsigned long *)user_addr;
477+
478+
pr_info("attempting bad read at %p\n", ptr);
467479
tmp = *ptr;
468480
tmp += 0xc0dec0de;
481+
482+
pr_info("attempting bad write at %p\n", ptr);
469483
*ptr = tmp;
470484

471485
vm_munmap(user_addr, PAGE_SIZE);
@@ -476,6 +490,8 @@ static void lkdtm_do_action(enum ctype which)
476490
unsigned long *ptr;
477491

478492
ptr = (unsigned long *)&rodata;
493+
494+
pr_info("attempting bad write at %p\n", ptr);
479495
*ptr ^= 0xabcd1234;
480496

481497
break;

0 commit comments

Comments
 (0)