* [PATCH] lkdtm: use SLAB_NO_MERGE instead of an empty constructor
@ 2025-03-18 1:45 Harry Yoo
2025-04-09 14:13 ` Harry Yoo
2025-04-09 16:15 ` Kees Cook
0 siblings, 2 replies; 3+ messages in thread
From: Harry Yoo @ 2025-03-18 1:45 UTC (permalink / raw)
To: Kees Cook; +Cc: 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 soley for debugging purposes.
No functional changes intended.
Signed-off-by: Harry Yoo <harry.yoo@oracle.com>
---
drivers/misc/lkdtm/heap.c | 17 +++--------------
1 file changed, 3 insertions(+), 14 deletions(-)
diff --git a/drivers/misc/lkdtm/heap.c b/drivers/misc/lkdtm/heap.c
index b1b316f99703..c1a05b935894 100644
--- a/drivers/misc/lkdtm/heap.c
+++ b/drivers/misc/lkdtm/heap.c
@@ -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)
--
2.43.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] lkdtm: use SLAB_NO_MERGE instead of an empty constructor
2025-03-18 1:45 [PATCH] lkdtm: use SLAB_NO_MERGE instead of an empty constructor Harry Yoo
@ 2025-04-09 14:13 ` Harry Yoo
2025-04-09 16:15 ` Kees Cook
1 sibling, 0 replies; 3+ messages in thread
From: Harry Yoo @ 2025-04-09 14:13 UTC (permalink / raw)
To: Kees Cook; +Cc: linux-kernel
On Tue, Mar 18, 2025 at 10:45:33AM +0900, Harry Yoo 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 soley for debugging purposes.
>
> No functional changes intended.
>
> Signed-off-by: Harry Yoo <harry.yoo@oracle.com>
Kindly ping :)
--
Cheers,
Harry / Hyeonggon
> ---
> drivers/misc/lkdtm/heap.c | 17 +++--------------
> 1 file changed, 3 insertions(+), 14 deletions(-)
>
> diff --git a/drivers/misc/lkdtm/heap.c b/drivers/misc/lkdtm/heap.c
> index b1b316f99703..c1a05b935894 100644
> --- a/drivers/misc/lkdtm/heap.c
> +++ b/drivers/misc/lkdtm/heap.c
> @@ -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)
> --
> 2.43.0
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] lkdtm: use SLAB_NO_MERGE instead of an empty constructor
2025-03-18 1:45 [PATCH] lkdtm: use SLAB_NO_MERGE instead of an empty constructor Harry Yoo
2025-04-09 14:13 ` Harry Yoo
@ 2025-04-09 16:15 ` Kees Cook
1 sibling, 0 replies; 3+ messages in thread
From: Kees Cook @ 2025-04-09 16:15 UTC (permalink / raw)
To: Harry Yoo; +Cc: Kees Cook, linux-kernel
On Tue, 18 Mar 2025 10:45:33 +0900, Harry Yoo 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 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,
--
Kees Cook
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-04-09 16:15 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-03-18 1:45 [PATCH] lkdtm: use SLAB_NO_MERGE instead of an empty constructor Harry Yoo
2025-04-09 14:13 ` Harry Yoo
2025-04-09 16:15 ` Kees Cook
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox