Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp1833018imm; Mon, 3 Sep 2018 10:35:59 -0700 (PDT) X-Google-Smtp-Source: ANB0VdYYnCzLweVTe66FbOa364Ze8ABHTDL4MBm5NdphEEIWNJzQzuJ85DG9ROupT4aK/p1sl0ac X-Received: by 2002:a63:d806:: with SMTP id b6-v6mr24735628pgh.347.1535996159318; Mon, 03 Sep 2018 10:35:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535996159; cv=none; d=google.com; s=arc-20160816; b=UWJC6DFlnyncjd33TA7uHlddgV84Vf1NgrcChvGNmVgrVjvTomcC53S02mB6KfLGWJ NshBVJjTxhlOGRBKwKAX5l/zzaK085dWYkFJEASbpci1kO+4BJ9qgUVvjCXJYatB+NWB tgMB9NHYG5dNwL7yyTP/bbl9BEvFheFp+6kIrVzkB/BTOMVOd/JwInEaC0Lxfa0whDXI KZqJfQQL0kPA+EmStz+SJ8YsBgT+18BQvOPsFvL5T0tttVeTl7ho6BBnc0JoiuU6KA0h iW0ynm9gaaA7j6tutY9YrJ3726DFpHBm6bVe8YUrfEylvIUdFFt46eNcoqyYGXIhyhGx Ld8A== 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=dW9eweRZc1H5MhzJiwgYdvcMTbaIiy5MFVn3/J6FUmo=; b=Fl5MGpbWpRaPQ3b/8FqFixHo2xDcPo5YPWQNDrgZ6zyrcsAmopZ8BtGFhfvjVzPqKc uW7I0H3/ZeOqj640Px06UtGm7e3tS+Iw0YIq/5yhX/WzQVESHORcrpglnp1oGqCZiPiI Dqt08Qn4wml8WTPK8k0yVgcN26Rd/INzc6D5TE2N4zpzu+UyMJgNUtsNYX3DVO/RG/Io uViWTVvXTjvaqi4zyM8YyfvOqt0K5BQ943E0iwDbLDAIp+GWdzIIXKuhSKeQMBqzbrbV i0duDSMdCC0epagf2h8yvFdbxXgiS16fYaiLGZr0v11ZBxhZs5jG8M62NaYd+z/uNEEo lGSA== 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 b19-v6si20740602pfb.89.2018.09.03.10.35.44; Mon, 03 Sep 2018 10:35:59 -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 S1731306AbeICVy1 (ORCPT + 99 others); Mon, 3 Sep 2018 17:54:27 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:47644 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729001AbeICVy1 (ORCPT ); Mon, 3 Sep 2018 17:54:27 -0400 Received: from localhost (ip-213-127-74-90.ip.prioritytelecom.net [213.127.74.90]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 8418DD16; Mon, 3 Sep 2018 17:33:17 +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.18 031/123] arm64: mm: check for upper PAGE_SHIFT bits in pfn_valid() Date: Mon, 3 Sep 2018 18:56:15 +0200 Message-Id: <20180903165720.805416906@linuxfoundation.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180903165719.499675257@linuxfoundation.org> References: <20180903165719.499675257@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.18-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