aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/misc
diff options
context:
space:
mode:
authorKees Cook <keescook@chromium.org>2013-10-24 12:25:57 -0400
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2013-10-29 19:13:39 -0400
commit9ae113ce5faf1c74af1ee71b5ef7d04b6b06b063 (patch)
treec7f16f731cc9c04f6cc33ff2afd17e662de3088e /drivers/misc
parent7d196ac303652588c60350f0a581d71e2e7b1a50 (diff)
lkdtm: add tests for additional page permissions
Testing execution and access of userspace from the kernel is needed for validating things like Intel's SMEP and SMAP protections. Additionally, add an explicit test for validating that RO page permissions have been set for the RO data area. Signed-off-by: Kees Cook <keescook@chromium.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers/misc')
-rw-r--r--drivers/misc/lkdtm.c61
1 files changed, 61 insertions, 0 deletions
diff --git a/drivers/misc/lkdtm.c b/drivers/misc/lkdtm.c
index 482344242f94..a2edb2ee0921 100644
--- a/drivers/misc/lkdtm.c
+++ b/drivers/misc/lkdtm.c
@@ -44,6 +44,7 @@
44#include <scsi/scsi_cmnd.h> 44#include <scsi/scsi_cmnd.h>
45#include <linux/debugfs.h> 45#include <linux/debugfs.h>
46#include <linux/vmalloc.h> 46#include <linux/vmalloc.h>
47#include <linux/mman.h>
47 48
48#ifdef CONFIG_IDE 49#ifdef CONFIG_IDE
49#include <linux/ide.h> 50#include <linux/ide.h>
@@ -97,6 +98,9 @@ enum ctype {
97 CT_EXEC_STACK, 98 CT_EXEC_STACK,
98 CT_EXEC_KMALLOC, 99 CT_EXEC_KMALLOC,
99 CT_EXEC_VMALLOC, 100 CT_EXEC_VMALLOC,
101 CT_EXEC_USERSPACE,
102 CT_ACCESS_USERSPACE,
103 CT_WRITE_RO,
100}; 104};
101 105
102static char* cp_name[] = { 106static char* cp_name[] = {
@@ -130,6 +134,9 @@ static char* cp_type[] = {
130 "EXEC_STACK", 134 "EXEC_STACK",
131 "EXEC_KMALLOC", 135 "EXEC_KMALLOC",
132 "EXEC_VMALLOC", 136 "EXEC_VMALLOC",
137 "EXEC_USERSPACE",
138 "ACCESS_USERSPACE",
139 "WRITE_RO",
133}; 140};
134 141
135static struct jprobe lkdtm; 142static struct jprobe lkdtm;
@@ -150,6 +157,8 @@ static DEFINE_SPINLOCK(lock_me_up);
150 157
151static u8 data_area[EXEC_SIZE]; 158static u8 data_area[EXEC_SIZE];
152 159
160static const unsigned long rodata = 0xAA55AA55;
161
153module_param(recur_count, int, 0644); 162module_param(recur_count, int, 0644);
154MODULE_PARM_DESC(recur_count, " Recursion level for the stack overflow test"); 163MODULE_PARM_DESC(recur_count, " Recursion level for the stack overflow test");
155module_param(cpoint_name, charp, 0444); 164module_param(cpoint_name, charp, 0444);
@@ -323,6 +332,15 @@ static void execute_location(void *dst)
323 func(); 332 func();
324} 333}
325 334
335static void execute_user_location(void *dst)
336{
337 void (*func)(void) = dst;
338
339 if (copy_to_user(dst, do_nothing, EXEC_SIZE))
340 return;
341 func();
342}
343
326static void lkdtm_do_action(enum ctype which) 344static void lkdtm_do_action(enum ctype which)
327{ 345{
328 switch (which) { 346 switch (which) {
@@ -415,6 +433,49 @@ static void lkdtm_do_action(enum ctype which)
415 vfree(vmalloc_area); 433 vfree(vmalloc_area);
416 break; 434 break;
417 } 435 }
436 case CT_EXEC_USERSPACE: {
437 unsigned long user_addr;
438
439 user_addr = vm_mmap(NULL, 0, PAGE_SIZE,
440 PROT_READ | PROT_WRITE | PROT_EXEC,
441 MAP_ANONYMOUS | MAP_PRIVATE, 0);
442 if (user_addr >= TASK_SIZE) {
443 pr_warn("Failed to allocate user memory\n");
444 return;
445 }
446 execute_user_location((void *)user_addr);
447 vm_munmap(user_addr, PAGE_SIZE);
448 break;
449 }
450 case CT_ACCESS_USERSPACE: {
451 unsigned long user_addr, tmp;
452 unsigned long *ptr;
453
454 user_addr = vm_mmap(NULL, 0, PAGE_SIZE,
455 PROT_READ | PROT_WRITE | PROT_EXEC,
456 MAP_ANONYMOUS | MAP_PRIVATE, 0);
457 if (user_addr >= TASK_SIZE) {
458 pr_warn("Failed to allocate user memory\n");
459 return;
460 }
461
462 ptr = (unsigned long *)user_addr;
463 tmp = *ptr;
464 tmp += 0xc0dec0de;
465 *ptr = tmp;
466
467 vm_munmap(user_addr, PAGE_SIZE);
468
469 break;
470 }
471 case CT_WRITE_RO: {
472 unsigned long *ptr;
473
474 ptr = (unsigned long *)&rodata;
475 *ptr ^= 0xabcd1234;
476
477 break;
478 }
418 case CT_NONE: 479 case CT_NONE:
419 default: 480 default:
420 break; 481 break;