diff mbox series

[v10,2/5] kasan: add test for vmalloc

Message ID 20191029042059.28541-3-dja@axtens.net (mailing list archive)
State Superseded
Headers show
Series kasan: support backing vmalloc space with real shadow memory | expand

Checks

Context Check Description
snowpatch_ozlabs/apply_patch warning Failed to apply on branch powerpc/merge (a437a1c6e54c045f19f7d894b2a749bc5155f19a)
snowpatch_ozlabs/apply_patch warning Failed to apply on branch powerpc/next (612ee81b9461475b5a5612c2e8d71559dd3c7920)
snowpatch_ozlabs/apply_patch warning Failed to apply on branch linus/master (8005803a2ca0af49f36f6e9329b5ecda3df27347)
snowpatch_ozlabs/apply_patch warning Failed to apply on branch powerpc/fixes (a8a30219ba78b1abb92091102b632f8e9bbdbf03)
snowpatch_ozlabs/apply_patch success Successfully applied on branch linux-next (60c1769a45f4b6beddcc48843739d7d41b88dc1c)
snowpatch_ozlabs/checkpatch warning total: 0 errors, 2 warnings, 0 checks, 44 lines checked

Commit Message

Daniel Axtens Oct. 29, 2019, 4:20 a.m. UTC
Test kasan vmalloc support by adding a new test to the module.

Signed-off-by: Daniel Axtens <dja@axtens.net>

--

v5: split out per Christophe Leroy
---
 lib/test_kasan.c | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)

Comments

Andrey Ryabinin Oct. 29, 2019, 4:43 p.m. UTC | #1
On 10/29/19 7:20 AM, Daniel Axtens wrote:
> Test kasan vmalloc support by adding a new test to the module.
> 
> Signed-off-by: Daniel Axtens <dja@axtens.net>
> 

Reviewed-by: Andrey Ryabinin <aryabinin@virtuozzo.com>
diff mbox series

Patch

diff --git a/lib/test_kasan.c b/lib/test_kasan.c
index 49cc4d570a40..328d33beae36 100644
--- a/lib/test_kasan.c
+++ b/lib/test_kasan.c
@@ -19,6 +19,7 @@ 
 #include <linux/string.h>
 #include <linux/uaccess.h>
 #include <linux/io.h>
+#include <linux/vmalloc.h>
 
 #include <asm/page.h>
 
@@ -748,6 +749,30 @@  static noinline void __init kmalloc_double_kzfree(void)
 	kzfree(ptr);
 }
 
+#ifdef CONFIG_KASAN_VMALLOC
+static noinline void __init vmalloc_oob(void)
+{
+	void *area;
+
+	pr_info("vmalloc out-of-bounds\n");
+
+	/*
+	 * We have to be careful not to hit the guard page.
+	 * The MMU will catch that and crash us.
+	 */
+	area = vmalloc(3000);
+	if (!area) {
+		pr_err("Allocation failed\n");
+		return;
+	}
+
+	((volatile char *)area)[3100];
+	vfree(area);
+}
+#else
+static void __init vmalloc_oob(void) {}
+#endif
+
 static int __init kmalloc_tests_init(void)
 {
 	/*
@@ -793,6 +818,7 @@  static int __init kmalloc_tests_init(void)
 	kasan_strings();
 	kasan_bitops();
 	kmalloc_double_kzfree();
+	vmalloc_oob();
 
 	kasan_restore_multi_shot(multishot);