lkml.org 
[lkml]   [2008]   [Nov]   [19]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
SubjectPossible memory leak via slub kmem_cache_create
From
Date
Hi Cristoph,

I've recently worked on reviving kmemleak (to be posted on LKML this
week) and tried the slub allocator. I got the following report of orphan
objects:

unreferenced object 0xdf80f180 (size 32):
comm "swapper", pid 1, jiffies 4294937343
backtrace:
[<c0082f44>] memleak_alloc
[<c0080ff0>] __kmalloc
[<c019edac>] proto_register
[<c001640c>] inet_init
[<c001e30c>] do_one_initcall
[<c0008400>] kernel_init
[<c0035aa8>] do_exit
[<ffffffff>]
unreferenced object 0xdf800840 (size 16):
comm "swapper", pid 1, jiffies 4294937343
backtrace:
[<c0082f44>] memleak_alloc
[<c0080ff0>] __kmalloc
[<c019ee3c>] proto_register
[<c001640c>] inet_init
[<c001e30c>] do_one_initcall
[<c0008400>] kernel_init
[<c0035aa8>] do_exit
[<ffffffff>]

The proto_register() function in net/core/sock.c allocates
request_sock_slab_name and timewait_sock_slab_name to generate the cache
names passed to kmem_cache_create(). However, this function in mm/slub.c
goes on the find_mergeable() route and doesn't update s->name to the
previously allocated pointers. Therefore, kmemleak reports them as
orphan.

It could be worse since proto_unregister() tries to free these pointers
but they don't actually point to the allocated blocks because of the
merging.

A solution could be to pass one of the SLUB_NEVER_MERGE bits to
kmem_cache_create in proto_register(), though none of them has any
meaning for this situation. Otherwise, maybe defining another bit like
SLAB_ALLOCATED_NAME to ensure that kmem_cache_name() returns the same
value.

Or just simplify proto_register() to no longer allocate memory for these
names and it should be stated somewhere that kmem_cache_create() doesn't
necessarily saves the pointer to the name.

Thanks.

--
Catalin



\
 
 \ /
  Last update: 2008-11-19 17:53    [W:0.067 / U:0.772 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site