Merge tag 'v4.9.214' of git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux...
[platform/kernel/linux-amlogic.git] / lib / test_kasan.c
index 6e76a44..c0b65e0 100644 (file)
@@ -19,6 +19,7 @@
 #include <linux/string.h>
 #include <linux/uaccess.h>
 #include <linux/module.h>
+#include <linux/kasan.h>
 
 /*
  * Note: test functions are marked noinline so that their names appear in
@@ -440,8 +441,34 @@ static noinline void __init use_after_scope_test(void)
        p[1023] = 1;
 }
 
+static noinline void __init kasan_alloca_oob_left(void)
+{
+       volatile int i = 10;
+       char alloca_array[i];
+       char *p = alloca_array - 1;
+
+       pr_info("out-of-bounds to left on alloca\n");
+       *(volatile char *)p;
+}
+
+static noinline void __init kasan_alloca_oob_right(void)
+{
+       volatile int i = 10;
+       char alloca_array[i];
+       char *p = alloca_array + i;
+
+       pr_info("out-of-bounds to right on alloca\n");
+       *(volatile char *)p;
+}
+
 static int __init kmalloc_tests_init(void)
 {
+       /*
+        * Temporarily enable multi-shot mode. Otherwise, we'd only get a
+        * report for the first case.
+        */
+       bool multishot = kasan_save_enable_multi_shot();
+
        kmalloc_oob_right();
        kmalloc_oob_left();
        kmalloc_node_oob_right();
@@ -463,9 +490,14 @@ static int __init kmalloc_tests_init(void)
        kmem_cache_oob();
        kasan_stack_oob();
        kasan_global_oob();
+       kasan_alloca_oob_left();
+       kasan_alloca_oob_right();
        ksize_unpoisons_memory();
        copy_user_test();
        use_after_scope_test();
+
+       kasan_restore_multi_shot(multishot);
+
        return -EAGAIN;
 }