* [PATCH] fix memory leak while coredumping
@ 2004-02-02 10:53 IWAMOTO Toshihiro
2004-02-02 22:17 ` Andrew Morton
0 siblings, 1 reply; 2+ messages in thread
From: IWAMOTO Toshihiro @ 2004-02-02 10:53 UTC (permalink / raw)
To: linux-kernel
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);
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] fix memory leak while coredumping
2004-02-02 10:53 [PATCH] fix memory leak while coredumping IWAMOTO Toshihiro
@ 2004-02-02 22:17 ` Andrew Morton
0 siblings, 0 replies; 2+ messages in thread
From: Andrew Morton @ 2004-02-02 22:17 UTC (permalink / raw)
To: IWAMOTO Toshihiro; +Cc: linux-kernel
IWAMOTO Toshihiro <iwamoto@valinux.co.jp> wrote:
>
> 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;
> + }
There's no point in doing page_cache_release() of the zero page.
> } 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);
This chunk is good, thanks.
Those macros are foul.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2004-02-02 22:15 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-02-02 10:53 [PATCH] fix memory leak while coredumping IWAMOTO Toshihiro
2004-02-02 22:17 ` Andrew Morton
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®