linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH mm-unstable] mm/kasan: use SLAB_NO_MERGE flag instead of an empty constructor
@ 2025-03-18  1:59 Harry Yoo
  2025-03-18  9:56 ` Alexander Potapenko
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Harry Yoo @ 2025-03-18  1:59 UTC (permalink / raw)
  To: Andrey Ryabinin
  Cc: Alexander Potapenko, Andrey Konovalov, Dmitry Vyukov,
	Vincenzo Frascino, Andrew Morton, kasan-dev, linux-mm,
	linux-kernel, Harry Yoo

Use SLAB_NO_MERGE flag to prevent merging instead of providing an
empty constructor. Using an empty constructor in this manner is an abuse
of slab interface.

The SLAB_NO_MERGE flag should be used with caution, but in this case,
it is acceptable as the cache is intended solely for debugging purposes.

No functional changes intended.

Signed-off-by: Harry Yoo <harry.yoo@oracle.com>
---
 mm/kasan/kasan_test_c.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/mm/kasan/kasan_test_c.c b/mm/kasan/kasan_test_c.c
index 59d673400085..3ea317837c2d 100644
--- a/mm/kasan/kasan_test_c.c
+++ b/mm/kasan/kasan_test_c.c
@@ -1073,14 +1073,11 @@ static void kmem_cache_rcu_uaf(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;
 
-	/* Provide a constructor to prevent cache merging. */
-	cache = kmem_cache_create("test_cache", 200, 0, 0, empty_cache_ctor);
+	cache = kmem_cache_create("test_cache", 200, 0, SLAB_NO_MERGE, NULL);
 	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, cache);
 	kmem_cache_destroy(cache);
 	KUNIT_EXPECT_KASAN_FAIL(test, kmem_cache_destroy(cache));
-- 
2.43.0



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

* Re: [PATCH mm-unstable] mm/kasan: use SLAB_NO_MERGE flag instead of an empty constructor
  2025-03-18  1:59 [PATCH mm-unstable] mm/kasan: use SLAB_NO_MERGE flag instead of an empty constructor Harry Yoo
@ 2025-03-18  9:56 ` Alexander Potapenko
  2025-03-18 15:32 ` Andrey Konovalov
  2025-03-20 16:44 ` Andrey Ryabinin
  2 siblings, 0 replies; 4+ messages in thread
From: Alexander Potapenko @ 2025-03-18  9:56 UTC (permalink / raw)
  To: Harry Yoo
  Cc: Andrey Ryabinin, Andrey Konovalov, Dmitry Vyukov,
	Vincenzo Frascino, Andrew Morton, kasan-dev, linux-mm,
	linux-kernel

On Tue, Mar 18, 2025 at 2:59 AM Harry Yoo <harry.yoo@oracle.com> wrote:
>
> Use SLAB_NO_MERGE flag to prevent merging instead of providing an
> empty constructor. Using an empty constructor in this manner is an abuse
> of slab interface.

This code predated the existence of SLAB_NO_MERGE. Thanks for fixing this!

>
> Signed-off-by: Harry Yoo <harry.yoo@oracle.com>

Reviewed-by: Alexander Potapenko <glider@google.com>


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

* Re: [PATCH mm-unstable] mm/kasan: use SLAB_NO_MERGE flag instead of an empty constructor
  2025-03-18  1:59 [PATCH mm-unstable] mm/kasan: use SLAB_NO_MERGE flag instead of an empty constructor Harry Yoo
  2025-03-18  9:56 ` Alexander Potapenko
@ 2025-03-18 15:32 ` Andrey Konovalov
  2025-03-20 16:44 ` Andrey Ryabinin
  2 siblings, 0 replies; 4+ messages in thread
From: Andrey Konovalov @ 2025-03-18 15:32 UTC (permalink / raw)
  To: Harry Yoo
  Cc: Andrey Ryabinin, Alexander Potapenko, Dmitry Vyukov,
	Vincenzo Frascino, Andrew Morton, kasan-dev, linux-mm,
	linux-kernel

On Tue, Mar 18, 2025 at 2:59 AM Harry Yoo <harry.yoo@oracle.com> wrote:
>
> Use SLAB_NO_MERGE flag to prevent merging instead of providing an
> empty constructor. Using an empty constructor in this manner is an abuse
> of slab interface.
>
> The SLAB_NO_MERGE flag should be used with caution, but in this case,
> it is acceptable as the cache is intended solely for debugging purposes.
>
> No functional changes intended.
>
> Signed-off-by: Harry Yoo <harry.yoo@oracle.com>
> ---
>  mm/kasan/kasan_test_c.c | 5 +----
>  1 file changed, 1 insertion(+), 4 deletions(-)
>
> diff --git a/mm/kasan/kasan_test_c.c b/mm/kasan/kasan_test_c.c
> index 59d673400085..3ea317837c2d 100644
> --- a/mm/kasan/kasan_test_c.c
> +++ b/mm/kasan/kasan_test_c.c
> @@ -1073,14 +1073,11 @@ static void kmem_cache_rcu_uaf(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;
>
> -       /* Provide a constructor to prevent cache merging. */
> -       cache = kmem_cache_create("test_cache", 200, 0, 0, empty_cache_ctor);
> +       cache = kmem_cache_create("test_cache", 200, 0, SLAB_NO_MERGE, NULL);
>         KUNIT_ASSERT_NOT_ERR_OR_NULL(test, cache);
>         kmem_cache_destroy(cache);
>         KUNIT_EXPECT_KASAN_FAIL(test, kmem_cache_destroy(cache));
> --
> 2.43.0
>

Reviewed-by: Andrey Konovalov <andreyknvl@gmail.com>

Thanks!


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

* Re: [PATCH mm-unstable] mm/kasan: use SLAB_NO_MERGE flag instead of an empty constructor
  2025-03-18  1:59 [PATCH mm-unstable] mm/kasan: use SLAB_NO_MERGE flag instead of an empty constructor Harry Yoo
  2025-03-18  9:56 ` Alexander Potapenko
  2025-03-18 15:32 ` Andrey Konovalov
@ 2025-03-20 16:44 ` Andrey Ryabinin
  2 siblings, 0 replies; 4+ messages in thread
From: Andrey Ryabinin @ 2025-03-20 16:44 UTC (permalink / raw)
  To: Harry Yoo
  Cc: Alexander Potapenko, Andrey Konovalov, Dmitry Vyukov,
	Vincenzo Frascino, Andrew Morton, kasan-dev, linux-mm,
	linux-kernel

On Tue, Mar 18, 2025 at 2:59 AM Harry Yoo <harry.yoo@oracle.com> wrote:
>
> Use SLAB_NO_MERGE flag to prevent merging instead of providing an
> empty constructor. Using an empty constructor in this manner is an abuse
> of slab interface.
>
> The SLAB_NO_MERGE flag should be used with caution, but in this case,
> it is acceptable as the cache is intended solely for debugging purposes.
>
> No functional changes intended.
>
> Signed-off-by: Harry Yoo <harry.yoo@oracle.com>

Acked-by: Andrey Ryabinin <ryabinin.a.a@gmail.com>


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

end of thread, other threads:[~2025-03-20 16:44 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-03-18  1:59 [PATCH mm-unstable] mm/kasan: use SLAB_NO_MERGE flag instead of an empty constructor Harry Yoo
2025-03-18  9:56 ` Alexander Potapenko
2025-03-18 15:32 ` Andrey Konovalov
2025-03-20 16:44 ` Andrey Ryabinin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox