LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
From: Jeff Dike <jdike@addtoit.com>
To: Andrew Morton <akpm@osdl.org>
Cc: LKML <linux-kernel@vger.kernel.org>,
	uml-devel <user-mode-linux-devel@lists.sourceforge.net>,
	Miklos Szeredi <miklos@szeredi.hu>
Subject: [PATCH 5/5] UML - Fix mm_context memory leak
Date: Wed, 6 Feb 2008 12:44:48 -0500	[thread overview]
Message-ID: <20080206174448.GA7851@c2.user-mode-linux.org> (raw)

[ Spotted by Miklos ]

Fix a memory leak in init_new_context.  The struct page ** buffer
allocated for install_special_mapping was never recorded, and thus
leaked when the mm_struct was freed.  Fix it by saving the pointer in
mm_context_t and freeing it in arch_exit_mmap.

Signed-off-by: Jeff Dike <jdike@linux.intel.com>
Cc: Miklos Szeredi <miklos@szeredi.hu>
---
 arch/um/include/um_mmu.h  |    1 +
 arch/um/kernel/skas/mmu.c |    5 +++++
 2 files changed, 6 insertions(+)

Index: linux-2.6-git/arch/um/include/um_mmu.h
===================================================================
--- linux-2.6-git.orig/arch/um/include/um_mmu.h	2008-02-06 12:15:05.000000000 -0500
+++ linux-2.6-git/arch/um/include/um_mmu.h	2008-02-06 12:24:08.000000000 -0500
@@ -13,6 +13,7 @@
 typedef struct mm_context {
 	struct mm_id id;
 	struct uml_ldt ldt;
+	struct page **stub_pages;
 } mm_context_t;
 
 extern void __switch_mm(struct mm_id * mm_idp);
Index: linux-2.6-git/arch/um/kernel/skas/mmu.c
===================================================================
--- linux-2.6-git.orig/arch/um/kernel/skas/mmu.c	2008-02-06 12:15:05.000000000 -0500
+++ linux-2.6-git/arch/um/kernel/skas/mmu.c	2008-02-06 12:24:31.000000000 -0500
@@ -91,6 +91,8 @@ int init_new_context(struct task_struct 
 		goto out_free;
 	}
 
+	to_mm->stub_pages = NULL;
+
 	return 0;
 
  out_free:
@@ -126,6 +128,7 @@ void arch_dup_mmap(struct mm_struct *old
 
 	pages[0] = virt_to_page(&__syscall_stub_start);
 	pages[1] = virt_to_page(mm->context.id.stack);
+	mm->context.stub_pages = pages;
 
 	/* dup_mmap already holds mmap_sem */
 	err = install_special_mapping(mm, STUB_START, STUB_END - STUB_START,
@@ -147,6 +150,8 @@ void arch_exit_mmap(struct mm_struct *mm
 {
 	pte_t *pte;
 
+	if (mm->context.stub_pages != NULL)
+		kfree(mm->context.stub_pages);
 	pte = virt_to_pte(mm, STUB_CODE);
 	if (pte != NULL)
 		pte_clear(mm, STUB_CODE, pte);

                 reply	other threads:[~2008-02-06 17:46 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20080206174448.GA7851@c2.user-mode-linux.org \
    --to=jdike@addtoit.com \
    --cc=akpm@osdl.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=miklos@szeredi.hu \
    --cc=user-mode-linux-devel@lists.sourceforge.net \
    --subject='Re: [PATCH 5/5] UML - Fix mm_context memory leak' \
    /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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).