Add a test that makes sure ksize() unpoisons the whole chunk.
Signed-off-by: Alexander Potapenko <glider@google.com>
Acked-by: Andrey Ryabinin <aryabinin@virtuozzo.com>
Cc: Andrey Konovalov <adech.fo@gmail.com>
Cc: Dmitry Vyukov <dvyukov@google.com>
Cc: Christoph Lameter <cl@linux.com>
Cc: Konstantin Serebryany <kcc@google.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
        *(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();
        kmem_cache_oob();
        kasan_stack_oob();
        kasan_global_oob();
+       ksize_unpoisons_memory();
        return -EAGAIN;
 }