• Paul Burton's avatar
    MIPS: VDSO: Always map near top of user memory · 86717a97
    Paul Burton authored
    commit ea7e0480a4b695d0aa6b3fa99bd658a003122113 upstream.
    
    When using the legacy mmap layout, for example triggered using ulimit -s
    unlimited, get_unmapped_area() fills memory from bottom to top starting
    from a fairly low address near TASK_UNMAPPED_BASE.
    
    This placement is suboptimal if the user application wishes to allocate
    large amounts of heap memory using the brk syscall. With the VDSO being
    located low in the user's virtual address space, the amount of space
    available for access using brk is limited much more than it was prior to
    the introduction of the VDSO.
    
    For example:
    
      # ulimit -s unlimited; cat /proc/self/maps
      00400000-004ec000 r-xp 00000000 08:00 71436      /usr/bin/coreutils
      004fc000-004fd000 rwxp 000ec000 08:00 71436      /usr/bin/coreutils
      004fd000-0050f000 rwxp 00000000 00:00 0
      00cc3000-00ce4000 rwxp 00000000 00:00 0          [heap]
      2ab96000-2ab98000 r--p 00000000 00:00 0          [vvar]
      2ab98000-2ab99000 r-xp 00000000 00:00 0          [vdso]
      2ab99000-2ab9d000 rwxp 00000000 00:00 0
      ...
    
    Resolve this by adjusting STACK_TOP to reserve space for the VDSO &
    providing an address hint to get_unmapped_area() causing it to use this
    space even when using the legacy mmap layout.
    
    We reserve enough space for the VDSO, plus 1MB or 256MB for 32 bit & 64
    bit systems respectively within which we randomize the VDSO base
    address. Previously this randomization was taken care of by the mmap
    base address randomization performed by arch_mmap_rnd(). The 1MB & 256MB
    sizes are somewhat arbitrary but chosen such that we have some
    randomization without taking up too much of the user's virtual address
    space, which is often in short supply for 32 bit systems.
    
    With this the VDSO is always mapped at a high address, leaving lots of
    space for statically linked programs to make use of brk:
    
      # ulimit -s unlimited; cat /proc/self/maps
      00400000-004ec000 r-xp 00000000 08:00 71436      /usr/bin/coreutils
      004fc000-004fd000 rwxp 000ec000 08:00 71436      /usr/bin/coreutils
      004fd000-0050f000 rwxp 00000000 00:00 0
      00c28000-00c49000 rwxp 00000000 00:00 0          [heap]
      ...
      7f67c000-7f69d000 rwxp 00000000 00:00 0          [stack]
      7f7fc000-7f7fd000 rwxp 00000000 00:00 0
      7fcf1000-7fcf3000 r--p 00000000 00:00 0          [vvar]
      7fcf3000-7fcf4000 r-xp 00000000 00:00 0          [vdso]
    Signed-off-by: 's avatarPaul Burton <paul.burton@mips.com>
    Reported-by: 's avatarHuacai Chen <chenhc@lemote.com>
    Fixes: ebb5e78c ("MIPS: Initial implementation of a VDSO")
    Cc: Huacai Chen <chenhc@lemote.com>
    Cc: linux-mips@linux-mips.org
    Cc: stable@vger.kernel.org # v4.4+
    Signed-off-by: 's avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
    86717a97
Name
Last commit
Last update
..
alchemy Loading commit data...
ar7 Loading commit data...
ath25 Loading commit data...
ath79 Loading commit data...
bcm47xx Loading commit data...
bcm63xx Loading commit data...
bmips Loading commit data...
boot Loading commit data...
cavium-octeon Loading commit data...
cobalt Loading commit data...
configs Loading commit data...
dec Loading commit data...
emma Loading commit data...
fw Loading commit data...
generic Loading commit data...
include Loading commit data...
jazz Loading commit data...
jz4740 Loading commit data...
kernel Loading commit data...
kvm Loading commit data...
lantiq Loading commit data...
lasat Loading commit data...
lib Loading commit data...
loongson32 Loading commit data...
loongson64 Loading commit data...
math-emu Loading commit data...
mm Loading commit data...
mti-malta Loading commit data...
net Loading commit data...
netlogic Loading commit data...
oprofile Loading commit data...
paravirt Loading commit data...
pci Loading commit data...
pic32 Loading commit data...
pistachio Loading commit data...
pmcs-msp71xx Loading commit data...
pnx833x Loading commit data...
power Loading commit data...
ralink Loading commit data...
rb532 Loading commit data...
sgi-ip22 Loading commit data...
sgi-ip27 Loading commit data...
sgi-ip32 Loading commit data...
sibyte Loading commit data...
sni Loading commit data...
tools Loading commit data...
txx9 Loading commit data...
vdso Loading commit data...
vr41xx Loading commit data...
xilfpga Loading commit data...
Kbuild Loading commit data...
Kbuild.platforms Loading commit data...
Kconfig Loading commit data...
Kconfig.debug Loading commit data...
Makefile Loading commit data...
Makefile.postlink Loading commit data...