Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp1004788yba; Thu, 4 Apr 2019 02:13:02 -0700 (PDT) X-Google-Smtp-Source: APXvYqzklDLSC0bxJW6hghZ1y7wX/ROlBeCYIGohDkIQtOW87yAz9GP9ai/z6ZU8nlvrf3FCyaNt X-Received: by 2002:a63:ef09:: with SMTP id u9mr4745997pgh.126.1554369182141; Thu, 04 Apr 2019 02:13:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1554369182; cv=none; d=google.com; s=arc-20160816; b=HC+spH7GrpfTjTNSV7d1XPxjLF58+vYfVvSucHsMgN+ik5tlttC1pbx6EhE8z+QD4o NsGa9gJZPVW/+cXf1IytkO0Sz+vqPkiZ3MGInGW+pl1uF8bNC1NGQ/Et97RTM1qIGvZa 8XVvOBxtxcOiVgutKMp83bcc8zna5QUhU2Kil2vXiWm9CveYbegYCBYruZ+pSuN00LPi EUzX2Q8IzlRzA/+g3KSaahBBJINaRVuO2M45G3fw/di9iGS2NbF52nx0JMCHHJlLz0dq BO1rTz6QHtE7+K7hhORaTN3vhdOVkWeJ9+rBLQPtiy88Wtcn6/ZPGc5GhmJJVvzJg7FX Ev3Q== 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=zYsReGwXgSK5nk6/DuWxuC9/I4eUocjE6JQzahh8ub8=; b=yqvK8ksefZdGF3AHrw4DX8eLSY4f4Td/h5rI2uzVfrhpIOc+sZAN41t2czfnBUkiYW naQKuGqTpfi9gSFp1wSHvOLr6ZAdyQ4e3h8kk7nzbfmM112QrtZbn2IGahbjWh6O2pT1 XL1sZPNKdqgNuX72aBeNSA9l6kE6NJrxUtdUF245bwJvMo4yYUsDllnR1SHYL+/ETUEg KqHUfFPfF433bYvjbd9lEfx4MpEmBs3rSQpE7Sb1/d4nVVxUPCEN44alHRHVYA7OzxSf CH4w8ElIQsxBXfXElnlZITIwQpkz1w/DlaeM31KnbJdwQkEcx0RT8vi8IXaZ5aW56WxX afNw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=NwykczK2; 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 v4si12638158pga.366.2019.04.04.02.12.46; Thu, 04 Apr 2019 02:13:02 -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=NwykczK2; 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 S1733243AbfDDJL6 (ORCPT + 99 others); Thu, 4 Apr 2019 05:11:58 -0400 Received: from mail.kernel.org ([198.145.29.99]:51880 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1733030AbfDDJL5 (ORCPT ); Thu, 4 Apr 2019 05:11:57 -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 40EE32054F; Thu, 4 Apr 2019 09:11:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1554369116; bh=4ZHzu6Nj+eNcUD3b8X7xVuToNRpq6124yjPBYt2rJjw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NwykczK2eONtSH7JDdp8vXGEOrme1dqkJbUPPVYh58Rxm7MY71Oz1wr3ca8a17ts5 6qRjgZVd2nKFqS0jlxszdTOKBXXTmjTwiQqn4q/PC9SUNzTYoq6GSf2HVAckd64l8p DY8j20F79L8LTWckyr26A/WJ/wmIQwQ6RuKplfvw= 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 5.0 080/246] powerpc/hugetlb: Handle mmap_min_addr correctly in get_unmapped_area callback Date: Thu, 4 Apr 2019 10:46:20 +0200 Message-Id: <20190404084621.935017873@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190404084619.236418459@linuxfoundation.org> References: <20190404084619.236418459@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 5.0-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