[PATCH] x86: Fix memory leak of init_vdso_vars()

From: Andy Lutomirski
Date: Thu Jul 21 2011 - 10:33:33 EST


From: Zhitong Wang <wzt.wzt@xxxxxxxxx>

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@xxxxxxxxxxxxxxx>
[Rebased and slightly simplified from the original.]
Signed-off-by: Andy Lutomirski <luto@xxxxxxx>
---
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

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/