summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLaura Abbott <labbott@fedoraproject.org>2016-02-25 19:36:43 -0500
committerKees Cook <keescook@chromium.org>2016-03-01 17:29:13 -0500
commit250a8988ef4071d8b7cdbb27388f09f33402293a (patch)
tree44943637efcbf5405da8308fd5effe77a4e740de
parentbc0b8cc6cb26a209fa1679d5c063b47bc0afe964 (diff)
lkdtm: Update WRITE_AFTER_FREE test
The SLUB allocator may use the first word of a freed block to store the freelist information. This may make it harder to test poisoning features. Change the WRITE_AFTER_FREE test to better match what the READ_AFTER_FREE test does and also print out a big more information. Signed-off-by: Laura Abbott <labbott@fedoraproject.org> Signed-off-by: Kees Cook <keescook@chromium.org>
-rw-r--r--drivers/misc/lkdtm.c17
1 files changed, 13 insertions, 4 deletions
diff --git a/drivers/misc/lkdtm.c b/drivers/misc/lkdtm.c
index 8de47462638a..a00a2b11b821 100644
--- a/drivers/misc/lkdtm.c
+++ b/drivers/misc/lkdtm.c
@@ -411,12 +411,21 @@ static void lkdtm_do_action(enum ctype which)
411 break; 411 break;
412 } 412 }
413 case CT_WRITE_AFTER_FREE: { 413 case CT_WRITE_AFTER_FREE: {
414 int *base;
414 size_t len = 1024; 415 size_t len = 1024;
415 u32 *data = kmalloc(len, GFP_KERNEL); 416 /*
417 * The slub allocator uses the first word to store the free
418 * pointer in some configurations. Use the middle of the
419 * allocation to avoid running into the freelist
420 */
421 size_t offset = (len / sizeof(*base)) / 2;
416 422
417 kfree(data); 423 base = kmalloc(len, GFP_KERNEL);
418 schedule(); 424 pr_info("Allocated memory %p-%p\n", base, &base[offset * 2]);
419 memset(data, 0x78, len); 425 kfree(base);
426 pr_info("Attempting bad write to freed memory at %p\n",
427 &base[offset]);
428 base[offset] = 0x0abcdef0;
420 break; 429 break;
421 } 430 }
422 case CT_READ_AFTER_FREE: { 431 case CT_READ_AFTER_FREE: {