Skip to content

Commit

Permalink
lib/test_kasan: Add test for double-kzfree detection
Browse files Browse the repository at this point in the history
Add a simple test that checks if double-kzfree is being detected
correctly.

Link: http://lkml.kernel.org/r/[email protected]
Signed-off-by: Marco Elver <[email protected]>
Reviewed-by: Andrey Ryabinin <[email protected]>
Cc: Dmitry Vyukov <[email protected]>
Cc: Alexander Potapenko <[email protected]>
Cc: Andrey Konovalov <[email protected]>
Cc: Christoph Lameter <[email protected]>
Cc: Pekka Enberg <[email protected]>
Cc: David Rientjes <[email protected]>
Cc: Joonsoo Kim <[email protected]>
Cc: Mark Rutland <[email protected]>
Cc: Kees Cook <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
melver authored and torvalds committed Jul 12, 2019
1 parent b5f6e0f commit bb104ed
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions lib/test_kasan.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
/*
Expand Down Expand Up @@ -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);

Expand Down

0 comments on commit bb104ed

Please sign in to comment.