• Paul Burton's avatar
    MIPS: VDSO: Always map near top of user memory · ea7e0480
    Paul Burton authored
    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: default avatarPaul Burton <paul.burton@mips.com>
    Reported-by: default 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+
    ea7e0480
processor.h 11.7 KB