lkdtm: various improvements
cover lkdtm: various improvements
This series adds several new test targets that have been useful when testing various kernel crash conditions while working on Chrome OS, and corrects the CORRUPT_STACK trigger as well.
Thanks,
-Kees
PATCH 1/4 lkdtm: fix stack protector trigger
The -fstack-protector compiler flag will only build stack protections if a character array is seen. Additionally, the offset to the saved instruction pointer changes based on architecture, so stomp much harder (64 bytes) when corrupting the stack.
--- drivers/misc/lkdtm.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/misc/lkdtm.c +3 -3
@@ -295,10 +295,10 @@ static void lkdtm_do_action(enum ctype which) (void )recursive_loop (0 );break ;case CT_CORRUPT_STACK : { -volatile u32 data[8 ]; -volatile u32 *p = data; +/* Make sure the compiler creates and uses an 8 char array. */ +volatile char data[8 ]; - p[12 ] =0x12345678 ; +memset ((void *)data,0 ,64 );break ; }case CT_UNALIGNED_LOAD_STORE_WRITE : {
Signature · 1 line
1.7.9.5
Re: [PATCH 1/4] lkdtm: fix stack protector trigger
Hi,
I'd like to get this series added to lkdtm. Can someone take a moment to review or ack them?
Thanks,
-Kees
Quoted 31 lines · Kees Cook
The -fstack-protector compiler flag will only build stack protections if a character array is seen. Additionally, the offset to the saved instruction pointer changes based on architecture, so stomp much harder (64 bytes) when corrupting the stack.
Signed-off-by Kees Cook <[email protected]>--- drivers/misc/lkdtm.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)drivers/misc/lkdtm.c +3
-4@@ -295,10 +295,10 @@ static void lkdtm_do_action(enum ctype which) (void )recursive_loop (0 );break ;case CT_CORRUPT_STACK : { -volatile u32 data[8 ]; -volatile u32 *p = data; +/* Make sure the compiler creates and uses an 8 char array. */ +volatile char data[8 ]; - p[12 ] =0x12345678 ; +memset ((void *)data,0 ,64 );break ; }case CT_UNALIGNED_LOAD_STORE_WRITE : { --1.7.9.5
Signature · 2 lines
Kees Cook Chrome OS Security
Greg Kroah-Hartman
maintainerRe: [PATCH 1/4] lkdtm: fix stack protector trigger
Quoted 4 lines · Kees Cook
Hi,
I'd like to get this series added to lkdtm. Can someone take a moment to review or ack them?
I don't see these in my queue at all, did you copy me the first time around on them?
Care to resend them? Everything is on hold until 3.11-rc1 is out for new stuff like this, so you'll have to wait until then at the earliest.
thanks,
greg k-h
Re: [PATCH 1/4] lkdtm: fix stack protector trigger
Quoted 8 lines · Greg Kroah-Hartman
Quoted 4 lines · Kees Cook
Hi,
I'd like to get this series added to lkdtm. Can someone take a moment to review or ack them?
I don't see these in my queue at all, did you copy me the first time around on them?
Yup. June 22nd.
Quoted 2 lines
Care to resend them? Everything is on hold until 3.11-rc1 is out for new stuff like this, so you'll have to wait until then at the earliest.
Sure, no problem.
-Kees
--
Kees Cook
Chrome OS Security
PATCH 2/4 lkdtm: add "WARNING" trigger
In reply to Kees CookFor additional testing, add "WARNING" as a trigger that calls WARN_ON(1).
--- drivers/misc/lkdtm.c | 5 +++++ 1 file changed, 5 insertions(+)
drivers/misc/lkdtm.c +5 -0
@@ -68,6 +68,7 @@ enum ctype {CT_NONE ,CT_PANIC ,CT_BUG , +CT_WARNING ,CT_EXCEPTION ,CT_LOOP , CT_OVERFLOW,
@@ -95,6 +96,7 @@ static char* cp_name[] = {static char * cp_type[] = {"PANIC" ,"BUG" , +"WARNING" ,"EXCEPTION" ,"LOOP" ,"OVERFLOW" ,
@@ -284,6 +286,9 @@ static void lkdtm_do_action(enum ctype which)case CT_BUG :BUG ();break ; +case CT_WARNING : +WARN_ON (1 ); +break ;case CT_EXCEPTION : *((int *)0 ) =0 ;break ;
Signature · 1 line
1.7.9.5
PATCH 3/4 lkdtm: add "SPINLOCKUP" trigger
In reply to Kees CookFor additional lockup testing, add "SPINLOCKUP" to trigger a spinlock deadlock when triggered twice.
--- drivers/misc/lkdtm.c | 7 +++++++ 1 file changed, 7 insertions(+)
drivers/misc/lkdtm.c +7 -0
@@ -78,6 +78,7 @@ enum ctype {CT_WRITE_AFTER_FREE ,CT_SOFTLOCKUP ,CT_HARDLOCKUP , +CT_SPINLOCKUP , CT_HUNG_TASK, };
@@ -106,6 +107,7 @@ static char* cp_type[] = {"WRITE_AFTER_FREE" ,"SOFTLOCKUP" ,"HARDLOCKUP" , +"SPINLOCKUP" , "HUNG_TASK", };
@@ -123,6 +125,7 @@ static enum cname cpoint = CN_INVALID;static enum ctype cptype =CT_NONE ;static int count =DEFAULT_COUNT ;static DEFINE_SPINLOCK (count_lock); +static DEFINE_SPINLOCK (lock_me_up);module_param (recur_count, int,0644 ); MODULE_PARM_DESC(recur_count, " Recursion level for the stack overflow test, "\
@@ -345,6 +348,10 @@ static void lkdtm_do_action(enum ctype which)for (;;)cpu_relax ();break ; +case CT_SPINLOCKUP : +/* Must be called twice to trigger. */ +spin_lock (&lock_me_up); +break ;case CT_HUNG_TASK :set_current_state (TASK_UNINTERRUPTIBLE );schedule ();
Signature · 1 line
1.7.9.5
PATCH 4/4 lkdtm: add "EXEC_*" triggers
In reply to Kees CookAdd new crash locations that attempt to execute non-executable memory regions (data segment, stack, kmalloc, vmalloc).
--- drivers/misc/lkdtm.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+)
drivers/misc/lkdtm.c +44 -0
@@ -50,6 +50,7 @@#define DEFAULT_COUNT 10#define REC_NUM_DEFAULT 10 +#define EXEC_SIZE 64enum cname {CN_INVALID ,
@@ -80,6 +81,10 @@ enum ctype {CT_HARDLOCKUP ,CT_SPINLOCKUP ,CT_HUNG_TASK , +CT_EXEC_DATA , +CT_EXEC_STACK , +CT_EXEC_KMALLOC , + CT_EXEC_VMALLOC, }; static char* cp_name[] = {
@@ -109,6 +114,10 @@ static char* cp_type[] = {"HARDLOCKUP" ,"SPINLOCKUP" ,"HUNG_TASK" , +"EXEC_DATA" , +"EXEC_STACK" , +"EXEC_KMALLOC" , + "EXEC_VMALLOC", };static struct jprobe lkdtm;
@@ -127,6 +136,8 @@ static int count = DEFAULT_COUNT;static DEFINE_SPINLOCK (count_lock);static DEFINE_SPINLOCK (lock_me_up); +static u8 data_area[EXEC_SIZE ]; +module_param (recur_count, int,0644 );MODULE_PARM_DESC (recur_count," Recursion level for the stack overflow test, " \"default is 10" );
@@ -280,6 +291,19 @@ static int recursive_loop(int a)return recursive_loop (a); } +static void do_nothing (void ) +{ +return ; +} + +static void execute_location (void *dst) +{ +void (*func)(void ) = dst; + +memcpy (dst, do_nothing,EXEC_SIZE ); +func (); +} +static void lkdtm_do_action (enum ctype which) {switch (which) {
@@ -356,6 +380,26 @@ static void lkdtm_do_action(enum ctype which)set_current_state (TASK_UNINTERRUPTIBLE );schedule ();break ; +case CT_EXEC_DATA : +execute_location (data_area); +break ; +case CT_EXEC_STACK : { +u8 stack_area[EXEC_SIZE ]; +execute_location (stack_area); +break ; + } +case CT_EXEC_KMALLOC : { +u32 *kmalloc_area =kmalloc (EXEC_SIZE ,GFP_KERNEL ); +execute_location (kmalloc_area); +kfree (kmalloc_area); +break ; + } +case CT_EXEC_VMALLOC : { +u32 *vmalloc_area =vmalloc (EXEC_SIZE ); +execute_location (vmalloc_area); +vfree (vmalloc_area); +break ; + }case CT_NONE :default :break ;
Signature · 1 line
1.7.9.5