linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/4] Refactor __kmem_cache_create() and fix memory leak
@ 2022-10-24  7:42 Liu Shixin
  2022-10-24  7:42 ` [PATCH 1/4] mm/slab_common: Move cache_name to create_cache() Liu Shixin
                   ` (3 more replies)
  0 siblings, 4 replies; 8+ messages in thread
From: Liu Shixin @ 2022-10-24  7:42 UTC (permalink / raw)
  To: Christoph Lameter, Pekka Enberg, David Rientjes, Joonsoo Kim,
	Andrew Morton, Vlastimil Babka, Roman Gushchin, Hyeonggon Yoo
  Cc: linux-mm, linux-kernel, Liu Shixin

I found a memory leak of kobj->name in sysfs_slab_add() which is introduced
by 80da026a8e5d ("mm/slub: fix slab double-free in case of duplicate sysfs filename").
Following the rules stated in the comment for kobject_init_and_add():

 If this function returns an error, kobject_put() must be called to
 properly clean up the memory associated with the object.

We should use kobject_put() to free kobject.

But we can't simply add kobject_put() since it will free kmem_cache too.
If we use kobject_put(), we need to skip other release functions.

In this series, We refactor the code to separate sysfs_slab_add() and
debugfs_slab_add() from __kmem_cache_create(), and then use kobject_put()
to free kobject in sysfs_slab_add(). This can fix the memory leak of
kobject->name.

Liu Shixin (4):
  mm/slab_common: Move cache_name to create_cache()
  mm/slub: rename kmem_cache_release to slab_release in slub.c
  mm/slab_common: Separate sysfs_slab_add() and debugfs_slab_add() from
    __kmem_cache_create()
  mm/slab_common: Fix memory leak of kobj->name in sysfs_slab_add()

 include/linux/slub_def.h | 11 ++++++++
 mm/slab_common.c         | 42 ++++++++++++++++--------------
 mm/slub.c                | 56 +++++++++++-----------------------------
 3 files changed, 48 insertions(+), 61 deletions(-)

-- 
2.25.1



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

end of thread, other threads:[~2022-10-25  8:02 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-24  7:42 [PATCH 0/4] Refactor __kmem_cache_create() and fix memory leak Liu Shixin
2022-10-24  7:42 ` [PATCH 1/4] mm/slab_common: Move cache_name to create_cache() Liu Shixin
2022-10-24  7:42 ` [PATCH 2/4] mm/slub: rename kmem_cache_release to slab_release in slub.c Liu Shixin
2022-10-24  7:42 ` [PATCH 3/4] mm/slab_common: Separate sysfs_slab_add() and debugfs_slab_add() from __kmem_cache_create() Liu Shixin
2022-10-24  8:16   ` kernel test robot
2022-10-24 20:23   ` kernel test robot
2022-10-25  8:01   ` kernel test robot
2022-10-24  7:42 ` [PATCH 4/4] mm/slab_common: Fix memory leak of kobj->name in sysfs_slab_add() Liu Shixin

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