Commit 96fe805f authored by Alexander Potapenko's avatar Alexander Potapenko Committed by Linus Torvalds

mm, kasan: add a ksize() test

Add a test that makes sure ksize() unpoisons the whole chunk.
Signed-off-by: default avatarAlexander Potapenko <>
Acked-by: default avatarAndrey Ryabinin <>
Cc: Andrey Konovalov <>
Cc: Dmitry Vyukov <>
Cc: Christoph Lameter <>
Cc: Konstantin Serebryany <>
Signed-off-by: default avatarAndrew Morton <>
Signed-off-by: default avatarLinus Torvalds <>
parent 4ebb31a4
......@@ -344,6 +344,25 @@ static noinline void __init kasan_stack_oob(void)
*(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");
real_size = ksize(ptr);
/* This access doesn't trigger an error. */
ptr[size] = 'x';
/* This one does. */
ptr[real_size] = 'y';
static int __init kmalloc_tests_init(void)
......@@ -367,6 +386,7 @@ static int __init kmalloc_tests_init(void)
return -EAGAIN;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment