summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorAlexander Potapenko <glider@google.com>2016-05-20 16:59:17 -0700
committerAmit Pundir <amit.pundir@linaro.org>2018-01-22 13:15:43 +0530
commit5337140e2a79c17a0ac8a6a9d0041d9cb286aa15 (patch)
tree5d979158c337a40e87606f205dde5c4b02029bfc /lib
parentf2fcd0f292d1414f0e77f608a3b9622de6eae500 (diff)
UPSTREAM: mm, kasan: add a ksize() test
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> Bug: 64145065 (cherry-picked from 96fe805fb6fe9b2ed12fc54ad0e3e6829a4152cb) Change-Id: Ia468981e2ccc62bc1678449a65aab341a9e7ceba Signed-off-by: Paul Lawrence <paullawrence@google.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/test_kasan.c20
1 files changed, 20 insertions, 0 deletions
diff --git a/lib/test_kasan.c b/lib/test_kasan.c
index 82169fbf2453..48e5a0be655c 100644
--- a/lib/test_kasan.c
+++ b/lib/test_kasan.c
@@ -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");
+ 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(void)
kmem_cache_oob();
kasan_stack_oob();
kasan_global_oob();
+ ksize_unpoisons_memory();
return -EAGAIN;
}