Skip to content

Commit 77ced98

Browse files
shroffnitehcaster
authored andcommitted
mm, slab: fix use of SLAB_SUPPORTS_SYSFS in kmem_cache_release()
The fix implemented in commit 4ec1026 ("mm, slab: unlink slabinfo, sysfs and debugfs immediately") caused a subtle side effect due to which while destroying the kmem cache, the code path would never get into sysfs_slab_release() function even though SLAB_SUPPORTS_SYSFS is defined and slab state is FULL. Due to this side effect, we would never release kobject defined for kmem cache and leak the associated memory. The issue here's with the use of __is_defined() macro in kmem_cache_ release(). The __is_defined() macro expands to __take_second_arg( arg1_or_junk 1, 0). If "arg1_or_junk" is defined to 1 then it expands to __take_second_arg(0, 1, 0) and returns 1. If "arg1_or_junk" is NOT defined to any value then it expands to __take_second_arg(... 1, 0) and returns 0. In this particular issue, SLAB_SUPPORTS_SYSFS is defined without any associated value and that causes __is_defined(SLAB_SUPPORTS_SYSFS) to always evaluate to 0 and hence it would never invoke sysfs_slab_release(). This patch helps fix this issue by defining SLAB_SUPPORTS_SYSFS to 1. Fixes: 4ec1026 ("mm, slab: unlink slabinfo, sysfs and debugfs immediately") Reported-by: Yi Zhang <[email protected]> Closes: https://lore.kernel.org/all/CAHj4cs9YCCcfmdxN43-9H3HnTYQsRtTYw1Kzq-L468GfLKAENA@mail.gmail.com/ Signed-off-by: Nilay Shroff <[email protected]> Reviewed-by: Hyeonggon Yoo <[email protected]> Tested-by: Yi Zhang <[email protected]> Signed-off-by: Vlastimil Babka <[email protected]>
1 parent 9852d85 commit 77ced98

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

mm/slab.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ struct kmem_cache {
310310
};
311311

312312
#if defined(CONFIG_SYSFS) && !defined(CONFIG_SLUB_TINY)
313-
#define SLAB_SUPPORTS_SYSFS
313+
#define SLAB_SUPPORTS_SYSFS 1
314314
void sysfs_slab_unlink(struct kmem_cache *s);
315315
void sysfs_slab_release(struct kmem_cache *s);
316316
#else

0 commit comments

Comments
 (0)