The patch titled Subject: kasan: add test for invalid size in memmove has been added to the -mm tree. Its filename is kasan-add-test-for-invalid-size-in-memmove.patch This patch should soon appear at http://ozlabs.org/~akpm/mmots/broken-out/kasan-add-test-for-invalid-size-in-memmove.patch and later at http://ozlabs.org/~akpm/mmotm/broken-out/kasan-add-test-for-invalid-size-in-memmove.patch Before you just go and hit "reply", please: a) Consider who else should be cc'ed b) Prefer to cc a suitable mailing list as well c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's *** Remember to use Documentation/process/submit-checklist.rst when testing your code *** The -mm tree is included into linux-next and is updated there every 3-4 working days ------------------------------------------------------ From: Walter Wu <walter-zh.wu@xxxxxxxxxxxx> Subject: kasan: add test for invalid size in memmove Test negative size in memmove in order to verify whether it correctly get KASAN report. Casting negative numbers to size_t would indeed turn up as a large size_t, so it will have out-of-bounds bug and be detected by KASAN. Link: http://lkml.kernel.org/r/20191112065313.7060-1-walter-zh.wu@xxxxxxxxxxxx Signed-off-by: Walter Wu <walter-zh.wu@xxxxxxxxxxxx> Reviewed-by: Dmitry Vyukov <dvyukov@xxxxxxxxxx> Reviewed-by: Andrey Ryabinin <aryabinin@xxxxxxxxxxxxx> Cc: Alexander Potapenko <glider@xxxxxxxxxx> Cc: kernel test robot <lkp@xxxxxxxxx> Signed-off-by: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx> --- lib/test_kasan.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) --- a/lib/test_kasan.c~kasan-add-test-for-invalid-size-in-memmove +++ a/lib/test_kasan.c @@ -285,6 +285,23 @@ static noinline void __init kmalloc_oob_ kfree(ptr); } +static noinline void __init kmalloc_memmove_invalid_size(void) +{ + char *ptr; + size_t size = 64; + + pr_info("invalid size in memmove\n"); + ptr = kmalloc(size, GFP_KERNEL); + if (!ptr) { + pr_err("Allocation failed\n"); + return; + } + + memset((char *)ptr, 0, 64); + memmove((char *)ptr, (char *)ptr + 4, -2); + kfree(ptr); +} + static noinline void __init kmalloc_uaf(void) { char *ptr; @@ -799,6 +816,7 @@ static int __init kmalloc_tests_init(voi kmalloc_oob_memset_4(); kmalloc_oob_memset_8(); kmalloc_oob_memset_16(); + kmalloc_memmove_invalid_size(); kmalloc_uaf(); kmalloc_uaf_memset(); kmalloc_uaf2(); _ Patches currently in -mm which might be from walter-zh.wu@xxxxxxxxxxxx are kasan-detect-negative-size-in-memory-operation-function.patch kasan-add-test-for-invalid-size-in-memmove.patch