Skip to contentSkip to conversation

fs, elf: make sure to page align bss in load_elf_library

PATCH New [email protected] 1 participant 1 message Jul 14, 2018

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 7/11 fs, elf: make sure to page align bss in load_elf_library

From: Oscar Salvador <[email protected]>
Subject: fs, elf: make sure to page align bss in load_elf_library

The current code does not make sure to page align bss before calling vm_brk(), and this can lead to a VM_BUG_ON() in __mm_populate() due to the requested lenght not being correctly aligned.

Let us make sure to align it properly.

Kees: only applicable to CONFIG_USELIB kernels: 32-bit and configured for libc5.

---

 fs/binfmt_elf.c |    5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
fs/binfmt_elf.c renamed from fs/binfmt_elf.c~fs-elf-make-sure-to-page-align-bss-in-load_elf_library +2 -3
diff -puN fs/binfmt_elf.c~fs-elf-make-sure-to-page-align-bss-in-load_elf_library fs/binfmt_elf.c
@@ -1259,9 +1259,8 @@ static int load_elf_library(struct file
 		goto out_free_ph;
 	}
 
-	len = ELF_PAGESTART(eppnt->p_filesz + eppnt->p_vaddr +
-			    ELF_MIN_ALIGN - 1);
-	bss = eppnt->p_memsz + eppnt->p_vaddr;
+	len = ELF_PAGEALIGN(eppnt->p_filesz + eppnt->p_vaddr);
+	bss = ELF_PAGEALIGN(eppnt->p_memsz + eppnt->p_vaddr);
 	if (bss > len) {
 		error = vm_brk(len, bss - len);
 		if (error)

_