mm, kasan: add a ksize() test
[email protected]
maintainerPATCH 59/162 mm, kasan: add a ksize() test
From: Alexander Potapenko <[email protected]>
Subject: mm, kasan: add a ksize() test
Add a test that makes sure ksize() unpoisons the whole chunk.
Signed-off-by Alexander Potapenko <[email protected]>
Acked-by Andrey Ryabinin <[email protected]>
Cc Andrey Konovalov <[email protected]>
Cc Dmitry Vyukov <[email protected]>
Cc Christoph Lameter <[email protected]>
Cc Konstantin Serebryany <[email protected]>
Signed-off-by Andrew Morton <[email protected]>
---
lib/test_kasan.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+)
lib/test_kasan.c renamed from lib/test_kasan.c~mm-kasan-add-a-ksize-test +20 -0
@@ -344,6 +344,25 @@ static noinline void __init kasan_stack_ *(volatile char *)p; } +static noinline void __init ksize_unpoisons_memory(void) +{ +char *ptr; +size_t size =123 , real_size = size; + +pr_info ("ksize() unpoisons the whole allocated chunk\n" ); + ptr =kmalloc (size,GFP_KERNEL ); +if (!ptr) { +pr_err ("Allocation failed\n" ); +return ; + } + real_size =ksize (ptr); +/* This access doesn't trigger an error. */ + ptr[size] ='x' ; +/* This one does. */ + ptr[real_size] ='y' ; +kfree (ptr); +} +static int __init kmalloc_tests_init (void ) {kmalloc_oob_right ();
@@ -367,6 +386,7 @@ static int __init kmalloc_tests_init(voikmem_cache_oob ();kasan_stack_oob ();kasan_global_oob (); +ksize_unpoisons_memory ();return -EAGAIN ; }
_