Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp1810725imm; Mon, 3 Sep 2018 10:02:32 -0700 (PDT) X-Google-Smtp-Source: ANB0VdbMPlDA/c/TJx4J3rd8IKCMDreENHqwjThEr+YW/QRi2muYJJBac2g3GV9pCVEKA1/uBaJl X-Received: by 2002:a63:ea0c:: with SMTP id c12-v6mr27282073pgi.158.1535994152810; Mon, 03 Sep 2018 10:02:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535994152; cv=none; d=google.com; s=arc-20160816; b=ND01a1OZcmuisq4YqcgIlY5C4UZ4NYPrzYV4DhzW+D6GVahg8jXhE7/QeNIRkJ31Ay AnLZJKnNmstF94Xu98q5ovnotIudFfb4CQ0Ap11NTOkJrGioz1YdnCftwLV+v4+87b4r cJbIMDbSm7p93VKeFYsdnPgnqpLaeeDEMilO+J+hGB75zAKwoM5tgI/LbB9s9uDUeaDP 0ni1ehvxc/67exolGns7Dmhyg+ERcZwQ/7Uh4JcwaNZEG5eLnB6RED4/bEa+SsIIeXM3 FgYQnYmQJWyOX1QgBEdqsK+/ex14Tjn8MkveA8FwJk6QUtuNuLH1T+NJD/inMHeOAFSW E2tw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=Gt9xHdA7VGxHsZnDjYmJeqEA9QQl9eAu90+bXITRlwA=; b=RbIjSoQ2ifHAaNWPyht+a7klLaxWfsS70aU+ixckW0g1jyJGY5Vhn34c78dCKoSY6U VzWnW6DtNctBtu7zr0S3BJSuMfVJeN6o6uj6PTit8ja4fO1Q7Ggr96v5HBksfdOIpev3 HAiJ/DiHxQJvyQ0EkCwUS/vDmAHPq2SiRCzohcxSGTQr5JKMtlbEcNDJpzOBYk+NYGph DxV4e0coZqjY+pIq1Fxw8tfomMDBoG8BXjt2kg0zdSX3Ojgx4LN9niOiTkW38qIO4LWP pquLbiQ26bqNIicz3/njH53z7gt0cXqqe75SyrA+js+KoYYgunhSbx69HYuED+TxTBWd BjKA== ARC-Authentication-Results: i=1; mx.google.com; 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 w3-v6si18511373pgw.135.2018.09.03.10.02.17; Mon, 03 Sep 2018 10:02: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; 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 S1728428AbeICVVr (ORCPT + 99 others); Mon, 3 Sep 2018 17:21:47 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:38576 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728410AbeICVVq (ORCPT ); Mon, 3 Sep 2018 17:21:46 -0400 Received: from localhost (ip-213-127-74-90.ip.prioritytelecom.net [213.127.74.90]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 5261ECFB; Mon, 3 Sep 2018 17:00:46 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Greg Hackmann , Will Deacon Subject: [PATCH 4.4 50/80] arm64: mm: check for upper PAGE_SHIFT bits in pfn_valid() Date: Mon, 3 Sep 2018 18:49:28 +0200 Message-Id: <20180903164936.153438049@linuxfoundation.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180903164934.171677301@linuxfoundation.org> References: <20180903164934.171677301@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.4-stable review patch. If anyone has any objections, please let me know. ------------------ From: Greg Hackmann commit 5ad356eabc47d26a92140a0c4b20eba471c10de3 upstream. ARM64's pfn_valid() shifts away the upper PAGE_SHIFT bits of the input before seeing if the PFN is valid. This leads to false positives when some of the upper bits are set, but the lower bits match a valid PFN. For example, the following userspace code looks up a bogus entry in /proc/kpageflags: int pagemap = open("/proc/self/pagemap", O_RDONLY); int pageflags = open("/proc/kpageflags", O_RDONLY); uint64_t pfn, val; lseek64(pagemap, [...], SEEK_SET); read(pagemap, &pfn, sizeof(pfn)); if (pfn & (1UL << 63)) { /* valid PFN */ pfn &= ((1UL << 55) - 1); /* clear flag bits */ pfn |= (1UL << 55); lseek64(pageflags, pfn * sizeof(uint64_t), SEEK_SET); read(pageflags, &val, sizeof(val)); } On ARM64 this causes the userspace process to crash with SIGSEGV rather than reading (1 << KPF_NOPAGE). kpageflags_read() treats the offset as valid, and stable_page_flags() will try to access an address between the user and kernel address ranges. Fixes: c1cc1552616d ("arm64: MMU initialisation") Cc: stable@vger.kernel.org Signed-off-by: Greg Hackmann Signed-off-by: Will Deacon Signed-off-by: Greg Kroah-Hartman --- arch/arm64/mm/init.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) --- a/arch/arm64/mm/init.c +++ b/arch/arm64/mm/init.c @@ -120,7 +120,11 @@ static void __init zone_sizes_init(unsig #ifdef CONFIG_HAVE_ARCH_PFN_VALID int pfn_valid(unsigned long pfn) { - return memblock_is_memory(pfn << PAGE_SHIFT); + phys_addr_t addr = pfn << PAGE_SHIFT; + + if ((addr >> PAGE_SHIFT) != pfn) + return 0; + return memblock_is_memory(addr); } EXPORT_SYMBOL(pfn_valid); #endif