From: Catalin Marinas <catalin.marinas@arm.com>
To: Christoph Lameter <cl@linux-foundation.org>
Cc: linux-kernel <linux-kernel@vger.kernel.org>
Subject: Possible memory leak via slub kmem_cache_create
Date: Wed, 19 Nov 2008 16:25:54 +0000 [thread overview]
Message-ID: <1227111954.27162.28.camel@pc1117.cambridge.arm.com> (raw)
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
next reply other threads:[~2008-11-19 16:51 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-11-19 16:25 Catalin Marinas [this message]
2008-11-19 19:22 ` Christoph Lameter
2008-11-20 9:51 ` Catalin Marinas
2008-11-20 11:04 ` Arnaldo Carvalho de Melo
2008-11-20 18:14 ` Christoph Lameter
2008-11-20 18:45 ` Pekka Enberg
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1227111954.27162.28.camel@pc1117.cambridge.arm.com \
--to=catalin.marinas@arm.com \
--cc=cl@linux-foundation.org \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®