lkdtm/heap: Add vmalloc linear overflow test
[linux-2.6-microblaze.git] / drivers / misc / lkdtm / heap.c
index 1323bc1..36be5e3 100644 (file)
@@ -5,24 +5,44 @@
  */
 #include "lkdtm.h"
 #include <linux/slab.h>
+#include <linux/vmalloc.h>
 #include <linux/sched.h>
 
 static struct kmem_cache *double_free_cache;
 static struct kmem_cache *a_cache;
 static struct kmem_cache *b_cache;
 
+/*
+ * If there aren't guard pages, it's likely that a consecutive allocation will
+ * let us overflow into the second allocation without overwriting something real.
+ */
+void lkdtm_VMALLOC_LINEAR_OVERFLOW(void)
+{
+       char *one, *two;
+
+       one = vzalloc(PAGE_SIZE);
+       two = vzalloc(PAGE_SIZE);
+
+       pr_info("Attempting vmalloc linear overflow ...\n");
+       memset(one, 0xAA, PAGE_SIZE + 1);
+
+       vfree(two);
+       vfree(one);
+}
+
 /*
  * This tries to stay within the next largest power-of-2 kmalloc cache
  * to avoid actually overwriting anything important if it's not detected
  * correctly.
  */
-void lkdtm_OVERWRITE_ALLOCATION(void)
+void lkdtm_SLAB_LINEAR_OVERFLOW(void)
 {
        size_t len = 1020;
        u32 *data = kmalloc(len, GFP_KERNEL);
        if (!data)
                return;
 
+       pr_info("Attempting slab linear overflow ...\n");
        data[1024 / sizeof(u32)] = 0x12345678;
        kfree(data);
 }