Merge branch 'akpm' (patches from Andrew)
[cascardo/linux.git] / fs / binfmt_elf.c
index a7a2811..7f6aff3 100644 (file)
@@ -605,28 +605,30 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
                         * Do the same thing for the memory mapping - between
                         * elf_bss and last_bss is the bss section.
                         */
-                       k = load_addr + eppnt->p_memsz + eppnt->p_vaddr;
+                       k = load_addr + eppnt->p_vaddr + eppnt->p_memsz;
                        if (k > last_bss)
                                last_bss = k;
                }
        }
 
+       /*
+        * Now fill out the bss section: first pad the last page from
+        * the file up to the page boundary, and zero it from elf_bss
+        * up to the end of the page.
+        */
+       if (padzero(elf_bss)) {
+               error = -EFAULT;
+               goto out;
+       }
+       /*
+        * Next, align both the file and mem bss up to the page size,
+        * since this is where elf_bss was just zeroed up to, and where
+        * last_bss will end after the vm_brk() below.
+        */
+       elf_bss = ELF_PAGEALIGN(elf_bss);
+       last_bss = ELF_PAGEALIGN(last_bss);
+       /* Finally, if there is still more bss to allocate, do it. */
        if (last_bss > elf_bss) {
-               /*
-                * Now fill out the bss section.  First pad the last page up
-                * to the page boundary, and then perform a mmap to make sure
-                * that there are zero-mapped pages up to and including the
-                * last bss page.
-                */
-               if (padzero(elf_bss)) {
-                       error = -EFAULT;
-                       goto out;
-               }
-
-               /* What we have mapped so far */
-               elf_bss = ELF_PAGESTART(elf_bss + ELF_MIN_ALIGN - 1);
-
-               /* Map the last of the bss segment */
                error = vm_brk(elf_bss, last_bss - elf_bss);
                if (error)
                        goto out;