mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: IWAMOTO Toshihiro <iwamoto@valinux.co.jp>
To: linux-kernel@vger.kernel.org
Subject: [PATCH] fix memory leak while coredumping
Date: Mon, 02 Feb 2004 19:53:35 +0900	[thread overview]
Message-ID: <20040202105335.DFE88700A2@sv1.valinux.co.jp> (raw)

Hi,

with some help of coworker, I found a bug in binfmt_elf.c.
The bug exists in linux-2.6.1 and linux-2.6.2-rc2-mm2.

This patch fixes a memory leak that happens when a core file hits the
process's resource limit.
I've tested the DUMP_WRITE case only a little, and the DUMP_SEEK case
is only compile tested.

--- old/fs/binfmt_elf.c	Fri Jan 16 12:12:24 2004
+++ new/fs/binfmt_elf.c	Mon Feb  2 19:31:42 2004
@@ -1441,12 +1441,22 @@
 				DUMP_SEEK (file->f_pos + PAGE_SIZE);
 			} else {
 				if (page == ZERO_PAGE(addr)) {
-					DUMP_SEEK (file->f_pos + PAGE_SIZE);
+					if (!dump_seek(file,
+					    file->f_pos + PAGE_SIZE)) {
+						page_cache_release(page);
+						goto end_coredump;
+					}
 				} else {
 					void *kaddr;
 					flush_cache_page(vma, addr);
 					kaddr = kmap(page);
-					DUMP_WRITE(kaddr, PAGE_SIZE);
+					if ((size += PAGE_SIZE) > limit ||
+					    !dump_write(file, kaddr,
+					    PAGE_SIZE)) {
+						kunmap(page);
+						page_cache_release(page);
+						goto end_coredump;
+					}
 					kunmap(page);
 				}
 				page_cache_release(page);

             reply	other threads:[~2004-02-02 10:53 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-02-02 10:53 IWAMOTO Toshihiro [this message]
2004-02-02 22:17 ` Andrew Morton

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=20040202105335.DFE88700A2@sv1.valinux.co.jp \
    --to=iwamoto@valinux.co.jp \
    --cc=linux-kernel@vger.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 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®