Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp2993107yba; Mon, 22 Apr 2019 17:22:23 -0700 (PDT) X-Google-Smtp-Source: APXvYqwChhNE5FqkQeHAE0mhRZNepUL9flkuCM/FpCxYyDI8Ju7g4XLBI6jbW8WvG1m3WYwprdAL X-Received: by 2002:a17:902:e091:: with SMTP id cb17mr22743526plb.222.1555978943254; Mon, 22 Apr 2019 17:22:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1555978943; cv=none; d=google.com; s=arc-20160816; b=j8b2p9LGWtvK5NvglHyEA5Dvn4IttYEAw4q8LPLmEWcrQXmpBkXboUh+W/DMCg+D4W x6l43QdoKI/0q/yXPKRrKKqeE7d5gDg4fEUwXn1f600L7fCy0Bz7jvobA4TL+JtVwoUv lm5gxxnxqE056g7heB6WJhsp3hM09spFnUEfhpTI/8DYscrzBrrNYZvHtr55xcRqEKV/ fXFaXi/+YaEB/nRAfLQjqFZkEuCpx6NnUp2d62TXflytRYLGh74Ud49CugQhG5P44ALH 0MfGkU/k7umyS4MhPAbJ34ScLwtgorTAmIN1doNtiPcVsc4vLswthjUD9LFjw9sAb56y f2hQ== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=1VHhyUNobjk884Y9nlMb0v583F3nZ6ZAZs0Wmw74z1c=; b=yLcDIH0j8aselJF/pJKcnxuW88h/Ax6EAjhe4HYOzHdQ2g3nTXo7AgK4iIjJ2oM9Bq TT09/WJby8sOVMIsC9u5sDPQZCOnyF58BYLep5bfzBvAK6xNLqEZUsdzYtFdlUjnSCkS IYmoLQJfHywtAcy0bntALrqK9Mx4t/A/+4yVAnDcq4JdhHTNr8sa9NUsj4lZbC8gnpjo lOYcboMYULqlOZhy9yUa13OjMeorT0P5LMMv3aqFWqV5pUCVEfjs7dk+JZera922Zo2V b5UU1U3cgFdPtItjlLv3gSiFv6fsoj6ag2mqJYFWPHu6lOOEh6SRMyjGlP3HpWimLZCf 4qWQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Gi57aGyW; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q190si15729714pfc.215.2019.04.22.17.22.08; Mon, 22 Apr 2019 17:22:23 -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=Gi57aGyW; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732350AbfDVUGz (ORCPT + 99 others); Mon, 22 Apr 2019 16:06:55 -0400 Received: from mail.kernel.org ([198.145.29.99]:45488 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729456AbfDVTo0 (ORCPT ); Mon, 22 Apr 2019 15:44:26 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 6B17F218E0; Mon, 22 Apr 2019 19:44:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1555962265; bh=6Jgx9YpbHstl/xcSD121vWXM28lK2hGsq9iqOgm/BXs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Gi57aGyW621HzEJMbGCdzG5ECc99rBx6iGyVq5DaTJGJ/Bxx41GVhQSeNr6QTZafQ 4HuJlIzGYYRsZpP+nChUTti4RN7HEUjKyAyWug1Ip8vTgVm39KERwHKdjbzWSsd/b0 TbopuZDiee1Gzp5qxXGJ9mU2YD4DTuu+6LnieMqU= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Ralph Campbell , Thomas Gleixner , Craig Bergstrom , Linus Torvalds , Boris Ostrovsky , Fengguang Wu , Greg Kroah-Hartman , Hans Verkuil , Mauro Carvalho Chehab , Peter Zijlstra , Sander Eikelenboom , Sean Young , Sasha Levin Subject: [PATCH AUTOSEL 5.0 73/98] x86/mm: Don't exceed the valid physical address space Date: Mon, 22 Apr 2019 15:41:40 -0400 Message-Id: <20190422194205.10404-73-sashal@kernel.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190422194205.10404-1-sashal@kernel.org> References: <20190422194205.10404-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Ralph Campbell [ Upstream commit 92c77f7c4d5dfaaf45b2ce19360e69977c264766 ] valid_phys_addr_range() is used to sanity check the physical address range of an operation, e.g., access to /dev/mem. It uses __pa(high_memory) internally. If memory is populated at the end of the physical address space, then __pa(high_memory) is outside of the physical address space because: high_memory = (void *)__va(max_pfn * PAGE_SIZE - 1) + 1; For the comparison in valid_phys_addr_range() this is not an issue, but if CONFIG_DEBUG_VIRTUAL is enabled, __pa() maps to __phys_addr(), which verifies that the resulting physical address is within the valid physical address space of the CPU. So in the case that memory is populated at the end of the physical address space, this is not true and triggers a VIRTUAL_BUG_ON(). Use __pa(high_memory - 1) to prevent the conversion from going beyond the end of valid physical addresses. Fixes: be62a3204406 ("x86/mm: Limit mmap() of /dev/mem to valid physical addresses") Signed-off-by: Ralph Campbell Signed-off-by: Thomas Gleixner Cc: Craig Bergstrom Cc: Linus Torvalds Cc: Boris Ostrovsky Cc: Fengguang Wu Cc: Greg Kroah-Hartman Cc: Hans Verkuil Cc: Mauro Carvalho Chehab Cc: Peter Zijlstra Cc: Sander Eikelenboom Cc: Sean Young Link: https://lkml.kernel.org/r/20190326001817.15413-2-rcampbell@nvidia.com Signed-off-by: Sasha Levin (Microsoft) --- arch/x86/mm/mmap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/x86/mm/mmap.c b/arch/x86/mm/mmap.c index db3165714521..dc726e07d8ba 100644 --- a/arch/x86/mm/mmap.c +++ b/arch/x86/mm/mmap.c @@ -230,7 +230,7 @@ bool mmap_address_hint_valid(unsigned long addr, unsigned long len) /* Can we access it for direct reading/writing? Must be RAM: */ int valid_phys_addr_range(phys_addr_t addr, size_t count) { - return addr + count <= __pa(high_memory); + return addr + count - 1 <= __pa(high_memory - 1); } /* Can we access it through mmap? Must be a valid physical address: */ -- 2.19.1