linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] kasan: test: prevent cache merging in kmem_cache_double_destroy
@ 2022-02-08 18:37 andrey.konovalov
  2022-02-08 18:42 ` Marco Elver
  0 siblings, 1 reply; 2+ messages in thread
From: andrey.konovalov @ 2022-02-08 18:37 UTC (permalink / raw)
  To: Marco Elver, Andrew Morton
  Cc: Andrey Konovalov, Alexander Potapenko, Dmitry Vyukov,
	Andrey Ryabinin, kasan-dev, linux-mm, linux-kernel,
	Andrey Konovalov

From: Andrey Konovalov <andreyknvl@google.com>

With HW_TAGS KASAN and kasan.stacktrace=off, the cache created in the
kmem_cache_double_destroy() test might get merged with an existing one.
Thus, the first kmem_cache_destroy() call won't actually destroy it
but will only descrease the refcount. This causes the test to fail.

Provide an empty contructor for the created cache to prevent the cache
from getting merged.

Fixes: f98f966cd750 ("kasan: test: add test case for double-kmem_cache_destroy()")
Signed-off-by: Andrey Konovalov <andreyknvl@google.com>
---
 lib/test_kasan.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/lib/test_kasan.c b/lib/test_kasan.c
index 26a5c9007653..3b413f8c8a71 100644
--- a/lib/test_kasan.c
+++ b/lib/test_kasan.c
@@ -869,11 +869,14 @@ static void kmem_cache_invalid_free(struct kunit *test)
 	kmem_cache_destroy(cache);
 }
 
+static void empty_cache_ctor(void *object) { }
+
 static void kmem_cache_double_destroy(struct kunit *test)
 {
 	struct kmem_cache *cache;
 
-	cache = kmem_cache_create("test_cache", 200, 0, 0, NULL);
+	/* Provide a constructor to prevent cache merging. */
+	cache = kmem_cache_create("test_cache", 200, 0, 0, empty_cache_ctor);
 	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, cache);
 	kmem_cache_destroy(cache);
 	KUNIT_EXPECT_KASAN_FAIL(test, kmem_cache_destroy(cache));
-- 
2.25.1



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

* Re: [PATCH] kasan: test: prevent cache merging in kmem_cache_double_destroy
  2022-02-08 18:37 [PATCH] kasan: test: prevent cache merging in kmem_cache_double_destroy andrey.konovalov
@ 2022-02-08 18:42 ` Marco Elver
  0 siblings, 0 replies; 2+ messages in thread
From: Marco Elver @ 2022-02-08 18:42 UTC (permalink / raw)
  To: andrey.konovalov
  Cc: Andrew Morton, Andrey Konovalov, Alexander Potapenko,
	Dmitry Vyukov, Andrey Ryabinin, kasan-dev, linux-mm,
	linux-kernel, Andrey Konovalov

On Tue, 8 Feb 2022 at 19:37, <andrey.konovalov@linux.dev> wrote:
>
> From: Andrey Konovalov <andreyknvl@google.com>
>
> With HW_TAGS KASAN and kasan.stacktrace=off, the cache created in the
> kmem_cache_double_destroy() test might get merged with an existing one.
> Thus, the first kmem_cache_destroy() call won't actually destroy it
> but will only descrease the refcount. This causes the test to fail.

s/descrease/decrease/

> Provide an empty contructor for the created cache to prevent the cache

s/contructor/constructor/

> from getting merged.
>
> Fixes: f98f966cd750 ("kasan: test: add test case for double-kmem_cache_destroy()")
> Signed-off-by: Andrey Konovalov <andreyknvl@google.com>

Reviewed-by: Marco Elver <elver@google.com>


> ---
>  lib/test_kasan.c | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/lib/test_kasan.c b/lib/test_kasan.c
> index 26a5c9007653..3b413f8c8a71 100644
> --- a/lib/test_kasan.c
> +++ b/lib/test_kasan.c
> @@ -869,11 +869,14 @@ static void kmem_cache_invalid_free(struct kunit *test)
>         kmem_cache_destroy(cache);
>  }
>
> +static void empty_cache_ctor(void *object) { }
> +
>  static void kmem_cache_double_destroy(struct kunit *test)
>  {
>         struct kmem_cache *cache;
>
> -       cache = kmem_cache_create("test_cache", 200, 0, 0, NULL);
> +       /* Provide a constructor to prevent cache merging. */
> +       cache = kmem_cache_create("test_cache", 200, 0, 0, empty_cache_ctor);
>         KUNIT_ASSERT_NOT_ERR_OR_NULL(test, cache);
>         kmem_cache_destroy(cache);
>         KUNIT_EXPECT_KASAN_FAIL(test, kmem_cache_destroy(cache));
> --
> 2.25.1
>


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

end of thread, other threads:[~2022-02-08 18:42 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-08 18:37 [PATCH] kasan: test: prevent cache merging in kmem_cache_double_destroy andrey.konovalov
2022-02-08 18:42 ` Marco Elver

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