Skip to contentSkip to conversation

lkdtm: use SLAB_NO_MERGE instead of an empty constructor

PATCH Applied Harry Yoo 2 participants 3 messages Mar 18, 2025 – Apr 9, 2025

Subsystems (2)
lore
Share & tools
lore

Harry Yoo

author
#0 lore raw

PATCH 1/1 lkdtm: use SLAB_NO_MERGE instead of an empty constructor

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 soley for debugging purposes.

No functional changes intended.

---
 drivers/misc/lkdtm/heap.c | 17 +++--------------
 1 file changed, 3 insertions(+), 14 deletions(-)
drivers/misc/lkdtm/heap.c +3 -14
index b1b316f99703..c1a05b935894 100644
@@ -355,23 +355,12 @@ static void lkdtm_SLAB_FREE_PAGE(void)
 	free_page(p);
 }
 
-/*
- * We have constructors to keep the caches distinctly separated without
- * needing to boot with "slab_nomerge".
- */
-static void ctor_double_free(void *region)
-{ }
-static void ctor_a(void *region)
-{ }
-static void ctor_b(void *region)
-{ }
-
 void __init lkdtm_heap_init(void)
 {
 	double_free_cache = kmem_cache_create("lkdtm-heap-double_free",
-					      64, 0, 0, ctor_double_free);
-	a_cache = kmem_cache_create("lkdtm-heap-a", 64, 0, 0, ctor_a);
-	b_cache = kmem_cache_create("lkdtm-heap-b", 64, 0, 0, ctor_b);
+					      64, 0, SLAB_NO_MERGE, NULL);
+	a_cache = kmem_cache_create("lkdtm-heap-a", 64, 0, SLAB_NO_MERGE, NULL);
+	b_cache = kmem_cache_create("lkdtm-heap-b", 64, 0, SLAB_NO_MERGE, NULL);
 }
 
 void __exit lkdtm_heap_exit(void)
Signature · 1 line
2.43.0
author
#1 lore raw
Quoted 10 lines · 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 soley for debugging purposes.

No functional changes intended.

Kindly ping :)

Signature · 2 lines
Cheers,
Harry / Hyeonggon
Quoted 38 lines
---
 drivers/misc/lkdtm/heap.c | 17 +++--------------
 1 file changed, 3 insertions(+), 14 deletions(-)
drivers/misc/lkdtm/heap.c +3 -14
index b1b316f99703..c1a05b935894 100644
@@ -355,23 +355,12 @@ static void lkdtm_SLAB_FREE_PAGE(void)
 	free_page(p);
 }
 
-/*
- * We have constructors to keep the caches distinctly separated without
- * needing to boot with "slab_nomerge".
- */
-static void ctor_double_free(void *region)
-{ }
-static void ctor_a(void *region)
-{ }
-static void ctor_b(void *region)
-{ }
-
 void __init lkdtm_heap_init(void)
 {
 	double_free_cache = kmem_cache_create("lkdtm-heap-double_free",
-					      64, 0, 0, ctor_double_free);
-	a_cache = kmem_cache_create("lkdtm-heap-a", 64, 0, 0, ctor_a);
-	b_cache = kmem_cache_create("lkdtm-heap-b", 64, 0, 0, ctor_b);
+					      64, 0, SLAB_NO_MERGE, NULL);
+	a_cache = kmem_cache_create("lkdtm-heap-a", 64, 0, SLAB_NO_MERGE, NULL);
+	b_cache = kmem_cache_create("lkdtm-heap-b", 64, 0, SLAB_NO_MERGE, NULL);
 }
 
 void __exit lkdtm_heap_exit(void)
Signature · 1 line
2.43.0
maintainer Applied
#2 lore raw
In reply to Harry Yoo
Quoted 8 lines · 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 soley for debugging purposes.

[...]

Applied to for-next/hardening, thanks!

[1/1] lkdtm: use SLAB_NO_MERGE instead of an empty constructor

      https://git.kernel.org/kees/c/9891398efae8

Take care,

Signature · 1 line
Kees Cook