Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

s390: redefine randomize_et_dyn for ELF_ET_DYN_BASE

In preparation for moving ET_DYN randomization into the ELF loader (which
requires a static ELF_ET_DYN_BASE), this redefines s390's existing ET_DYN
randomization in a call to arch_mmap_rnd(). This refactoring results in
the same ET_DYN randomization on s390.

Signed-off-by: Kees Cook <keescook@chromium.org>
Acked-by: Martin Schwidefsky <schwidefsky@de.ibm.com>
Cc: Heiko Carstens <heiko.carstens@de.ibm.com>
Reviewed-by: Ingo Molnar <mingo@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by

Kees Cook and committed by
Linus Torvalds
c6f5b001 2b68f6ca

+7 -12
+5 -3
arch/s390/include/asm/elf.h
··· 161 161 /* This is the location that an ET_DYN program is loaded if exec'ed. Typical 162 162 use of this is to invoke "./ld.so someprog" to test out a new version of 163 163 the loader. We need to make sure that it is out of the way of the program 164 - that it will "exec", and that there is sufficient room for the brk. */ 165 - 164 + that it will "exec", and that there is sufficient room for the brk. 64-bit 165 + tasks are aligned to 4GB. */ 166 166 extern unsigned long randomize_et_dyn(void); 167 - #define ELF_ET_DYN_BASE randomize_et_dyn() 167 + #define ELF_ET_DYN_BASE (randomize_et_dyn() + (is_32bit_task() ? \ 168 + (STACK_TOP / 3 * 2) : \ 169 + (STACK_TOP / 3 * 2) & ~((1UL << 32) - 1))) 168 170 169 171 /* This yields a mask that user programs can use to figure out what 170 172 instruction set this CPU supports. */
+2 -9
arch/s390/mm/mmap.c
··· 179 179 180 180 unsigned long randomize_et_dyn(void) 181 181 { 182 - unsigned long base; 183 - 184 - base = STACK_TOP / 3 * 2; 185 - if (!is_32bit_task()) 186 - /* Align to 4GB */ 187 - base &= ~((1UL << 32) - 1); 188 - 189 182 if (current->flags & PF_RANDOMIZE) 190 - base += arch_mmap_rnd(); 183 + return arch_mmap_rnd(); 191 184 192 - return base; 185 + return 0UL; 193 186 } 194 187 195 188 #ifndef CONFIG_64BIT