aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKees Cook <keescook@chromium.org>2013-10-24 12:25:39 -0400
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2013-10-29 19:13:39 -0400
commit7d196ac303652588c60350f0a581d71e2e7b1a50 (patch)
tree5bcda7cfe5cdb498abf5ac3c9cbe81ee75bc6813
parent629c66a22c21b692b6e58b9c1d8fa56a60ccb52d (diff)
lkdtm: adjust recursion size to avoid warnings
When CONFIG_FRAME_WARN is set low (e.g. some ARM builds), the hard-coded stack buffer size used for kernel stack over run testing triggers build warnings. Instead, avoid the warning by recalcuating the buffer size and recursion count needed to trigger the test. Also uses the recursion counter indirectly to avoid changing the parameter during the test. Signed-off-by: Kees Cook <keescook@chromium.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
-rw-r--r--drivers/misc/lkdtm.c30
1 files changed, 20 insertions, 10 deletions
diff --git a/drivers/misc/lkdtm.c b/drivers/misc/lkdtm.c
index 9cbd0370ca44..482344242f94 100644
--- a/drivers/misc/lkdtm.c
+++ b/drivers/misc/lkdtm.c
@@ -49,8 +49,19 @@
49#include <linux/ide.h> 49#include <linux/ide.h>
50#endif 50#endif
51 51
52/*
53 * Make sure our attempts to over run the kernel stack doesn't trigger
54 * a compiler warning when CONFIG_FRAME_WARN is set. Then make sure we
55 * recurse past the end of THREAD_SIZE by default.
56 */
57#if defined(CONFIG_FRAME_WARN) && (CONFIG_FRAME_WARN > 0)
58#define REC_STACK_SIZE (CONFIG_FRAME_WARN / 2)
59#else
60#define REC_STACK_SIZE (THREAD_SIZE / 8)
61#endif
62#define REC_NUM_DEFAULT ((THREAD_SIZE / REC_STACK_SIZE) * 2)
63
52#define DEFAULT_COUNT 10 64#define DEFAULT_COUNT 10
53#define REC_NUM_DEFAULT 10
54#define EXEC_SIZE 64 65#define EXEC_SIZE 64
55 66
56enum cname { 67enum cname {
@@ -140,8 +151,7 @@ static DEFINE_SPINLOCK(lock_me_up);
140static u8 data_area[EXEC_SIZE]; 151static u8 data_area[EXEC_SIZE];
141 152
142module_param(recur_count, int, 0644); 153module_param(recur_count, int, 0644);
143MODULE_PARM_DESC(recur_count, " Recursion level for the stack overflow test, "\ 154MODULE_PARM_DESC(recur_count, " Recursion level for the stack overflow test");
144 "default is 10");
145module_param(cpoint_name, charp, 0444); 155module_param(cpoint_name, charp, 0444);
146MODULE_PARM_DESC(cpoint_name, " Crash Point, where kernel is to be crashed"); 156MODULE_PARM_DESC(cpoint_name, " Crash Point, where kernel is to be crashed");
147module_param(cpoint_type, charp, 0444); 157module_param(cpoint_type, charp, 0444);
@@ -280,16 +290,16 @@ static int lkdtm_parse_commandline(void)
280 return -EINVAL; 290 return -EINVAL;
281} 291}
282 292
283static int recursive_loop(int a) 293static int recursive_loop(int remaining)
284{ 294{
285 char buf[1024]; 295 char buf[REC_STACK_SIZE];
286 296
287 memset(buf,0xFF,1024); 297 /* Make sure compiler does not optimize this away. */
288 recur_count--; 298 memset(buf, (remaining & 0xff) | 0x1, REC_STACK_SIZE);
289 if (!recur_count) 299 if (!remaining)
290 return 0; 300 return 0;
291 else 301 else
292 return recursive_loop(a); 302 return recursive_loop(remaining - 1);
293} 303}
294 304
295static void do_nothing(void) 305static void do_nothing(void)
@@ -333,7 +343,7 @@ static void lkdtm_do_action(enum ctype which)
333 ; 343 ;
334 break; 344 break;
335 case CT_OVERFLOW: 345 case CT_OVERFLOW:
336 (void) recursive_loop(0); 346 (void) recursive_loop(recur_count);
337 break; 347 break;
338 case CT_CORRUPT_STACK: 348 case CT_CORRUPT_STACK:
339 corrupt_stack(); 349 corrupt_stack();