* [PATCH 2/2] kasan: add test for invalid size in memmove
@ 2019-10-14 10:36 Walter Wu
2019-10-14 10:41 ` Dmitry Vyukov
2019-10-14 15:07 ` Matthew Wilcox
0 siblings, 2 replies; 4+ messages in thread
From: Walter Wu @ 2019-10-14 10:36 UTC (permalink / raw)
To: Andrey Ryabinin, Alexander Potapenko, Dmitry Vyukov, Matthias Brugger
Cc: kasan-dev, linux-mm, linux-kernel, linux-arm-kernel,
linux-mediatek, wsd_upstream, Walter Wu
Test size is negative numbers in memmove in order to verify
whether it correctly get KASAN report.
Signed-off-by: Walter Wu <walter-zh.wu@mediatek.com>
---
lib/test_kasan.c | 18 ++++++++++++++++++
1 file changed, 18 insertions(+)
diff --git a/lib/test_kasan.c b/lib/test_kasan.c
index 49cc4d570a40..06942cf585cc 100644
--- a/lib/test_kasan.c
+++ b/lib/test_kasan.c
@@ -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();
--
2.18.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH 2/2] kasan: add test for invalid size in memmove
2019-10-14 10:36 [PATCH 2/2] kasan: add test for invalid size in memmove Walter Wu
@ 2019-10-14 10:41 ` Dmitry Vyukov
2019-10-14 15:07 ` Matthew Wilcox
1 sibling, 0 replies; 4+ messages in thread
From: Dmitry Vyukov @ 2019-10-14 10:41 UTC (permalink / raw)
To: Walter Wu
Cc: Andrey Ryabinin, Alexander Potapenko, Matthias Brugger,
kasan-dev, Linux-MM, LKML, Linux ARM, linux-mediatek,
wsd_upstream
On Mon, Oct 14, 2019 at 12:37 PM Walter Wu <walter-zh.wu@mediatek.com> wrote:
>
> Test size is negative numbers in memmove in order to verify
> whether it correctly get KASAN report.
>
> Signed-off-by: Walter Wu <walter-zh.wu@mediatek.com>
Reviewed-by: Dmitry Vyukov <dvyukov@google.com>
Thanks!
> ---
> lib/test_kasan.c | 18 ++++++++++++++++++
> 1 file changed, 18 insertions(+)
>
> diff --git a/lib/test_kasan.c b/lib/test_kasan.c
> index 49cc4d570a40..06942cf585cc 100644
> --- a/lib/test_kasan.c
> +++ b/lib/test_kasan.c
> @@ -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();
> --
> 2.18.0
>
> --
> You received this message because you are subscribed to the Google Groups "kasan-dev" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to kasan-dev+unsubscribe@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/kasan-dev/20191014103654.17982-1-walter-zh.wu%40mediatek.com.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH 2/2] kasan: add test for invalid size in memmove
2019-10-14 10:36 [PATCH 2/2] kasan: add test for invalid size in memmove Walter Wu
2019-10-14 10:41 ` Dmitry Vyukov
@ 2019-10-14 15:07 ` Matthew Wilcox
2019-10-14 15:57 ` Walter Wu
1 sibling, 1 reply; 4+ messages in thread
From: Matthew Wilcox @ 2019-10-14 15:07 UTC (permalink / raw)
To: Walter Wu
Cc: Andrey Ryabinin, Alexander Potapenko, Dmitry Vyukov,
Matthias Brugger, kasan-dev, linux-mm, linux-kernel,
linux-arm-kernel, linux-mediatek, wsd_upstream
On Mon, Oct 14, 2019 at 06:36:54PM +0800, Walter Wu wrote:
> Test size is negative numbers in memmove in order to verify
> whether it correctly get KASAN report.
You're not testing negative numbers, though. memmove() takes an unsigned
type, so you're testing a very large number.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH 2/2] kasan: add test for invalid size in memmove
2019-10-14 15:07 ` Matthew Wilcox
@ 2019-10-14 15:57 ` Walter Wu
0 siblings, 0 replies; 4+ messages in thread
From: Walter Wu @ 2019-10-14 15:57 UTC (permalink / raw)
To: Matthew Wilcox
Cc: Andrey Ryabinin, Alexander Potapenko, Dmitry Vyukov,
Matthias Brugger, kasan-dev, linux-mm, linux-kernel,
linux-arm-kernel, linux-mediatek, wsd_upstream
On Mon, 2019-10-14 at 08:07 -0700, Matthew Wilcox wrote:
> On Mon, Oct 14, 2019 at 06:36:54PM +0800, Walter Wu wrote:
> > Test size is negative numbers in memmove in order to verify
> > whether it correctly get KASAN report.
>
> You're not testing negative numbers, though. memmove() takes an unsigned
> type, so you're testing a very large number.
>
Casting negative numbers to size_t would indeed turn up as a "large"
size_t and its value will be larger than ULONG_MAX/2. We mainly want to
express this case. Maybe we can add some descriptions. Thanks for your
reminder.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2019-10-14 15:57 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-10-14 10:36 [PATCH 2/2] kasan: add test for invalid size in memmove Walter Wu
2019-10-14 10:41 ` Dmitry Vyukov
2019-10-14 15:07 ` Matthew Wilcox
2019-10-14 15:57 ` Walter Wu
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).