From: Pekka Enberg <penberg@kernel.org>
To: torvalds@linux-founation.org
Cc: linux-kernel@vger.kernel.org, Pekka Enberg <penberg@kernel.org>,
Christoph Lameter <cl@linux.com>,
David Rientjes <rientjes@google.com>
Subject: [PATCH 1/2] SLUB: Fix merged slab cache names
Date: Tue, 14 Sep 2010 20:06:03 +0300 [thread overview]
Message-ID: <1284483964-2370-1-git-send-email-penberg@kernel.org> (raw)
As explained by Linus "I'm Proud to be an American" Torvalds:
Looking at the merging code, I actually think it's totally
buggy. If you have something like this:
- load module A: create slab cache A
- load module B: create slab cache B that can merge with A
- unload module A
- "cat /proc/slabinfo": BOOM. Oops.
exactly because the name is not handled correctly, and you'll have
module B holding open a slab cache that has a name pointer that points
to module A that no longer exists.
This patch fixes the problem by introducing a SLAB_DYNAMIC_NAME flag and using
kstrdup() to allocate memory when reference count is bumped up.
Cc: Christoph Lameter <cl@linux.com>
Cc: David Rientjes <rientjes@google.com>
Reported-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
---
include/linux/slab.h | 2 ++
mm/slub.c | 15 +++++++++++++++
2 files changed, 17 insertions(+), 0 deletions(-)
diff --git a/include/linux/slab.h b/include/linux/slab.h
index 59260e2..df201cf 100644
--- a/include/linux/slab.h
+++ b/include/linux/slab.h
@@ -76,6 +76,8 @@
# define SLAB_FAILSLAB 0x00000000UL
#endif
+#define SLAB_DYNAMIC_NAME 0x04000000UL /* s->name is kmalloc()'d */
+
/* The following flags affect the page allocator grouping pages by mobility */
#define SLAB_RECLAIM_ACCOUNT 0x00020000UL /* Objects are reclaimable */
#define SLAB_TEMPORARY SLAB_RECLAIM_ACCOUNT /* Objects are short-lived */
diff --git a/mm/slub.c b/mm/slub.c
index 13fffe1..0704288 100644
--- a/mm/slub.c
+++ b/mm/slub.c
@@ -210,6 +210,9 @@ static inline int sysfs_slab_alias(struct kmem_cache *s, const char *p)
{ return 0; }
static inline void sysfs_slab_remove(struct kmem_cache *s)
{
+ if (s->flags & SLAB_DYNAMIC_NAME)
+ kfree(s->name);
+
kfree(s);
}
@@ -3218,6 +3221,18 @@ struct kmem_cache *kmem_cache_create(const char *name, size_t size,
down_write(&slub_lock);
s = find_mergeable(size, align, flags, name, ctor);
if (s) {
+ if (!(s->flags & SLAB_DYNAMIC_NAME)) {
+ const char *new_name;
+
+ new_name = kstrdup(s->name, GFP_KERNEL);
+ if (!new_name)
+ goto err;
+
+ s->name = new_name;
+
+ s->flags |= SLAB_DYNAMIC_NAME;
+ }
+
s->refcount++;
/*
* Adjust the object sizes so that we clear
--
1.6.3.3
next reply other threads:[~2010-09-14 17:06 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-09-14 17:06 Pekka Enberg [this message]
2010-09-14 17:06 ` [PATCH 2/2] SLUB: Mark merged slab caches in /proc/slabinfo Pekka Enberg
2010-09-14 17:10 ` Pekka Enberg
2010-09-14 17:28 ` Christoph Lameter
2010-09-14 17:59 ` Pekka Enberg
2010-09-14 18:05 ` Linus Torvalds
2010-09-14 18:47 ` Pekka Enberg
2010-09-14 17:26 ` [PATCH 1/2] SLUB: Fix merged slab cache names Christoph Lameter
2010-09-14 17:36 ` Pekka Enberg
2010-09-14 17:47 ` Christoph Lameter
2010-09-14 17:49 ` Pekka Enberg
2010-09-14 17:59 ` Christoph Lameter
2010-09-14 18:02 ` Linus Torvalds
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=1284483964-2370-1-git-send-email-penberg@kernel.org \
--to=penberg@kernel.org \
--cc=cl@linux.com \
--cc=linux-kernel@vger.kernel.org \
--cc=rientjes@google.com \
--cc=torvalds@linux-founation.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