kasan: add test for invalid size in memmove
Subsystems (3)
PATCH v4 2/2 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.
--- lib/test_kasan.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+)
lib/test_kasan.c +18 -0
@@ -283,6 +283,23 @@ static noinline void __init kmalloc_oob_in_memset(void)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;
@@ -773,6 +790,7 @@ static int __init kmalloc_tests_init(void)kmalloc_oob_memset_4 ();kmalloc_oob_memset_8 ();kmalloc_oob_memset_16 (); +kmalloc_memmove_invalid_size ();kmalloc_uaf ();kmalloc_uaf_memset ();kmalloc_uaf2 ();
Signature · 1 line
2.18.0
Quoted 8 lines · Walter Wu
Test negative size in memmove in order to verify whether it correctly get KASAN report.
Casting negative numbers to
size_twould indeed turn up as a largesize_t, so it will have out-of-bounds bug and be detected by KASAN.Signed-off-by Walter Wu <[email protected]>Reviewed-by Dmitry Vyukov <[email protected]>
_______________________________________________
Linux-mediatek mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-mediatek
Quoted 5 lines · Andrey Ryabinin
Quoted 3 lines · Walter Wu
Test negative size in memmove in order to verify whether it correctly get KASAN report.
Quoted 7 lines
Quoted 5 lines
Casting negative numbers to
size_twould indeed turn up as a largesize_t, so it will have out-of-bounds bug and be detected by KASAN.Signed-off-by Walter Wu <[email protected]>Reviewed-by Dmitry Vyukov <[email protected]>Reviewed-by Andrey Ryabinin <[email protected]>
Hi Andrey, Dmitry, Andrew,
Would you tell me why this patch-sets don't merge into linux-next tree? We lost something?
Thanks for your help.
Walter
Andrew Morton
maintainerQuoted 12 lines · On Thu, 30 Jan 2020 11:43:58 +0800 Walter Wu <[email protected]> wrote:
Quoted 11 lines · Andrey Ryabinin
Quoted 8 lines · Walter Wu
Test negative size in memmove in order to verify whether it correctly get KASAN report.
Casting negative numbers to
size_twould indeed turn up as a largesize_t, so it will have out-of-bounds bug and be detected by KASAN.Signed-off-by Walter Wu <[email protected]>Reviewed-by Dmitry Vyukov <[email protected]>
Quoted 7 lines
Quoted 1 line
Reviewed-by Andrey Ryabinin <[email protected]>Hi Andrey, Dmitry, Andrew,
Would you tell me why this patch-sets don't merge into linux-next tree? We lost something?
In response to [1/2] Andrey said "So let's keep this code as this" and you said "I will send a new v5 patch tomorrow". So we're awaiting a v5 patchset?
Quoted 18 lines · Andrew Morton
Quoted 16 lines · On Thu, 30 Jan 2020 11:43:58 +0800 Walter Wu <[email protected]> wrote:
Quoted 5 lines · Andrey Ryabinin
Quoted 3 lines · Walter Wu
Test negative size in memmove in order to verify whether it correctly get KASAN report.
Quoted 7 lines
Quoted 5 lines
Casting negative numbers to
size_twould indeed turn up as a largesize_t, so it will have out-of-bounds bug and be detected by KASAN.Signed-off-by Walter Wu <[email protected]>Reviewed-by Dmitry Vyukov <[email protected]>Reviewed-by Andrey Ryabinin <[email protected]>Hi Andrey, Dmitry, Andrew,
Quoted 8 lines
Quoted 3 lines
Would you tell me why this patch-sets don't merge into linux-next tree? We lost something?
In response to [1/2] Andrey said "So let's keep this code as this" and you said "I will send a new v5 patch tomorrow". So we're awaiting a v5 patchset?
Hi Andrew,
The [1/2] patch discussion shows below. Thanks for Dimitry help to explain it. So that v4 patchset got Andrey's signature. Because I see Andrey said "But I see you point now. No objections to the patch in that case."
@Andrey, if I have an incorrect understanding, please let me know. Thanks for your help.
https://lkml.org/lkml/2019/11/21/1019
https://lkml.org/lkml/2019/11/21/1020
Walter