summary refs log tree commit diff
path: root/lib/test_kasan.c
diff options
context:
space:
mode:
authorMarco Elver <elver@google.com>2019-07-11 20:54:11 -0700
committerLinus Torvalds <torvalds@linux-foundation.org>2019-07-12 11:05:42 -0700
commitbb104ed78552147bed3a981fdada622afd2084b6 (patch)
tree78a8a7389d65e4bbb32b8df7eddd77cd3cb2cfb8 /lib/test_kasan.c
parentb5f6e0fc7d60e0234dac82498e90dfe9027bad1f (diff)
downloadlinux-bb104ed78552147bed3a981fdada622afd2084b6.tar.gz
lib/test_kasan: Add test for double-kzfree detection
Add a simple test that checks if double-kzfree is being detected
correctly.

Link: http://lkml.kernel.org/r/20190626142014.141844-4-elver@google.com
Signed-off-by: Marco Elver <elver@google.com>
Reviewed-by: Andrey Ryabinin <aryabinin@virtuozzo.com>
Cc: Dmitry Vyukov <dvyukov@google.com>
Cc: Alexander Potapenko <glider@google.com>
Cc: Andrey Konovalov <andreyknvl@google.com>
Cc: Christoph Lameter <cl@linux.com>
Cc: Pekka Enberg <penberg@kernel.org>
Cc: David Rientjes <rientjes@google.com>
Cc: Joonsoo Kim <iamjoonsoo.kim@lge.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Kees Cook <keescook@chromium.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'lib/test_kasan.c')
-rw-r--r--lib/test_kasan.c17
1 files changed, 17 insertions, 0 deletions
diff --git a/lib/test_kasan.c b/lib/test_kasan.c
index d85f25c65b0a..b63b367a94e8 100644
--- a/lib/test_kasan.c
+++ b/lib/test_kasan.c
@@ -693,6 +693,22 @@ static noinline void __init kasan_bitops(void)
 	kfree(bits);
 }
 
+static noinline void __init kmalloc_double_kzfree(void)
+{
+	char *ptr;
+	size_t size = 16;
+
+	pr_info("double-free (kzfree)\n");
+	ptr = kmalloc(size, GFP_KERNEL);
+	if (!ptr) {
+		pr_err("Allocation failed\n");
+		return;
+	}
+
+	kzfree(ptr);
+	kzfree(ptr);
+}
+
 static int __init kmalloc_tests_init(void)
 {
 	/*
@@ -735,6 +751,7 @@ static int __init kmalloc_tests_init(void)
 	kasan_memcmp();
 	kasan_strings();
 	kasan_bitops();
+	kmalloc_double_kzfree();
 
 	kasan_restore_multi_shot(multishot);