Received: by 2002:a25:5b86:0:0:0:0:0 with SMTP id p128csp473581ybb; Thu, 28 Mar 2019 06:19:38 -0700 (PDT) X-Google-Smtp-Source: APXvYqwt6urN4kElIKXNhtOmgBtWfjT87YdXzJePa3eN7nZ9ERj0cP4uxPAFpNYPXZ0LoOQIIVkK X-Received: by 2002:a17:902:8d89:: with SMTP id v9mr25602457plo.230.1553779178508; Thu, 28 Mar 2019 06:19:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553779178; cv=none; d=google.com; s=arc-20160816; b=wlGIkCddVjmbVTf9HJrpr8hTFogIrIdpVnDl3vkJjk439YdBukAZyNXrNkX0Ej9ajY dKpSA3Kk61GrRqvUaoqSJALFKDhh2OoHI4NaIwUvJKEJ47dV7mjI8jWNc9YZlHWj2OB/ hv/owi08ig6c65V27ifa9zgAF5p2bChwJOi0/lokr3t/4+QYOgf0kXZub1KxQXJ+cPx2 cDmp7U5/XUydpDC+f6G2sMplqexf+zj3lMuyRmt4l5GKFg5Xl+/rpAhxdZmYLuGhkNXb a0SuhfKp5VSwFkH97A/lnDsWSS/69oUVa79pPThsfKH0+OrHbKy73zhyHUYwGT8NnVBk oqJw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-disposition :content-transfer-encoding:mime-version:robot-unsubscribe:robot-id :git-commit-id:subject:to:references:in-reply-to:reply-to:cc :message-id:from:date; bh=GlFbJCze0npL4pOIfmQIP415IKC0JlbNi3tm9CIx6KQ=; b=Q5hTK/KB/vrOsD7tuarERt7/1l4eyoiYiaBbur6M8BlGCQsnrnv7KiVZq9isAcJ3MJ UJ3zP6ch3XypmObxJnZpH2dzAF5OQROHO0W2hTMXSD1VPzgJO5Vt3t8Ld2m3L4RigAbf lQFJCbK7vB7ypYRyES+TPEuOMiS3Z/+n3r66mm+YCpvHetQDFS69nQpIDb955vtmt3nF XIy6OFZy+P5Vaz2Fia4ACCiz1vg4ouBcPFAmx98gMlCI357Ovmrdkx+AQopLHwuhn34V kiWf2ElFnIwVvH7l/qabQ6sk6nB6Xso6p8LLRfOCLNOmRrb8wdM6lL6HQDoqmg0ZcsjK EC/A== 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 w12si20438859pgr.104.2019.03.28.06.19.22; Thu, 28 Mar 2019 06:19:38 -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 S1726687AbfC1NS2 (ORCPT + 99 others); Thu, 28 Mar 2019 09:18:28 -0400 Received: from terminus.zytor.com ([198.137.202.136]:40767 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725779AbfC1NS2 (ORCPT ); Thu, 28 Mar 2019 09:18:28 -0400 Received: from terminus.zytor.com (localhost [127.0.0.1]) by terminus.zytor.com (8.15.2/8.15.2) with ESMTPS id x2SDGE1g3331780 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NO); Thu, 28 Mar 2019 06:16:14 -0700 Received: (from tipbot@localhost) by terminus.zytor.com (8.15.2/8.15.2/Submit) id x2SDG9TR3331769; Thu, 28 Mar 2019 06:16:09 -0700 Date: Thu, 28 Mar 2019 06:16:09 -0700 X-Authentication-Warning: terminus.zytor.com: tipbot set sender to tipbot@zytor.com using -f From: tip-bot for Ralph Campbell Message-ID: Cc: rcampbell@nvidia.com, linux@eikelenboom.it, boris.ostrovsky@oracle.com, mchehab@s-opensource.com, linux-kernel@vger.kernel.org, hans.verkuil@cisco.com, mingo@kernel.org, tglx@linutronix.de, craigb@google.com, hpa@zytor.com, torvalds@linux-foundation.org, sean@mess.org, fengguang.wu@intel.com, peterz@infradead.org, gregkh@linuxfoundation.org Reply-To: peterz@infradead.org, fengguang.wu@intel.com, gregkh@linuxfoundation.org, torvalds@linux-foundation.org, sean@mess.org, linux-kernel@vger.kernel.org, mchehab@s-opensource.com, hans.verkuil@cisco.com, mingo@kernel.org, tglx@linutronix.de, hpa@zytor.com, craigb@google.com, rcampbell@nvidia.com, linux@eikelenboom.it, boris.ostrovsky@oracle.com In-Reply-To: <20190326001817.15413-2-rcampbell@nvidia.com> References: <20190326001817.15413-2-rcampbell@nvidia.com> To: linux-tip-commits@vger.kernel.org Subject: [tip:x86/urgent] x86/mm: Don't exceed the valid physical address space Git-Commit-ID: 92c77f7c4d5dfaaf45b2ce19360e69977c264766 X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline X-Spam-Status: No, score=0.1 required=5.0 tests=ALL_TRUSTED,BAYES_00, DATE_IN_FUTURE_03_06 autolearn=no autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on terminus.zytor.com Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit-ID: 92c77f7c4d5dfaaf45b2ce19360e69977c264766 Gitweb: https://git.kernel.org/tip/92c77f7c4d5dfaaf45b2ce19360e69977c264766 Author: Ralph Campbell AuthorDate: Mon, 25 Mar 2019 17:18:17 -0700 Committer: Thomas Gleixner CommitDate: Thu, 28 Mar 2019 14:13:51 +0100 x86/mm: Don't exceed the valid physical address space 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 --- 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: */