Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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.

Signed-off-by: Harry Yoo <harry.yoo@oracle.com>
Link: https://lore.kernel.org/r/20250318014533.1624852-1-harry.yoo@oracle.com
Signed-off-by: Kees Cook <kees@kernel.org>

authored by

Harry Yoo and committed by
Kees Cook
28cd28a7 b4432656

+3 -14
+3 -14
drivers/misc/lkdtm/heap.c
··· 355 355 free_page(p); 356 356 } 357 357 358 - /* 359 - * We have constructors to keep the caches distinctly separated without 360 - * needing to boot with "slab_nomerge". 361 - */ 362 - static void ctor_double_free(void *region) 363 - { } 364 - static void ctor_a(void *region) 365 - { } 366 - static void ctor_b(void *region) 367 - { } 368 - 369 358 void __init lkdtm_heap_init(void) 370 359 { 371 360 double_free_cache = kmem_cache_create("lkdtm-heap-double_free", 372 - 64, 0, 0, ctor_double_free); 373 - a_cache = kmem_cache_create("lkdtm-heap-a", 64, 0, 0, ctor_a); 374 - b_cache = kmem_cache_create("lkdtm-heap-b", 64, 0, 0, ctor_b); 361 + 64, 0, SLAB_NO_MERGE, NULL); 362 + a_cache = kmem_cache_create("lkdtm-heap-a", 64, 0, SLAB_NO_MERGE, NULL); 363 + b_cache = kmem_cache_create("lkdtm-heap-b", 64, 0, SLAB_NO_MERGE, NULL); 375 364 } 376 365 377 366 void __exit lkdtm_heap_exit(void)