aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKees Cook <keescook@chromium.org>2016-06-26 11:51:14 -0400
committerKees Cook <keescook@chromium.org>2016-07-07 14:09:20 -0400
commit0edca7b5afb4b0909eecd2ede9a6736ef7cafc42 (patch)
tree4646c4bc53eddb1ce8be1c72ef88ba9b166e3a17
parent6c3521400c345fa2575a6f5b212c215db38c5d93 (diff)
lkdtm: drop "alloc_size" parameter
There is no good reason to have the alloc_size parameter currently. The compiler-tricking value used to exercise the stack can just use a stack address instead. Similarly hard-code cache_size. Signed-off-by: Kees Cook <keescook@chromium.org>
-rw-r--r--drivers/misc/lkdtm_core.c15
1 files changed, 5 insertions, 10 deletions
diff --git a/drivers/misc/lkdtm_core.c b/drivers/misc/lkdtm_core.c
index c915961c4df2..1454d58aa278 100644
--- a/drivers/misc/lkdtm_core.c
+++ b/drivers/misc/lkdtm_core.c
@@ -184,8 +184,6 @@ static char* cpoint_name;
184static char* cpoint_type; 184static char* cpoint_type;
185static int cpoint_count = DEFAULT_COUNT; 185static int cpoint_count = DEFAULT_COUNT;
186static int recur_count = REC_NUM_DEFAULT; 186static int recur_count = REC_NUM_DEFAULT;
187static int alloc_size = 1024;
188static size_t cache_size;
189 187
190static enum cname cpoint = CN_INVALID; 188static enum cname cpoint = CN_INVALID;
191static enum ctype cptype = CT_NONE; 189static enum ctype cptype = CT_NONE;
@@ -194,6 +192,8 @@ static DEFINE_SPINLOCK(count_lock);
194static DEFINE_SPINLOCK(lock_me_up); 192static DEFINE_SPINLOCK(lock_me_up);
195 193
196static u8 data_area[EXEC_SIZE]; 194static u8 data_area[EXEC_SIZE];
195
196static size_t cache_size = 1024;
197static struct kmem_cache *bad_cache; 197static struct kmem_cache *bad_cache;
198 198
199static const unsigned char test_text[] = "This is a test.\n"; 199static const unsigned char test_text[] = "This is a test.\n";
@@ -210,9 +210,6 @@ MODULE_PARM_DESC(cpoint_type, " Crash Point Type, action to be taken on "\
210module_param(cpoint_count, int, 0644); 210module_param(cpoint_count, int, 0644);
211MODULE_PARM_DESC(cpoint_count, " Crash Point Count, number of times the "\ 211MODULE_PARM_DESC(cpoint_count, " Crash Point Count, number of times the "\
212 "crash point is to be hit to trigger action"); 212 "crash point is to be hit to trigger action");
213module_param(alloc_size, int, 0644);
214MODULE_PARM_DESC(alloc_size, " Size of allocation for user copy tests "\
215 "(from 1 to PAGE_SIZE)");
216 213
217static unsigned int jp_do_irq(unsigned int irq) 214static unsigned int jp_do_irq(unsigned int irq)
218{ 215{
@@ -441,7 +438,7 @@ static noinline void do_usercopy_stack(bool to_user, bool bad_frame)
441 438
442 /* This is a pointer to outside our current stack frame. */ 439 /* This is a pointer to outside our current stack frame. */
443 if (bad_frame) { 440 if (bad_frame) {
444 bad_stack = do_usercopy_stack_callee(alloc_size); 441 bad_stack = do_usercopy_stack_callee((uintptr_t)bad_stack);
445 } else { 442 } else {
446 /* Put start address just inside stack. */ 443 /* Put start address just inside stack. */
447 bad_stack = task_stack_page(current) + THREAD_SIZE; 444 bad_stack = task_stack_page(current) + THREAD_SIZE;
@@ -530,7 +527,7 @@ static void do_usercopy_heap_size(bool to_user)
530{ 527{
531 unsigned long user_addr; 528 unsigned long user_addr;
532 unsigned char *one, *two; 529 unsigned char *one, *two;
533 size_t size = clamp_t(int, alloc_size, 1, PAGE_SIZE); 530 size_t size = 1024;
534 531
535 one = kmalloc(size, GFP_KERNEL); 532 one = kmalloc(size, GFP_KERNEL);
536 two = kmalloc(size, GFP_KERNEL); 533 two = kmalloc(size, GFP_KERNEL);
@@ -564,8 +561,7 @@ static void do_usercopy_heap_size(bool to_user)
564 } 561 }
565 } else { 562 } else {
566 pr_info("attempting good copy_from_user of correct size\n"); 563 pr_info("attempting good copy_from_user of correct size\n");
567 if (copy_from_user(one, (void __user *)user_addr, 564 if (copy_from_user(one, (void __user *)user_addr, size)) {
568 size)) {
569 pr_warn("copy_from_user failed unexpectedly?!\n"); 565 pr_warn("copy_from_user failed unexpectedly?!\n");
570 goto free_user; 566 goto free_user;
571 } 567 }
@@ -1284,7 +1280,6 @@ static int __init lkdtm_module_init(void)
1284 ro_after_init |= 0xAA; 1280 ro_after_init |= 0xAA;
1285 1281
1286 /* Prepare cache that lacks SLAB_USERCOPY flag. */ 1282 /* Prepare cache that lacks SLAB_USERCOPY flag. */
1287 cache_size = clamp_t(int, alloc_size, 1, PAGE_SIZE);
1288 bad_cache = kmem_cache_create("lkdtm-no-usercopy", cache_size, 0, 1283 bad_cache = kmem_cache_create("lkdtm-no-usercopy", cache_size, 0,
1289 0, NULL); 1284 0, NULL);
1290 1285