linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v4 2/2] kasan: add test for invalid size in memmove
@ 2019-11-12  6:53 Walter Wu
  2019-11-21 22:21 ` Andrey Ryabinin
  0 siblings, 1 reply; 5+ messages in thread
From: Walter Wu @ 2019-11-12  6:53 UTC (permalink / raw)
  To: Andrey Ryabinin, Alexander Potapenko, Dmitry Vyukov, Matthias Brugger
  Cc: kasan-dev, linux-mm, linux-kernel, linux-arm-kernel,
	wsd_upstream, linux-mediatek, Walter Wu

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.

Signed-off-by: Walter Wu <walter-zh.wu@mediatek.com>
Reviewed-by: Dmitry Vyukov <dvyukov@google.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] 5+ messages in thread

* Re: [PATCH v4 2/2] kasan: add test for invalid size in memmove
  2019-11-12  6:53 [PATCH v4 2/2] kasan: add test for invalid size in memmove Walter Wu
@ 2019-11-21 22:21 ` Andrey Ryabinin
  2020-01-30  3:43   ` Walter Wu
  0 siblings, 1 reply; 5+ messages in thread
From: Andrey Ryabinin @ 2019-11-21 22:21 UTC (permalink / raw)
  To: Walter Wu, Alexander Potapenko, Dmitry Vyukov, Matthias Brugger
  Cc: kasan-dev, linux-mm, linux-kernel, linux-arm-kernel,
	wsd_upstream, linux-mediatek, Andrew Morton



On 11/12/19 9:53 AM, Walter Wu wrote:
> 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.
> 
> Signed-off-by: Walter Wu <walter-zh.wu@mediatek.com>
> Reviewed-by: Dmitry Vyukov <dvyukov@google.com>

Reviewed-by: Andrey Ryabinin <aryabinin@virtuozzo.com>

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v4 2/2] kasan: add test for invalid size in memmove
  2019-11-21 22:21 ` Andrey Ryabinin
@ 2020-01-30  3:43   ` Walter Wu
  2020-01-31  2:16     ` Andrew Morton
  0 siblings, 1 reply; 5+ messages in thread
From: Walter Wu @ 2020-01-30  3:43 UTC (permalink / raw)
  To: Andrey Ryabinin, Dmitry Vyukov, Andrew Morton
  Cc: Alexander Potapenko, Dmitry Vyukov, Matthias Brugger, kasan-dev,
	linux-mm, linux-kernel, linux-arm-kernel, wsd_upstream,
	linux-mediatek, Andrew Morton

On Fri, 2019-11-22 at 06:21 +0800, Andrey Ryabinin wrote:
> 
> On 11/12/19 9:53 AM, Walter Wu wrote:
> > 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.
> > 
> > Signed-off-by: Walter Wu <walter-zh.wu@mediatek.com>
> > Reviewed-by: Dmitry Vyukov <dvyukov@google.com>
> 
> Reviewed-by: Andrey Ryabinin <aryabinin@virtuozzo.com>

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


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v4 2/2] kasan: add test for invalid size in memmove
  2020-01-30  3:43   ` Walter Wu
@ 2020-01-31  2:16     ` Andrew Morton
  2020-01-31  2:53       ` Walter Wu
  0 siblings, 1 reply; 5+ messages in thread
From: Andrew Morton @ 2020-01-31  2:16 UTC (permalink / raw)
  To: Walter Wu
  Cc: Andrey Ryabinin, Dmitry Vyukov, Alexander Potapenko,
	Matthias Brugger, kasan-dev, linux-mm, linux-kernel,
	linux-arm-kernel, wsd_upstream, linux-mediatek

On Thu, 30 Jan 2020 11:43:58 +0800 Walter Wu <walter-zh.wu@mediatek.com> wrote:

> On Fri, 2019-11-22 at 06:21 +0800, Andrey Ryabinin wrote:
> > 
> > On 11/12/19 9:53 AM, Walter Wu wrote:
> > > 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.
> > > 
> > > Signed-off-by: Walter Wu <walter-zh.wu@mediatek.com>
> > > Reviewed-by: Dmitry Vyukov <dvyukov@google.com>
> > 
> > Reviewed-by: Andrey Ryabinin <aryabinin@virtuozzo.com>
> 
> 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?


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v4 2/2] kasan: add test for invalid size in memmove
  2020-01-31  2:16     ` Andrew Morton
@ 2020-01-31  2:53       ` Walter Wu
  0 siblings, 0 replies; 5+ messages in thread
From: Walter Wu @ 2020-01-31  2:53 UTC (permalink / raw)
  To: Andrew Morton
  Cc: Andrey Ryabinin, Dmitry Vyukov, Alexander Potapenko,
	Matthias Brugger, kasan-dev, linux-mm, linux-kernel,
	linux-arm-kernel, wsd_upstream, linux-mediatek

On Thu, 2020-01-30 at 18:16 -0800, Andrew Morton wrote:
> On Thu, 30 Jan 2020 11:43:58 +0800 Walter Wu <walter-zh.wu@mediatek.com> wrote:
> 
> > On Fri, 2019-11-22 at 06:21 +0800, Andrey Ryabinin wrote:
> > > 
> > > On 11/12/19 9:53 AM, Walter Wu wrote:
> > > > 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.
> > > > 
> > > > Signed-off-by: Walter Wu <walter-zh.wu@mediatek.com>
> > > > Reviewed-by: Dmitry Vyukov <dvyukov@google.com>
> > > 
> > > Reviewed-by: Andrey Ryabinin <aryabinin@virtuozzo.com>
> > 
> > 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?
> 

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

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2020-01-31  2:53 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-11-12  6:53 [PATCH v4 2/2] kasan: add test for invalid size in memmove Walter Wu
2019-11-21 22:21 ` Andrey Ryabinin
2020-01-30  3:43   ` Walter Wu
2020-01-31  2:16     ` Andrew Morton
2020-01-31  2:53       ` 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).