mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
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:30:23 +0100	[thread overview]
Message-ID: <1269466223.2849.23.camel@edumazet-laptop> (raw)
In-Reply-To: <alpine.DEB.2.00.1003241624580.17362@router.home>

Le mercredi 24 mars 2010 à 16:25 -0500, Christoph Lameter a écrit :
> Here is a patch for the second case. I think its better since it results
> in an error display and it avoids the alloc for each slab. Add this piece
> to your patch?

Yes, I did it

> 
> V1->V2 Fix missing kfree
> 
> Signed-off-by: Christoph Lameter <cl@linux-foundation.org>
> 
> ---
>  mm/slub.c |   13 ++++++++-----
>  1 file changed, 8 insertions(+), 5 deletions(-)
> 
> Index: linux-2.6/mm/slub.c
> ===================================================================
> --- linux-2.6.orig/mm/slub.c	2010-03-24 16:23:19.000000000 -0500
> +++ linux-2.6/mm/slub.c	2010-03-24 16:24:21.000000000 -0500
> @@ -3648,10 +3648,10 @@ static int add_location(struct loc_track
>  }
> 
>  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,
> +		unsigned long *map)
>  {
>  	void *addr = page_address(page);
> -	DECLARE_BITMAP(map, page->objects);
>  	void *p;
> 
>  	bitmap_zero(map, page->objects);
> @@ -3670,8 +3670,10 @@ static int list_locations(struct kmem_ca
>  	unsigned long i;
>  	struct loc_track t = { 0, 0, NULL };
>  	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))

I also added a kfree(map); here

>  		return sprintf(buf, "Out of memory\n");
> 
> @@ -3688,11 +3690,12 @@ static int list_locations(struct kmem_ca
> 
>  		spin_lock_irqsave(&n->list_lock, flags);
>  		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)
> -			process_slab(&t, s, page, alloc);
> +			process_slab(&t, s, page, alloc, map);
>  		spin_unlock_irqrestore(&n->list_lock, flags);
>  	}
> +	kfree(map);
> 
>  	for (i = 0; i < t.count; i++) {
>  		struct location *l = &t.loc[i];
> --




      reply	other threads:[~2010-03-24 21:30 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
2010-03-24 21:10         ` Christoph Lameter
2010-03-24 21:14           ` Christoph Lameter
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
2010-03-24 21:25             ` Christoph Lameter
2010-03-24 21:30               ` Eric Dumazet [this message]

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=1269466223.2849.23.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®