All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andrey Ryabinin <aryabinin@virtuozzo.com>
To: Alexander Potapenko <glider@google.com>,
	adech.fo@gmail.com, dvyukov@google.com, cl@linux.com,
	akpm@linux-foundation.org, kcc@google.com
Cc: kasan-dev@googlegroups.com, linux-kernel@vger.kernel.org,
	linux-mm@kvack.org
Subject: Re: [PATCH v2 2/2] mm, kasan: add a ksize() test
Date: Fri, 15 Apr 2016 18:59:25 +0300	[thread overview]
Message-ID: <57110FDD.4070900@virtuozzo.com> (raw)
In-Reply-To: <562d43518232cf7d26297ee004255a083b084071.1460545373.git.glider@google.com>



On 04/13/2016 02:20 PM, Alexander Potapenko wrote:
> Add a test that makes sure ksize() unpoisons the whole chunk.
> 
> Signed-off-by: Alexander Potapenko <glider@google.com>

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

> ---
> v2: - splitted v1 into two patches
> ---
>  lib/test_kasan.c | 20 ++++++++++++++++++++
>  1 file changed, 20 insertions(+)
> 
> diff --git a/lib/test_kasan.c b/lib/test_kasan.c
> index 82169fb..48e5a0b 100644
> --- a/lib/test_kasan.c
> +++ b/lib/test_kasan.c
> @@ -344,6 +344,25 @@ static noinline void __init kasan_stack_oob(void)
>  	*(volatile char *)p;
>  }
>  
> +static noinline void __init ksize_unpoisons_memory(void)
> +{
> +	char *ptr;
> +	size_t size = 123, real_size = size;
> +
> +	pr_info("ksize() unpoisons the whole allocated chunk\n");
> +	ptr = kmalloc(size, GFP_KERNEL);
> +	if (!ptr) {
> +		pr_err("Allocation failed\n");
> +		return;
> +	}
> +	real_size = ksize(ptr);
> +	/* This access doesn't trigger an error. */
> +	ptr[size] = 'x';
> +	/* This one does. */
> +	ptr[real_size] = 'y';
> +	kfree(ptr);
> +}
> +
>  static int __init kmalloc_tests_init(void)
>  {
>  	kmalloc_oob_right();
> @@ -367,6 +386,7 @@ static int __init kmalloc_tests_init(void)
>  	kmem_cache_oob();
>  	kasan_stack_oob();
>  	kasan_global_oob();
> +	ksize_unpoisons_memory();
>  	return -EAGAIN;
>  }
>  
> 

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

WARNING: multiple messages have this Message-ID (diff)
From: Andrey Ryabinin <aryabinin@virtuozzo.com>
To: Alexander Potapenko <glider@google.com>, <adech.fo@gmail.com>,
	<dvyukov@google.com>, <cl@linux.com>, <akpm@linux-foundation.org>,
	<kcc@google.com>
Cc: <kasan-dev@googlegroups.com>, <linux-kernel@vger.kernel.org>,
	<linux-mm@kvack.org>
Subject: Re: [PATCH v2 2/2] mm, kasan: add a ksize() test
Date: Fri, 15 Apr 2016 18:59:25 +0300	[thread overview]
Message-ID: <57110FDD.4070900@virtuozzo.com> (raw)
In-Reply-To: <562d43518232cf7d26297ee004255a083b084071.1460545373.git.glider@google.com>



On 04/13/2016 02:20 PM, Alexander Potapenko wrote:
> Add a test that makes sure ksize() unpoisons the whole chunk.
> 
> Signed-off-by: Alexander Potapenko <glider@google.com>

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

> ---
> v2: - splitted v1 into two patches
> ---
>  lib/test_kasan.c | 20 ++++++++++++++++++++
>  1 file changed, 20 insertions(+)
> 
> diff --git a/lib/test_kasan.c b/lib/test_kasan.c
> index 82169fb..48e5a0b 100644
> --- a/lib/test_kasan.c
> +++ b/lib/test_kasan.c
> @@ -344,6 +344,25 @@ static noinline void __init kasan_stack_oob(void)
>  	*(volatile char *)p;
>  }
>  
> +static noinline void __init ksize_unpoisons_memory(void)
> +{
> +	char *ptr;
> +	size_t size = 123, real_size = size;
> +
> +	pr_info("ksize() unpoisons the whole allocated chunk\n");
> +	ptr = kmalloc(size, GFP_KERNEL);
> +	if (!ptr) {
> +		pr_err("Allocation failed\n");
> +		return;
> +	}
> +	real_size = ksize(ptr);
> +	/* This access doesn't trigger an error. */
> +	ptr[size] = 'x';
> +	/* This one does. */
> +	ptr[real_size] = 'y';
> +	kfree(ptr);
> +}
> +
>  static int __init kmalloc_tests_init(void)
>  {
>  	kmalloc_oob_right();
> @@ -367,6 +386,7 @@ static int __init kmalloc_tests_init(void)
>  	kmem_cache_oob();
>  	kasan_stack_oob();
>  	kasan_global_oob();
> +	ksize_unpoisons_memory();
>  	return -EAGAIN;
>  }
>  
> 

  reply	other threads:[~2016-04-15 15:59 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-04-13 11:20 [PATCH v2 1/2] mm, kasan: don't call kasan_krealloc() from ksize() Alexander Potapenko
2016-04-13 11:20 ` Alexander Potapenko
2016-04-13 11:20 ` [PATCH v2 2/2] mm, kasan: add a ksize() test Alexander Potapenko
2016-04-13 11:20   ` Alexander Potapenko
2016-04-15 15:59   ` Andrey Ryabinin [this message]
2016-04-15 15:59     ` Andrey Ryabinin
2016-04-15 15:58 ` [PATCH v2 1/2] mm, kasan: don't call kasan_krealloc() from ksize() Andrey Ryabinin
2016-04-15 15:58   ` Andrey Ryabinin
2016-04-22 21:32 ` Andrew Morton
2016-04-22 21:32   ` Andrew Morton
2016-04-28 11:31   ` Alexander Potapenko
2016-04-28 11:31     ` Alexander Potapenko

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=57110FDD.4070900@virtuozzo.com \
    --to=aryabinin@virtuozzo.com \
    --cc=adech.fo@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=cl@linux.com \
    --cc=dvyukov@google.com \
    --cc=glider@google.com \
    --cc=kasan-dev@googlegroups.com \
    --cc=kcc@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.