aboutsummaryrefslogtreecommitdiffstats
path: root/arch/x86_64
diff options
context:
space:
mode:
authorHugh Dickins <hugh@veritas.com>2005-09-14 01:13:02 -0400
committerLinus Torvalds <torvalds@g5.osdl.org>2005-09-14 14:18:13 -0400
commit2fd4ef85e0db9ed75c98e13953257a967ea55e03 (patch)
tree119dfe9f88a832f3db6ff66e631112626f268f18 /arch/x86_64
parentfb085cf1d4294824571815d487daccc0609543f0 (diff)
[PATCH] error path in setup_arg_pages() misses vm_unacct_memory()
Pavel Emelianov and Kirill Korotaev observe that fs and arch users of security_vm_enough_memory tend to forget to vm_unacct_memory when a failure occurs further down (typically in setup_arg_pages variants). These are all users of insert_vm_struct, and that reservation will only be unaccounted on exit if the vma is marked VM_ACCOUNT: which in some cases it is (hidden inside VM_STACK_FLAGS) and in some cases it isn't. So x86_64 32-bit and ppc64 vDSO ELFs have been leaking memory into Committed_AS each time they're run. But don't add VM_ACCOUNT to them, it's inappropriate to reserve against the very unlikely case that gdb be used to COW a vDSO page - we ought to do something about that in do_wp_page, but there are yet other inconsistencies to be resolved. The safe and economical way to fix this is to let insert_vm_struct do the security_vm_enough_memory check when it finds VM_ACCOUNT is set. And the MIPS irix_brk has been calling security_vm_enough_memory before calling do_brk which repeats it, doubly accounting and so also leaking. Remove that, and all the fs and arch calls to security_vm_enough_memory: give it a less misleading name later on. Signed-off-by: Hugh Dickins <hugh@veritas.com> Signed-Off-By: Kirill Korotaev <dev@sw.ru> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Diffstat (limited to 'arch/x86_64')
-rw-r--r--arch/x86_64/ia32/ia32_binfmt.c5
-rw-r--r--arch/x86_64/ia32/syscall32.c6
2 files changed, 1 insertions, 10 deletions
diff --git a/arch/x86_64/ia32/ia32_binfmt.c b/arch/x86_64/ia32/ia32_binfmt.c
index c8131f342cfc..d9161e395978 100644
--- a/arch/x86_64/ia32/ia32_binfmt.c
+++ b/arch/x86_64/ia32/ia32_binfmt.c
@@ -353,11 +353,6 @@ int setup_arg_pages(struct linux_binprm *bprm, unsigned long stack_top, int exec
353 mpnt = kmem_cache_alloc(vm_area_cachep, SLAB_KERNEL); 353 mpnt = kmem_cache_alloc(vm_area_cachep, SLAB_KERNEL);
354 if (!mpnt) 354 if (!mpnt)
355 return -ENOMEM; 355 return -ENOMEM;
356
357 if (security_vm_enough_memory((IA32_STACK_TOP - (PAGE_MASK & (unsigned long) bprm->p))>>PAGE_SHIFT)) {
358 kmem_cache_free(vm_area_cachep, mpnt);
359 return -ENOMEM;
360 }
361 356
362 memset(mpnt, 0, sizeof(*mpnt)); 357 memset(mpnt, 0, sizeof(*mpnt));
363 358
diff --git a/arch/x86_64/ia32/syscall32.c b/arch/x86_64/ia32/syscall32.c
index adbc5f8089e9..3a01329473ab 100644
--- a/arch/x86_64/ia32/syscall32.c
+++ b/arch/x86_64/ia32/syscall32.c
@@ -52,17 +52,13 @@ int syscall32_setup_pages(struct linux_binprm *bprm, int exstack)
52 vma = kmem_cache_alloc(vm_area_cachep, SLAB_KERNEL); 52 vma = kmem_cache_alloc(vm_area_cachep, SLAB_KERNEL);
53 if (!vma) 53 if (!vma)
54 return -ENOMEM; 54 return -ENOMEM;
55 if (security_vm_enough_memory(npages)) {
56 kmem_cache_free(vm_area_cachep, vma);
57 return -ENOMEM;
58 }
59 55
60 memset(vma, 0, sizeof(struct vm_area_struct)); 56 memset(vma, 0, sizeof(struct vm_area_struct));
61 /* Could randomize here */ 57 /* Could randomize here */
62 vma->vm_start = VSYSCALL32_BASE; 58 vma->vm_start = VSYSCALL32_BASE;
63 vma->vm_end = VSYSCALL32_END; 59 vma->vm_end = VSYSCALL32_END;
64 /* MAYWRITE to allow gdb to COW and set breakpoints */ 60 /* MAYWRITE to allow gdb to COW and set breakpoints */
65 vma->vm_flags = VM_READ|VM_EXEC|VM_MAYREAD|VM_MAYEXEC|VM_MAYEXEC|VM_MAYWRITE; 61 vma->vm_flags = VM_READ|VM_EXEC|VM_MAYREAD|VM_MAYEXEC|VM_MAYWRITE;
66 vma->vm_flags |= mm->def_flags; 62 vma->vm_flags |= mm->def_flags;
67 vma->vm_page_prot = protection_map[vma->vm_flags & 7]; 63 vma->vm_page_prot = protection_map[vma->vm_flags & 7];
68 vma->vm_ops = &syscall32_vm_ops; 64 vma->vm_ops = &syscall32_vm_ops;