From: Eric Dumazet <eric.dumazet@gmail.com>
To: Christoph Lameter <cl@linux-foundation.org>
Cc: Pekka J Enberg <penberg@cs.helsinki.fi>,
linux-kernel <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] slub: Potential stack overflow
Date: Wed, 24 Mar 2010 22:03:11 +0100 [thread overview]
Message-ID: <1269464591.2849.15.camel@edumazet-laptop> (raw)
In-Reply-To: <alpine.DEB.2.00.1003241443520.14329@router.home>
Le mercredi 24 mars 2010 à 14:49 -0500, Christoph Lameter a écrit :
> On Wed, 24 Mar 2010, Eric Dumazet wrote:
>
> > Are we allowed to nest in these two functions ?
>
> This is kmem_cache_close() no danger of nesting.
>
> > These are debugging functions, what happens if kmalloc() returns NULL ?
>
> Then you return ENOMEM and the user gets an error. We already do that in
> validate_slab_cache().
>
> Hmmm... In this case we called from list_slab_objects() which gets called
> from free_partial() (which took a spinlock!) which gets called from
> kmem_cache_close().
>
> Its just a debugging aid so no problem if it fails. GFP_ATOMIC?
OK, here is second version of the patch, thanks !
[PATCH] slub: Potential stack overflow
I discovered that we can overflow stack if CONFIG_SLUB_DEBUG=y and use
slabs with many objects, since list_slab_objects() and process_slab()
use DECLARE_BITMAP(map, page->objects);
With 65535 bits, we use 8192 bytes of stack ...
A possible solution is to allocate memory, using GFP_ATOMIC, and do
nothing if allocation fails.
Signed-off-by: Eric Dumazet <eric.dumazet@gmail.com>
---
diff --git a/mm/slub.c b/mm/slub.c
index b364844..5ee857a 100644
--- a/mm/slub.c
+++ b/mm/slub.c
@@ -2426,9 +2426,11 @@ static void list_slab_objects(struct kmem_cache *s, struct page *page,
#ifdef CONFIG_SLUB_DEBUG
void *addr = page_address(page);
void *p;
- DECLARE_BITMAP(map, page->objects);
+ long *map = kzalloc(BITS_TO_LONGS(page->objects) * sizeof(long),
+ GFP_ATOMIC);
- bitmap_zero(map, page->objects);
+ if (!map)
+ return;
slab_err(s, page, "%s", text);
slab_lock(page);
for_each_free_object(p, s, page->freelist)
@@ -2443,6 +2445,7 @@ static void list_slab_objects(struct kmem_cache *s, struct page *page,
}
}
slab_unlock(page);
+ kfree(map);
#endif
}
@@ -3651,16 +3654,19 @@ static void process_slab(struct loc_track *t, struct kmem_cache *s,
struct page *page, enum track_item alloc)
{
void *addr = page_address(page);
- DECLARE_BITMAP(map, page->objects);
+ long *map = kzalloc(BITS_TO_LONGS(page->objects) * sizeof(long),
+ GFP_ATOMIC);
void *p;
- bitmap_zero(map, page->objects);
+ if (!map)
+ return;
for_each_free_object(p, s, page->freelist)
set_bit(slab_index(p, s, addr), map);
for_each_object(p, s, addr, page->objects)
if (!test_bit(slab_index(p, s, addr), map))
add_location(t, s, get_track(s, p, alloc));
+ kfree(map);
}
static int list_locations(struct kmem_cache *s, char *buf,
next prev parent reply other threads:[~2010-03-24 21:03 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-03-24 11:40 Eric Dumazet
2010-03-24 19:16 ` Christoph Lameter
2010-03-24 19:22 ` Eric Dumazet
2010-03-24 19:49 ` Christoph Lameter
2010-03-24 21:03 ` Eric Dumazet [this message]
2010-03-24 21:10 ` Christoph Lameter
2010-03-24 21:14 ` Christoph Lameter
2010-03-24 21:25 ` Christoph Lameter
2010-03-24 21:30 ` Eric Dumazet
2010-03-24 21:25 ` Eric Dumazet
2010-03-25 19:29 ` Pekka Enberg
2010-03-25 21:03 ` Christoph Lameter
2010-03-28 17:10 ` 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=1269464591.2849.15.camel@edumazet-laptop \
--to=eric.dumazet@gmail.com \
--cc=cl@linux-foundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=penberg@cs.helsinki.fi \
/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®