Commit bbd7d57b authored by Eric Dumazet's avatar Eric Dumazet Committed by Pekka Enberg

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 ...

Switch these allocations to dynamic allocations.
Signed-off-by: default avatarEric Dumazet <eric.dumazet@gmail.com>
Signed-off-by: default avatarChristoph Lameter <cl@linux-foundation.org>
Signed-off-by: default avatarPekka Enberg <penberg@cs.helsinki.fi>
parent e40152ee
...@@ -2429,9 +2429,11 @@ static void list_slab_objects(struct kmem_cache *s, struct page *page, ...@@ -2429,9 +2429,11 @@ static void list_slab_objects(struct kmem_cache *s, struct page *page,
#ifdef CONFIG_SLUB_DEBUG #ifdef CONFIG_SLUB_DEBUG
void *addr = page_address(page); void *addr = page_address(page);
void *p; 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_err(s, page, "%s", text);
slab_lock(page); slab_lock(page);
for_each_free_object(p, s, page->freelist) for_each_free_object(p, s, page->freelist)
...@@ -2446,6 +2448,7 @@ static void list_slab_objects(struct kmem_cache *s, struct page *page, ...@@ -2446,6 +2448,7 @@ static void list_slab_objects(struct kmem_cache *s, struct page *page,
} }
} }
slab_unlock(page); slab_unlock(page);
kfree(map);
#endif #endif
} }
...@@ -3651,10 +3654,10 @@ static int add_location(struct loc_track *t, struct kmem_cache *s, ...@@ -3651,10 +3654,10 @@ static int add_location(struct loc_track *t, struct kmem_cache *s,
} }
static void process_slab(struct loc_track *t, struct kmem_cache *s, static void process_slab(struct loc_track *t, struct kmem_cache *s,
struct page *page, enum track_item alloc) struct page *page, enum track_item alloc,
long *map)
{ {
void *addr = page_address(page); void *addr = page_address(page);
DECLARE_BITMAP(map, page->objects);
void *p; void *p;
bitmap_zero(map, page->objects); bitmap_zero(map, page->objects);
...@@ -3673,11 +3676,14 @@ static int list_locations(struct kmem_cache *s, char *buf, ...@@ -3673,11 +3676,14 @@ static int list_locations(struct kmem_cache *s, char *buf,
unsigned long i; unsigned long i;
struct loc_track t = { 0, 0, NULL }; struct loc_track t = { 0, 0, NULL };
int node; int node;
unsigned long *map = kmalloc(BITS_TO_LONGS(oo_objects(s->max)) *
sizeof(unsigned long), GFP_KERNEL);
if (!alloc_loc_track(&t, PAGE_SIZE / sizeof(struct location), if (!map || !alloc_loc_track(&t, PAGE_SIZE / sizeof(struct location),
GFP_TEMPORARY)) GFP_TEMPORARY)) {
kfree(map);
return sprintf(buf, "Out of memory\n"); return sprintf(buf, "Out of memory\n");
}
/* Push back cpu slabs */ /* Push back cpu slabs */
flush_all(s); flush_all(s);
...@@ -3691,9 +3697,9 @@ static int list_locations(struct kmem_cache *s, char *buf, ...@@ -3691,9 +3697,9 @@ static int list_locations(struct kmem_cache *s, char *buf,
spin_lock_irqsave(&n->list_lock, flags); spin_lock_irqsave(&n->list_lock, flags);
list_for_each_entry(page, &n->partial, lru) list_for_each_entry(page, &n->partial, lru)
process_slab(&t, s, page, alloc); process_slab(&t, s, page, alloc, map);
list_for_each_entry(page, &n->full, lru) list_for_each_entry(page, &n->full, lru)
process_slab(&t, s, page, alloc); process_slab(&t, s, page, alloc, map);
spin_unlock_irqrestore(&n->list_lock, flags); spin_unlock_irqrestore(&n->list_lock, flags);
} }
...@@ -3744,6 +3750,7 @@ static int list_locations(struct kmem_cache *s, char *buf, ...@@ -3744,6 +3750,7 @@ static int list_locations(struct kmem_cache *s, char *buf,
} }
free_loc_track(&t); free_loc_track(&t);
kfree(map);
if (!t.count) if (!t.count)
len += sprintf(buf, "No data\n"); len += sprintf(buf, "No data\n");
return len; return len;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment