• Aneesh Kumar K.V's avatar
    powerpc/hugetlb: Handle mmap_min_addr correctly in get_unmapped_area callback · 085aefc2
    Aneesh Kumar K.V authored
    [ Upstream commit 5330367f ]
    
    After we ALIGN up the address we need to make sure we didn't overflow
    and resulted in zero address. In that case, we need to make sure that
    the returned address is greater than mmap_min_addr.
    
    This fixes selftest va_128TBswitch --run-hugetlb reporting failures when
    run as non root user for
    
    mmap(-1, MAP_HUGETLB)
    
    The bug is that a non-root user requesting address -1 will be given address 0
    which will then fail, whereas they should have been given something else that
    would have succeeded.
    
    We also avoid the first mmap(-1, MAP_HUGETLB) returning NULL address as mmap address
    with this change. So we think this is not a security issue, because it only affects
    whether we choose an address below mmap_min_addr, not whether we
    actually allow that address to be mapped. ie. there are existing capability
    checks to prevent a user mapping below mmap_min_addr and those will still be
    honoured even without this fix.
    
    Fixes: 48483760 ("powerpc/mm: Add radix support for hugetlb")
    Reviewed-by: default avatarLaurent Dufour <ldufour@linux.vnet.ibm.com>
    Signed-off-by: default avatarAneesh Kumar K.V <aneesh.kumar@linux.ibm.com>
    Signed-off-by: default avatarMichael Ellerman <mpe@ellerman.id.au>
    Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
    085aefc2
hugetlbpage-radix.c 2.62 KB