Skip to content

Commit 2a5eb99

Browse files
committed
binfmt_elf: Leave a gap between .bss and brk
Currently the brk starts its randomization immediately after .bss, which means there is a chance that when the random offset is 0, linear overflows from .bss can reach into the brk area. Leave at least a single page gap between .bss and brk (when it has not already been explicitly relocated into the mmap range). Reported-by: <[email protected]> Closes: https://lore.kernel.org/linux-hardening/CA+2EKTVLvc8hDZc+2Yhwmus=dzOUG5E4gV7ayCbu0MPJTZzWkw@mail.gmail.com/ Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Kees Cook <[email protected]>
1 parent a9c3475 commit 2a5eb99

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

fs/binfmt_elf.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1262,6 +1262,9 @@ static int load_elf_binary(struct linux_binprm *bprm)
12621262
if (IS_ENABLED(CONFIG_ARCH_HAS_ELF_RANDOMIZE) &&
12631263
elf_ex->e_type == ET_DYN && !interpreter) {
12641264
mm->brk = mm->start_brk = ELF_ET_DYN_BASE;
1265+
} else {
1266+
/* Otherwise leave a gap between .bss and brk. */
1267+
mm->brk = mm->start_brk = mm->brk + PAGE_SIZE;
12651268
}
12661269

12671270
mm->brk = mm->start_brk = arch_randomize_brk(mm);

0 commit comments

Comments
 (0)