Skip to content

Commit

Permalink
kasan: add test for vmalloc
Browse files Browse the repository at this point in the history
Test kasan vmalloc support by adding a new test to the module.

Link: http://lkml.kernel.org/r/[email protected]
Signed-off-by: Daniel Axtens <[email protected]>
Reviewed-by: Andrey Ryabinin <[email protected]>
Cc: Alexander Potapenko <[email protected]>
Cc: Christophe Leroy <[email protected]>
Cc: Dmitry Vyukov <[email protected]>
Cc: Mark Rutland <[email protected]>
Cc: Vasily Gorbik <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
daxtens authored and torvalds committed Dec 1, 2019
1 parent 3c5c3cf commit 0651391
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions lib/test_kasan.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include <linux/string.h>
#include <linux/uaccess.h>
#include <linux/io.h>
#include <linux/vmalloc.h>

#include <asm/page.h>

Expand Down Expand Up @@ -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)
{
/*
Expand Down Expand Up @@ -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);

Expand Down

0 comments on commit 0651391

Please sign in to comment.