All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andy Lutomirski <luto@MIT.EDU>
To: mingo@redhat.com, wzt <wzt.wzt@gmail.com>
Cc: linux-kernel@vger.kernel.org, x86@kernel.org, ak@linux.intel.com,
	tglx@linutronix.de, hpa@zytor.com, Michal Hocko <mhocko@suse.cz>,
	Zhitong Wang <zhitong.wangzt@alibaba-inc.com>,
	Andy Lutomirski <luto@MIT.EDU>
Subject: [PATCH] x86: Fix memory leak of init_vdso_vars()
Date: Thu, 21 Jul 2011 10:33:14 -0400	[thread overview]
Message-ID: <d1a1b6416d71a5062fb3b3e364f9db6b6d4ef6b2.1311258580.git.luto@mit.edu> (raw)
In-Reply-To: <20110705062148.GA6056@program>

From: Zhitong Wang <wzt.wzt@gmail.com>

If init_vdso_vars ran out of memory (not very likely), then it would
leak a few pages as well.

Also rename init_vdso_vars to just init_vdso, since initializing
vvars is just about the only thing this function doesn't do.

Signed-off-by: Zhitong Wang <zhitong.wangzt@alibaba-inc.com>
[Rebased and slightly simplified from the original.]
Signed-off-by: Andy Lutomirski <luto@mit.edu>
---
 arch/x86/vdso/vma.c |   13 +++++++++----
 1 files changed, 9 insertions(+), 4 deletions(-)

diff --git a/arch/x86/vdso/vma.c b/arch/x86/vdso/vma.c
index c39938d..cabaf0e 100644
--- a/arch/x86/vdso/vma.c
+++ b/arch/x86/vdso/vma.c
@@ -54,7 +54,7 @@ found:
 	apply_alternatives(alt_data, alt_data + alt_sec->sh_size);
 }
 
-static int __init init_vdso_vars(void)
+static int __init init_vdso(void)
 {
 	int npages = (vdso_end - vdso_start + PAGE_SIZE - 1) / PAGE_SIZE;
 	int i;
@@ -69,19 +69,24 @@ static int __init init_vdso_vars(void)
 		struct page *p;
 		p = alloc_page(GFP_KERNEL);
 		if (!p)
-			goto oom;
+			goto oom_free;
 		vdso_pages[i] = p;
 		copy_page(page_address(p), vdso_start + i*PAGE_SIZE);
 	}
 
 	return 0;
 
- oom:
+oom_free:
+	for(i--; i >= 0; i--)
+		__free_page(vdso_pages[i]);
+	__free_page(vdso_pages);
+
+oom:
 	printk("Cannot allocate vdso\n");
 	vdso_enabled = 0;
 	return -ENOMEM;
 }
-subsys_initcall(init_vdso_vars);
+subsys_initcall(init_vdso);
 
 struct linux_binprm;
 
-- 
1.7.6


  parent reply	other threads:[~2011-07-21 14:33 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-07-05  6:21 [PATCH] x86: Fix memory leak of init_vdso_vars() wzt
2011-07-07 13:14 ` Michal Hocko
2011-07-07 18:33   ` Andi Kleen
2011-07-11  3:23     ` wzt wzt
2011-07-11 10:04       ` Ingo Molnar
2011-07-21 14:33 ` Andy Lutomirski [this message]
2011-07-21 17:08   ` Andi Kleen
2011-07-21 17:26     ` Andrew Lutomirski
2011-07-21 18:38       ` Ingo Molnar
2011-07-21 19:39         ` Andrew Lutomirski
2011-07-21 19:43           ` Ingo Molnar
2011-07-21 19:47           ` [PATCH] x86-64: Do not allocate memory for the vDSO Andy Lutomirski
2011-07-21 20:52             ` [tip:x86/vdso] x86-64, vdso: " tip-bot for Andy Lutomirski

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=d1a1b6416d71a5062fb3b3e364f9db6b6d4ef6b2.1311258580.git.luto@mit.edu \
    --to=luto@mit.edu \
    --cc=ak@linux.intel.com \
    --cc=hpa@zytor.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mhocko@suse.cz \
    --cc=mingo@redhat.com \
    --cc=tglx@linutronix.de \
    --cc=wzt.wzt@gmail.com \
    --cc=x86@kernel.org \
    --cc=zhitong.wangzt@alibaba-inc.com \
    /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.