[PATCH 0/2] binfmt_elf: fix calculations for bss padding

From: Kees Cook
Date: Fri Jul 08 2016 - 17:48:53 EST


This fixes a double-bug in ELF loading, as noticed by Hector
Marco-Gisbert. To quote his original email:


The size of the bss section for some interpreters is not correctly
calculated resulting in unnecessary calls to vm_brk() with enormous size
values.

The bug appears when loading some interpreters with a small bss size. Once
the last loadable segment has been loaded, the bss section is zeroed up to
the page boundary and the elf_bss variable is updated to this new page
boundary. Because of this update (alignment), the last_bss could be less
than elf_bss and the subtraction "last_bss - elf_bss" value could overflow.
...
[e.g.] The size value requested to the vm_brk() call (last_bss - elf_bss) is
0xfffffffffffff938 and internally this size is page aligned in the do_brk()
function resulting in a 0 length request.


This series takes a slightly different approach to fixing it and updates
vm_brk to refuse bad allocation sizes.

-Kees