All of lore.kernel.org
 help / color / mirror / Atom feed
From: Wang Sheng-Hui <shhuiw@gmail.com>
To: yinghai@kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org
Subject: [PATCH 3/3] mm/memblock.c: eliminate potential memleak in memblock_double_array
Date: Wed, 09 Nov 2011 19:37:30 +0800	[thread overview]
Message-ID: <4EBA65FA.1010605@gmail.com> (raw)

In memblock_double_array, we don't deal with old_array if we use
slab for new_array. So the memory used by old_array may be lost.
Add logic to try to free old_array when using slab for new_array.

Signed-off-by: Wang Sheng-Hui <shhuiw@gmail.com>
---
 mm/memblock.c |    8 ++++++--
 1 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/mm/memblock.c b/mm/memblock.c
index 09ff05b..0e4248f 100644
--- a/mm/memblock.c
+++ b/mm/memblock.c
@@ -250,13 +250,17 @@ static int __init_memblock memblock_double_array(struct memblock_type *type)
 	type->regions = new_array;
 	type->max <<= 1;
 
-	/* If we use SLAB that's it, we are done */
-	if (use_slab)
+	if (use_slab) {
+		if (memblock_is_region_reserved(__pa(old_array), old_size))
+			goto old_memblock;
+		kfree(old_array);
 		return 0;
+	}
 
 	/* Add the new reserved region now. Should not fail ! */
 	BUG_ON(memblock_add_region(&memblock.reserved, addr, new_size));
 
+old_memblock:
 	/* If the array wasn't our static init one, then free it. We only do
 	 * that before SLAB is available as later on, we don't know whether
 	 * to use kfree or free_bootmem_pages(). Shouldn't be a big deal
-- 
1.7.1


WARNING: multiple messages have this Message-ID (diff)
From: Wang Sheng-Hui <shhuiw@gmail.com>
To: yinghai@kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org
Subject: [PATCH 3/3] mm/memblock.c: eliminate potential memleak in memblock_double_array
Date: Wed, 09 Nov 2011 19:37:30 +0800	[thread overview]
Message-ID: <4EBA65FA.1010605@gmail.com> (raw)

In memblock_double_array, we don't deal with old_array if we use
slab for new_array. So the memory used by old_array may be lost.
Add logic to try to free old_array when using slab for new_array.

Signed-off-by: Wang Sheng-Hui <shhuiw@gmail.com>
---
 mm/memblock.c |    8 ++++++--
 1 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/mm/memblock.c b/mm/memblock.c
index 09ff05b..0e4248f 100644
--- a/mm/memblock.c
+++ b/mm/memblock.c
@@ -250,13 +250,17 @@ static int __init_memblock memblock_double_array(struct memblock_type *type)
 	type->regions = new_array;
 	type->max <<= 1;
 
-	/* If we use SLAB that's it, we are done */
-	if (use_slab)
+	if (use_slab) {
+		if (memblock_is_region_reserved(__pa(old_array), old_size))
+			goto old_memblock;
+		kfree(old_array);
 		return 0;
+	}
 
 	/* Add the new reserved region now. Should not fail ! */
 	BUG_ON(memblock_add_region(&memblock.reserved, addr, new_size));
 
+old_memblock:
 	/* If the array wasn't our static init one, then free it. We only do
 	 * that before SLAB is available as later on, we don't know whether
 	 * to use kfree or free_bootmem_pages(). Shouldn't be a big deal
-- 
1.7.1

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

             reply	other threads:[~2011-11-09 11:37 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-11-09 11:37 Wang Sheng-Hui [this message]
2011-11-09 11:37 ` [PATCH 3/3] mm/memblock.c: eliminate potential memleak in memblock_double_array Wang Sheng-Hui

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=4EBA65FA.1010605@gmail.com \
    --to=shhuiw@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=yinghai@kernel.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.