Skip to content

Commit a3defbe

Browse files
Jiri Kosinatorvalds
authored andcommitted
binfmt_elf: fix PIE execution with randomization disabled
The case of address space randomization being disabled in runtime through randomize_va_space sysctl is not treated properly in load_elf_binary(), resulting in SIGKILL coming at exec() time for certain PIE-linked binaries in case the randomization has been disabled at runtime prior to calling exec(). Handle the randomize_va_space == 0 case the same way as if we were not supporting .text randomization at all. Based on original patch by H.J. Lu and Josh Boyer. Signed-off-by: Jiri Kosina <jkosina@suse.cz> Cc: Ingo Molnar <mingo@elte.hu> Cc: Russell King <rmk@arm.linux.org.uk> Cc: H.J. Lu <hongjiu.lu@intel.com> Cc: <stable@kernel.org> Tested-by: Josh Boyer <jwboyer@redhat.com> Acked-by: Nicolas Pitre <nicolas.pitre@linaro.org> Cc: <stable@vger.kernel.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent b35a35b commit a3defbe

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

‎fs/binfmt_elf.c‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -795,7 +795,16 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
795795
* might try to exec. This is because the brk will
796796
* follow the loader, and is not movable. */
797797
#if defined(CONFIG_X86) || defined(CONFIG_ARM)
798-
load_bias = 0;
798+
/* Memory randomization might have been switched off
799+
* in runtime via sysctl.
800+
* If that is the case, retain the original non-zero
801+
* load_bias value in order to establish proper
802+
* non-randomized mappings.
803+
*/
804+
if (current->flags & PF_RANDOMIZE)
805+
load_bias = 0;
806+
else
807+
load_bias = ELF_PAGESTART(ELF_ET_DYN_BASE - vaddr);
799808
#else
800809
load_bias = ELF_PAGESTART(ELF_ET_DYN_BASE - vaddr);
801810
#endif

0 commit comments

Comments
 (0)