linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] kasan: add test for -fsanitize-address-use-after-scope
@ 2016-12-05 14:16 Jiri Slaby
  2016-12-05 14:20 ` Dmitry Vyukov
  2016-12-05 14:20 ` Jiri Slaby
  0 siblings, 2 replies; 3+ messages in thread
From: Jiri Slaby @ 2016-12-05 14:16 UTC (permalink / raw)
  To: akpm; +Cc: dvyukov, linux-kernel, marxin, Jiri Slaby

From: marxin <mliska@suse.cz>

In commit 828347f8f9a5 ("kasan: support use-after-scope detection") we
added support for use-after-scope. Let's add a check if it actually
works.

Signed-off-by: Martin Liska <mliska@suse.cz>
Signed-off-by: Jiri Slaby <jslaby@suse.cz>
---
 lib/test_kasan.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/lib/test_kasan.c b/lib/test_kasan.c
index fbdf87920093..32f31b8d306e 100644
--- a/lib/test_kasan.c
+++ b/lib/test_kasan.c
@@ -352,6 +352,19 @@ static noinline void __init kasan_stack_oob(void)
 	*(volatile char *)p;
 }
 
+static noinline void __init kasan_stack_use_after_scope(void)
+{
+	char *ptr = NULL;
+	{
+		char a;
+
+		ptr = &a;
+	}
+
+	pr_info("use-after-scope on stack\n");
+	*(volatile char *)ptr;
+}
+
 static noinline void __init ksize_unpoisons_memory(void)
 {
 	char *ptr;
@@ -461,6 +474,7 @@ static int __init kmalloc_tests_init(void)
 	kmalloc_uaf2();
 	kmem_cache_oob();
 	kasan_stack_oob();
+	kasan_stack_use_after_scope();
 	kasan_global_oob();
 	ksize_unpoisons_memory();
 	copy_user_test();
-- 
2.11.0

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

* Re: [PATCH] kasan: add test for -fsanitize-address-use-after-scope
  2016-12-05 14:16 [PATCH] kasan: add test for -fsanitize-address-use-after-scope Jiri Slaby
@ 2016-12-05 14:20 ` Dmitry Vyukov
  2016-12-05 14:20 ` Jiri Slaby
  1 sibling, 0 replies; 3+ messages in thread
From: Dmitry Vyukov @ 2016-12-05 14:20 UTC (permalink / raw)
  To: Jiri Slaby; +Cc: Andrew Morton, LKML, marxin

On Mon, Dec 5, 2016 at 3:16 PM, Jiri Slaby <jslaby@suse.cz> wrote:
> From: marxin <mliska@suse.cz>
>
> In commit 828347f8f9a5 ("kasan: support use-after-scope detection") we
> added support for use-after-scope. Let's add a check if it actually
> works.
>
> Signed-off-by: Martin Liska <mliska@suse.cz>
> Signed-off-by: Jiri Slaby <jslaby@suse.cz>
> ---
>  lib/test_kasan.c | 14 ++++++++++++++
>  1 file changed, 14 insertions(+)
>
> diff --git a/lib/test_kasan.c b/lib/test_kasan.c
> index fbdf87920093..32f31b8d306e 100644
> --- a/lib/test_kasan.c
> +++ b/lib/test_kasan.c
> @@ -352,6 +352,19 @@ static noinline void __init kasan_stack_oob(void)
>         *(volatile char *)p;
>  }
>
> +static noinline void __init kasan_stack_use_after_scope(void)
> +{
> +       char *ptr = NULL;
> +       {
> +               char a;
> +
> +               ptr = &a;
> +       }
> +
> +       pr_info("use-after-scope on stack\n");
> +       *(volatile char *)ptr;
> +}
> +
>  static noinline void __init ksize_unpoisons_memory(void)
>  {
>         char *ptr;
> @@ -461,6 +474,7 @@ static int __init kmalloc_tests_init(void)
>         kmalloc_uaf2();
>         kmem_cache_oob();
>         kasan_stack_oob();
> +       kasan_stack_use_after_scope();
>         kasan_global_oob();
>         ksize_unpoisons_memory();
>         copy_user_test();
> --
> 2.11.0


I might be missing something, but my patch contained a test:

+static noinline void __init use_after_scope_test(void)
+{
+       volatile char *volatile p;
+
+       pr_info("use-after-scope on int\n");
+       {
+               int local = 0;
+
+               p = (char *)&local;
+       }
+       p[0] = 1;
+       p[3] = 1;
+
+       pr_info("use-after-scope on array\n");
+       {
+               char local[1024] = {0};
+
+               p = local;
+       }
+       p[0] = 1;
+       p[1023] = 1;
+}
+

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

* Re: [PATCH] kasan: add test for -fsanitize-address-use-after-scope
  2016-12-05 14:16 [PATCH] kasan: add test for -fsanitize-address-use-after-scope Jiri Slaby
  2016-12-05 14:20 ` Dmitry Vyukov
@ 2016-12-05 14:20 ` Jiri Slaby
  1 sibling, 0 replies; 3+ messages in thread
From: Jiri Slaby @ 2016-12-05 14:20 UTC (permalink / raw)
  To: akpm; +Cc: dvyukov, linux-kernel, marxin

On 12/05/2016, 03:16 PM, Jiri Slaby wrote:
> From: marxin <mliska@suse.cz>
> 
> In commit 828347f8f9a5 ("kasan: support use-after-scope detection") we
> added support for use-after-scope. Let's add a check if it actually
> works.

Nah, scratch that, 828347f8f9a5 added also a test which I overlooked.

thanks,
-- 
js
suse labs

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

end of thread, other threads:[~2016-12-05 14:27 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-12-05 14:16 [PATCH] kasan: add test for -fsanitize-address-use-after-scope Jiri Slaby
2016-12-05 14:20 ` Dmitry Vyukov
2016-12-05 14:20 ` Jiri Slaby

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).