Skip to content

Commit

Permalink
lib: test_kasan: add some testcases
Browse files Browse the repository at this point in the history
Add some out of bounds testcases to test_kasan module.

Signed-off-by: Wang Long <long.wanglong@huawei.com>
Acked-by: Andrey Ryabinin <aryabinin@virtuozzo.com>
Cc: Vladimir Murzin <vladimir.murzin@arm.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
  • Loading branch information
datawolf authored and torvalds committed Nov 6, 2015
1 parent 5d0926e commit f523e73
Showing 1 changed file with 69 additions and 0 deletions.
69 changes: 69 additions & 0 deletions lib/test_kasan.c
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,71 @@ static noinline void __init kmalloc_oob_16(void)
kfree(ptr2);
}

static noinline void __init kmalloc_oob_memset_2(void)
{
char *ptr;
size_t size = 8;

pr_info("out-of-bounds in memset2\n");
ptr = kmalloc(size, GFP_KERNEL);
if (!ptr) {
pr_err("Allocation failed\n");
return;
}

memset(ptr+7, 0, 2);
kfree(ptr);
}

static noinline void __init kmalloc_oob_memset_4(void)
{
char *ptr;
size_t size = 8;

pr_info("out-of-bounds in memset4\n");
ptr = kmalloc(size, GFP_KERNEL);
if (!ptr) {
pr_err("Allocation failed\n");
return;
}

memset(ptr+5, 0, 4);
kfree(ptr);
}


static noinline void __init kmalloc_oob_memset_8(void)
{
char *ptr;
size_t size = 8;

pr_info("out-of-bounds in memset8\n");
ptr = kmalloc(size, GFP_KERNEL);
if (!ptr) {
pr_err("Allocation failed\n");
return;
}

memset(ptr+1, 0, 8);
kfree(ptr);
}

static noinline void __init kmalloc_oob_memset_16(void)
{
char *ptr;
size_t size = 16;

pr_info("out-of-bounds in memset16\n");
ptr = kmalloc(size, GFP_KERNEL);
if (!ptr) {
pr_err("Allocation failed\n");
return;
}

memset(ptr+1, 0, 16);
kfree(ptr);
}

static noinline void __init kmalloc_oob_in_memset(void)
{
char *ptr;
Expand Down Expand Up @@ -264,6 +329,10 @@ static int __init kmalloc_tests_init(void)
kmalloc_oob_krealloc_less();
kmalloc_oob_16();
kmalloc_oob_in_memset();
kmalloc_oob_memset_2();
kmalloc_oob_memset_4();
kmalloc_oob_memset_8();
kmalloc_oob_memset_16();
kmalloc_uaf();
kmalloc_uaf_memset();
kmalloc_uaf2();
Expand Down

0 comments on commit f523e73

Please sign in to comment.