Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp1827322imm; Mon, 3 Sep 2018 10:27:33 -0700 (PDT) X-Google-Smtp-Source: ANB0Vda8BToxnypkzSF8ieMKgbVzt2rLJeTHWYpgiPiDunTTpz5hUr29QTyEY8uKI5tgYp25BZDW X-Received: by 2002:a63:4306:: with SMTP id q6-v6mr26129401pga.181.1535995653346; Mon, 03 Sep 2018 10:27:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535995653; cv=none; d=google.com; s=arc-20160816; b=dd7oS1E4nYaD5YarvdnfqtTPMp8ljzitaHy2pnr8Q1bBd0BdNOXF+vUiWWLkfG4Ro/ UVUhfED0gYJ5kHkHm1yLKCVgB7vsD3C5uk3tLpKppZvQZAZbyeX21254kd68BQ+jkKip faGBtyZ7VJV4P0vjZ8qQ71NOP/RpQHObK0qeGU6PYiUUw4Ejc9dKswCQAhHqy411wxjU hfHEvQGkXG62+sa37QHe1cbyvFlzszBHXHOpTYqXuCq6KwIW+jO0bseulOGioT+3qDfN KG/rc9ZxxS8BOD2GpQEnaQGCI373k27d715W22s8Wgaeq/rMyMd9Moq1q0nSwOD83Xls p0Rw== 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=JSUe7aXVNDv0GAYl9h8WJ/ewJU6N5iyIflNgBjHyIMg=; b=c5VVeTxgESElmrn2CAm/DhFZoIEwAW9uJb4aUMHtoJWlLZNBC0bGrQdHQM9MIsfCo8 7mu/raJGBPlvoRbt6rOnLa4N82u2j3fvUxcdr3ZBbpMmF7/hxt3A2F3eLcKLDqEowGxz 2eInYBWH6ppjoxcc9Kk/LwcAUZt/FoIA1SQ6t7JrKza0uTApiK/mrzDtJYpkzw/b6Db2 05uCcvujSMTJ07Vzw63NV7zJSmJZq1Rsq3R77ENDgCDpwkksZtw9gDL4iY8Nm74jdMnq 3Du2n6zp9mOUqJTAtnWEZjoAxxKh/jrpRjL+3TuvgzPVD6RHH0Bt5jl7SdrmgKvpcPtO d3Zw== 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 q8-v6si18128430pli.355.2018.09.03.10.27.18; Mon, 03 Sep 2018 10:27:33 -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 S1730804AbeICVrX (ORCPT + 99 others); Mon, 3 Sep 2018 17:47:23 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:45870 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728500AbeICVrW (ORCPT ); Mon, 3 Sep 2018 17:47:22 -0400 Received: from localhost (ip-213-127-74-90.ip.prioritytelecom.net [213.127.74.90]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 17121D24; Mon, 3 Sep 2018 17:26:14 +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.14 098/165] arm64: mm: check for upper PAGE_SHIFT bits in pfn_valid() Date: Mon, 3 Sep 2018 18:56:24 +0200 Message-Id: <20180903165700.438229557@linuxfoundation.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180903165655.003605184@linuxfoundation.org> References: <20180903165655.003605184@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.14-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 @@ -287,7 +287,11 @@ static void __init zone_sizes_init(unsig #ifdef CONFIG_HAVE_ARCH_PFN_VALID int pfn_valid(unsigned long pfn) { - return memblock_is_map_memory(pfn << PAGE_SHIFT); + phys_addr_t addr = pfn << PAGE_SHIFT; + + if ((addr >> PAGE_SHIFT) != pfn) + return 0; + return memblock_is_map_memory(addr); } EXPORT_SYMBOL(pfn_valid); #endif