Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp997979yba; Thu, 4 Apr 2019 02:04:32 -0700 (PDT) X-Google-Smtp-Source: APXvYqyMPBTnkQUktAvoA32rHgAdeJICJEOm4nQlLB2x3ApRGCHYNldgFL24lg7L4L8JfER6AqS0 X-Received: by 2002:a17:902:20eb:: with SMTP id v40mr5076039plg.20.1554368672898; Thu, 04 Apr 2019 02:04:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1554368672; cv=none; d=google.com; s=arc-20160816; b=Nv+MR8PprWsEuTB1Sn6Mg5ABtFnm52ibk1bxhFLu8AcMXiSm1GgRKgfqPAi6t1kreL 1P+PxD9UvAELEc7MDamT436qFNFiTVDSWc9eCOntnPNan/syaSCy9HohXw5RdpqUG4en C0pxc19C798KE9iau8+bLsKW6PQf3GApEph+3kWaq2HFzW4YIWPP0srMMEDWoj/4KV4t IWjLEJagPXyYeMQAMuAnJ4OdFjTjE2jEaWDl2gNnT6lsbvAJS814mJcHIvf5UqqafzJW XyZO+1HhAavUHi5yC8PWDhqvlVBdSu0LAAX7E/5lRdEnA6qZkWCQ3ezVfwOasqEgaiDQ rKkg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=cwa42ltrvPd3p6JySXWH6Sw+zbObghsf0QggRp7oq0w=; b=aHAzkobXPC2QkqL/5ujUehvXIG//0mYPirJDW536isPs5PcYomsDlE6uA496nPT6NC ZFeaygMSnf8kSoL/Z3L5GVhZFBlX6kD7uNCdWQGNYRYAArHcZS9PGcNUWgllDt+F90ZB 1kClssBVLFlDA1cEO1vo09oToJHO77DdmyWQRpEJY99Juak5gS7pPtHIBkegjv9h8bsH Yi4befZpKbRhsWVrzs5sigAx9TbRpGXwEZ6xPS9dbI1q6ujqZH1VDwcqUPrri9FVMWxE GbStQeoTeCd8O3xsMapSnq7iDBj8/GhiwGaeged0im9Qn9atNWGJmTscGzl+s5zNa0/H qZwA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=wVeFOLbr; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v5si14720852pfm.134.2019.04.04.02.04.17; Thu, 04 Apr 2019 02:04:32 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=wVeFOLbr; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731368AbfDDJC0 (ORCPT + 99 others); Thu, 4 Apr 2019 05:02:26 -0400 Received: from mail.kernel.org ([198.145.29.99]:39708 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731603AbfDDJCV (ORCPT ); Thu, 4 Apr 2019 05:02:21 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 36C7B21855; Thu, 4 Apr 2019 09:02:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1554368540; bh=p1Q9vdU56hNv4TQmlhfv8lp0VbDsrwjEkd/BucVq42U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=wVeFOLbrdyY71R957T+nvE3BWJS33CMIvbHkphHKd2M0LcWOR31VCRW13vemGoTdz Aq94UCDUm9D+VuRPdo0KAS2YfgqjO8JcUn8I1xcqUPFcIUnDZbcJxmgjua66YklRvJ N2kFGiapwsPr+7G1Tn21sCqty/R8cg4xbCYhmjpA= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Laurent Dufour , "Aneesh Kumar K.V" , Michael Ellerman , Sasha Levin Subject: [PATCH 4.19 061/187] powerpc/hugetlb: Handle mmap_min_addr correctly in get_unmapped_area callback Date: Thu, 4 Apr 2019 10:46:38 +0200 Message-Id: <20190404084605.951694851@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190404084603.119654039@linuxfoundation.org> References: <20190404084603.119654039@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.19-stable review patch. If anyone has any objections, please let me know. ------------------ [ Upstream commit 5330367fa300742a97e20e953b1f77f48392faae ] 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: 484837601d4d ("powerpc/mm: Add radix support for hugetlb") Reviewed-by: Laurent Dufour Signed-off-by: Aneesh Kumar K.V Signed-off-by: Michael Ellerman Signed-off-by: Sasha Levin --- arch/powerpc/mm/hugetlbpage-radix.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/arch/powerpc/mm/hugetlbpage-radix.c b/arch/powerpc/mm/hugetlbpage-radix.c index 2486bee0f93e..97c7a39ebc00 100644 --- a/arch/powerpc/mm/hugetlbpage-radix.c +++ b/arch/powerpc/mm/hugetlbpage-radix.c @@ -1,6 +1,7 @@ // SPDX-License-Identifier: GPL-2.0 #include #include +#include #include #include #include @@ -73,7 +74,7 @@ radix__hugetlb_get_unmapped_area(struct file *file, unsigned long addr, if (addr) { addr = ALIGN(addr, huge_page_size(h)); vma = find_vma(mm, addr); - if (high_limit - len >= addr && + if (high_limit - len >= addr && addr >= mmap_min_addr && (!vma || addr + len <= vm_start_gap(vma))) return addr; } @@ -83,7 +84,7 @@ radix__hugetlb_get_unmapped_area(struct file *file, unsigned long addr, */ info.flags = VM_UNMAPPED_AREA_TOPDOWN; info.length = len; - info.low_limit = PAGE_SIZE; + info.low_limit = max(PAGE_SIZE, mmap_min_addr); info.high_limit = mm->mmap_base + (high_limit - DEFAULT_MAP_WINDOW); info.align_mask = PAGE_MASK & ~huge_page_mask(h); info.align_offset = 0; -- 2.19.1