Le jeudi 12 janvier 2012 à 15:30 -0800, [email protected] a écrit :
> The patch below does not apply to the 3.0-stable tree.
> If someone wants it applied there, or to any other stable or longterm
> tree, then please email the backport, including the original git commit
> id to <[email protected]>.
> 
> thanks,
> 
> greg k-h
> 
> ------------------ original commit in Linus's tree ------------------
> 
> From 73736e0387ba0e6d2b703407b4d26168d31516a7 Mon Sep 17 00:00:00 2001
> From: Eric Dumazet <[email protected]>
> Date: Tue, 13 Dec 2011 04:57:06 +0100
> Subject: [PATCH] slub: fix a possible memleak in __slab_alloc()



Hi Greg, here is the backported patch for 3.0, sorry for the delay.

I can exhaust memory (~10 pages/second) using "hackbench 10 thread
4000000" on my server, so this leak is real...

Thanks !

[PATCH] slub: fix a possible memleak in __slab_alloc()

commit 73736e0387ba0e6d2b703407b4d26168d31516a7 upstream.

Zhihua Che reported a possible memleak in slub allocator on
CONFIG_PREEMPT=y builds.

It is possible current thread migrates right before disabling irqs in
__slab_alloc(). We must check again c->freelist, and perform a normal
allocation instead of scratching c->freelist.

Many thanks to Zhihua Che for spotting this bug, introduced in 2.6.39

Cc: <[email protected]>        [2.6.39+]
Reported-by: Zhihua Che <[email protected]>
Signed-off-by: Eric Dumazet <[email protected]>
Acked-by: Christoph Lameter <[email protected]>
Signed-off-by: Pekka Enberg <[email protected]>
---
 mm/slub.c |    6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/mm/slub.c b/mm/slub.c
index 35f351f..0d0901e 100644
--- a/mm/slub.c
+++ b/mm/slub.c
@@ -1818,6 +1818,11 @@ static void *__slab_alloc(struct kmem_cache *s, gfp_t 
gfpflags, int node,
        if (unlikely(!node_match(c, node)))
                goto another_slab;
 
+       /* must check again c->freelist in case of cpu migration or IRQ */
+       object = c->freelist;
+       if (object)
+               goto update_freelist;
+
        stat(s, ALLOC_REFILL);
 
 load_freelist:
@@ -1827,6 +1832,7 @@ load_freelist:
        if (kmem_cache_debug(s))
                goto debug;
 
+update_freelist:
        c->freelist = get_freepointer(s, object);
        page->inuse = page->objects;
        page->freelist = NULL;


--
To unsubscribe from this list: send the line "unsubscribe stable" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to