Merge branch 'dmi-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/jdelvar...
[linux-2.6-microblaze.git] / lib / test_kasan.c
index e3087d9..dc2c6a5 100644 (file)
 
 #include <asm/page.h>
 
+/*
+ * We assign some test results to these globals to make sure the tests
+ * are not eliminated as dead code.
+ */
+
+int kasan_int_result;
+void *kasan_ptr_result;
+
 /*
  * Note: test functions are marked noinline so that their names appear in
  * reports.
@@ -622,7 +630,7 @@ static noinline void __init kasan_memchr(void)
        if (!ptr)
                return;
 
-       memchr(ptr, '1', size + 1);
+       kasan_ptr_result = memchr(ptr, '1', size + 1);
        kfree(ptr);
 }
 
@@ -638,7 +646,7 @@ static noinline void __init kasan_memcmp(void)
                return;
 
        memset(arr, 0, sizeof(arr));
-       memcmp(ptr, arr, size+1);
+       kasan_int_result = memcmp(ptr, arr, size + 1);
        kfree(ptr);
 }
 
@@ -661,22 +669,22 @@ static noinline void __init kasan_strings(void)
         * will likely point to zeroed byte.
         */
        ptr += 16;
-       strchr(ptr, '1');
+       kasan_ptr_result = strchr(ptr, '1');
 
        pr_info("use-after-free in strrchr\n");
-       strrchr(ptr, '1');
+       kasan_ptr_result = strrchr(ptr, '1');
 
        pr_info("use-after-free in strcmp\n");
-       strcmp(ptr, "2");
+       kasan_int_result = strcmp(ptr, "2");
 
        pr_info("use-after-free in strncmp\n");
-       strncmp(ptr, "2", 1);
+       kasan_int_result = strncmp(ptr, "2", 1);
 
        pr_info("use-after-free in strlen\n");
-       strlen(ptr);
+       kasan_int_result = strlen(ptr);
 
        pr_info("use-after-free in strnlen\n");
-       strnlen(ptr, 1);
+       kasan_int_result = strnlen(ptr, 1);
 }
 
 static noinline void __init kasan_bitops(void)
@@ -743,11 +751,12 @@ static noinline void __init kasan_bitops(void)
        __test_and_change_bit(BITS_PER_LONG + BITS_PER_BYTE, bits);
 
        pr_info("out-of-bounds in test_bit\n");
-       (void)test_bit(BITS_PER_LONG + BITS_PER_BYTE, bits);
+       kasan_int_result = test_bit(BITS_PER_LONG + BITS_PER_BYTE, bits);
 
 #if defined(clear_bit_unlock_is_negative_byte)
        pr_info("out-of-bounds in clear_bit_unlock_is_negative_byte\n");
-       clear_bit_unlock_is_negative_byte(BITS_PER_LONG + BITS_PER_BYTE, bits);
+       kasan_int_result = clear_bit_unlock_is_negative_byte(BITS_PER_LONG +
+               BITS_PER_BYTE, bits);
 #endif
        kfree(bits);
 }