linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Sasha Levin <sashal@kernel.org>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Cc: Ralph Campbell <rcampbell@nvidia.com>,
	Thomas Gleixner <tglx@linutronix.de>,
	Craig Bergstrom <craigb@google.com>,
	Linus Torvalds <torvalds@linux-foundation.org>,
	Boris Ostrovsky <boris.ostrovsky@oracle.com>,
	Fengguang Wu <fengguang.wu@intel.com>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Hans Verkuil <hans.verkuil@cisco.com>,
	Mauro Carvalho Chehab <mchehab@s-opensource.com>,
	Peter Zijlstra <peterz@infradead.org>,
	Sander Eikelenboom <linux@eikelenboom.it>,
	Sean Young <sean@mess.org>, Sasha Levin <sashal@kernel.org>
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	[thread overview]
Message-ID: <20190422194205.10404-73-sashal@kernel.org> (raw)
In-Reply-To: <20190422194205.10404-1-sashal@kernel.org>

From: Ralph Campbell <rcampbell@nvidia.com>

[ 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 <rcampbell@nvidia.com>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Cc: Craig Bergstrom <craigb@google.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Boris Ostrovsky <boris.ostrovsky@oracle.com>
Cc: Fengguang Wu <fengguang.wu@intel.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Hans Verkuil <hans.verkuil@cisco.com>
Cc: Mauro Carvalho Chehab <mchehab@s-opensource.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Sander Eikelenboom <linux@eikelenboom.it>
Cc: Sean Young <sean@mess.org>

Link: https://lkml.kernel.org/r/20190326001817.15413-2-rcampbell@nvidia.com
Signed-off-by: Sasha Levin (Microsoft) <sashal@kernel.org>
---
 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


  parent reply	other threads:[~2019-04-22 20:06 UTC|newest]

Thread overview: 104+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-04-22 19:40 [PATCH AUTOSEL 5.0 01/98] arm64: dts: renesas: r8a77990: Fix SCIF5 DMA channels Sasha Levin
2019-04-22 19:40 ` [PATCH AUTOSEL 5.0 02/98] ARM: dts: bcm283x: Fix hdmi hpd gpio pull Sasha Levin
2019-04-22 19:40 ` [PATCH AUTOSEL 5.0 03/98] s390: limit brk randomization to 32MB Sasha Levin
2019-04-22 19:40 ` [PATCH AUTOSEL 5.0 04/98] mt76x02: fix hdr pointer in write txwi for USB Sasha Levin
2019-04-22 19:40 ` [PATCH AUTOSEL 5.0 05/98] mt76: mt76x2: fix external LNA gain settings Sasha Levin
2019-04-22 19:40 ` [PATCH AUTOSEL 5.0 06/98] mt76: mt76x2: fix 2.4 GHz channel " Sasha Levin
2019-04-22 19:40 ` [PATCH AUTOSEL 5.0 07/98] net: ieee802154: fix a potential NULL pointer dereference Sasha Levin
2019-04-22 19:40 ` [PATCH AUTOSEL 5.0 08/98] ieee802154: hwsim: propagate genlmsg_reply return code Sasha Levin
2019-04-22 19:40 ` [PATCH AUTOSEL 5.0 09/98] Btrfs: fix file corruption after snapshotting due to mix of buffered/DIO writes Sasha Levin
2019-04-22 19:40 ` [PATCH AUTOSEL 5.0 10/98] net: stmmac: don't set own bit too early for jumbo frames Sasha Levin
2019-04-22 19:40 ` [PATCH AUTOSEL 5.0 11/98] net: stmmac: fix jumbo frame sending with non-linear skbs Sasha Levin
2019-04-22 19:40 ` [PATCH AUTOSEL 5.0 12/98] qlcnic: Avoid potential NULL pointer dereference Sasha Levin
2019-04-22 19:40 ` [PATCH AUTOSEL 5.0 13/98] xsk: fix umem memory leak on cleanup Sasha Levin
2019-04-22 19:40 ` [PATCH AUTOSEL 5.0 14/98] staging: axis-fifo: add CONFIG_OF dependency Sasha Levin
2019-04-22 19:40 ` [PATCH AUTOSEL 5.0 15/98] staging, mt7621-pci: fix build without pci support Sasha Levin
2019-04-22 19:40 ` [PATCH AUTOSEL 5.0 16/98] netfilter: nft_set_rbtree: check for inactive element after flag mismatch Sasha Levin
2019-04-22 19:40 ` [PATCH AUTOSEL 5.0 17/98] netfilter: bridge: set skb transport_header before entering NF_INET_PRE_ROUTING Sasha Levin
2019-04-22 19:40 ` [PATCH AUTOSEL 5.0 18/98] netfilter: fix NETFILTER_XT_TARGET_TEE dependencies Sasha Levin
2019-04-22 19:40 ` [PATCH AUTOSEL 5.0 19/98] netfilter: ip6t_srh: fix NULL pointer dereferences Sasha Levin
2019-04-22 19:40 ` [PATCH AUTOSEL 5.0 20/98] netfilter: nf_tables: bogus EBUSY in helper removal from transaction Sasha Levin
2019-04-22 19:40 ` [PATCH AUTOSEL 5.0 21/98] s390/qeth: fix race when initializing the IP address table Sasha Levin
2019-04-22 19:40 ` [PATCH AUTOSEL 5.0 22/98] ARM: imx51: fix a leaked reference by adding missing of_node_put Sasha Levin
2019-04-22 19:40 ` [PATCH AUTOSEL 5.0 23/98] sc16is7xx: missing unregister/delete driver on error in sc16is7xx_init() Sasha Levin
2019-04-22 19:40 ` [PATCH AUTOSEL 5.0 24/98] serial: ar933x_uart: Fix build failure with disabled console Sasha Levin
2019-04-22 19:40 ` [PATCH AUTOSEL 5.0 25/98] KVM: arm64: Reset the PMU in preemptible context Sasha Levin
2019-04-22 19:40 ` [PATCH AUTOSEL 5.0 26/98] arm64: KVM: Always set ICH_HCR_EL2.EN if GICv4 is enabled Sasha Levin
2019-04-22 19:40 ` [PATCH AUTOSEL 5.0 27/98] KVM: arm/arm64: vgic-its: Take the srcu lock when writing to guest memory Sasha Levin
2019-04-22 19:40 ` [PATCH AUTOSEL 5.0 28/98] KVM: arm/arm64: vgic-its: Take the srcu lock when parsing the memslots Sasha Levin
2019-04-22 19:40 ` [PATCH AUTOSEL 5.0 29/98] KVM: arm/arm64: Enforce PTE mappings at stage2 when needed Sasha Levin
2019-04-23  9:27   ` Suzuki K Poulose
2019-05-02 12:50     ` Sasha Levin
2019-04-22 19:40 ` [PATCH AUTOSEL 5.0 30/98] usb: dwc3: pci: add support for Comet Lake PCH ID Sasha Levin
2019-04-22 19:40 ` [PATCH AUTOSEL 5.0 31/98] usb: gadget: net2280: Fix overrun of OUT messages Sasha Levin
2019-04-22 19:40 ` [PATCH AUTOSEL 5.0 32/98] usb: gadget: net2280: Fix net2280_dequeue() Sasha Levin
2019-04-22 19:41 ` [PATCH AUTOSEL 5.0 33/98] usb: gadget: net2272: Fix net2272_dequeue() Sasha Levin
2019-04-22 19:41 ` [PATCH AUTOSEL 5.0 34/98] ARM: dts: pfla02: increase phy reset duration Sasha Levin
2019-04-22 19:41 ` [PATCH AUTOSEL 5.0 35/98] i2c: i801: Add support for Intel Comet Lake Sasha Levin
2019-04-22 19:41 ` [PATCH AUTOSEL 5.0 36/98] KVM: arm/arm64: Fix handling of stage2 huge mappings Sasha Levin
2019-04-22 19:41 ` [PATCH AUTOSEL 5.0 37/98] net: ks8851: Dequeue RX packets explicitly Sasha Levin
2019-04-22 19:41 ` [PATCH AUTOSEL 5.0 38/98] net: ks8851: Reassert reset pin if chip ID check fails Sasha Levin
2019-04-22 19:41 ` [PATCH AUTOSEL 5.0 39/98] net: ks8851: Delay requesting IRQ until opened Sasha Levin
2019-04-22 19:41 ` [PATCH AUTOSEL 5.0 40/98] net: ks8851: Set initial carrier state to down Sasha Levin
2019-04-22 19:41 ` [PATCH AUTOSEL 5.0 41/98] staging: rtl8188eu: Fix potential NULL pointer dereference of kcalloc Sasha Levin
2019-04-22 19:41 ` [PATCH AUTOSEL 5.0 42/98] staging: rtlwifi: rtl8822b: fix to avoid potential NULL pointer dereference Sasha Levin
2019-04-22 19:41 ` [PATCH AUTOSEL 5.0 43/98] staging: rtl8712: uninitialized memory in read_bbreg_hdl() Sasha Levin
2019-04-22 19:41 ` [PATCH AUTOSEL 5.0 44/98] staging: rtlwifi: Fix potential NULL pointer dereference of kzalloc Sasha Levin
2019-04-22 19:41 ` [PATCH AUTOSEL 5.0 45/98] net: phy: Add DP83825I to the DP83822 driver Sasha Levin
2019-04-22 19:41 ` [PATCH AUTOSEL 5.0 46/98] net: macb: Add null check for PCLK and HCLK Sasha Levin
2019-04-22 19:41 ` [PATCH AUTOSEL 5.0 47/98] net/sched: don't dereference a->goto_chain to read the chain index Sasha Levin
2019-04-22 19:41 ` [PATCH AUTOSEL 5.0 48/98] ARM: dts: imx6qdl: Fix typo in imx6qdl-icore-rqs.dtsi Sasha Levin
2019-04-22 19:41 ` [PATCH AUTOSEL 5.0 49/98] drm/tegra: hub: Fix dereference before check Sasha Levin
2019-04-22 19:41 ` [PATCH AUTOSEL 5.0 50/98] NFS: Fix a typo in nfs_init_timeout_values() Sasha Levin
2019-04-22 19:41 ` [PATCH AUTOSEL 5.0 51/98] net: xilinx: fix possible object reference leak Sasha Levin
2019-04-22 19:41 ` [PATCH AUTOSEL 5.0 52/98] net: ibm: " Sasha Levin
2019-04-22 19:41 ` [PATCH AUTOSEL 5.0 53/98] net: ethernet: ti: " Sasha Levin
2019-04-22 19:41 ` [PATCH AUTOSEL 5.0 54/98] drm: Fix drm_release() and device unplug Sasha Levin
2019-04-22 19:41 ` [PATCH AUTOSEL 5.0 55/98] gpio: aspeed: fix a potential NULL pointer dereference Sasha Levin
2019-04-22 19:41 ` [PATCH AUTOSEL 5.0 56/98] drm/meson: Fix invalid pointer in meson_drv_unbind() Sasha Levin
2019-04-22 19:41 ` [PATCH AUTOSEL 5.0 57/98] drm/meson: Uninstall IRQ handler Sasha Levin
2019-04-22 19:41 ` [PATCH AUTOSEL 5.0 58/98] ARM: davinci: fix build failure with allnoconfig Sasha Levin
2019-04-22 19:41 ` [PATCH AUTOSEL 5.0 59/98] sbitmap: order READ/WRITE freed instance and setting clear bit Sasha Levin
2019-04-22 19:41 ` [PATCH AUTOSEL 5.0 60/98] staging: vc04_services: Fix an error code in vchiq_probe() Sasha Levin
2019-04-22 19:41 ` [PATCH AUTOSEL 5.0 61/98] libceph: fix breakage caused by multipage bvecs Sasha Levin
2019-04-23  8:28   ` Ilya Dryomov
2019-05-02 12:51     ` Sasha Levin
2019-04-22 19:41 ` [PATCH AUTOSEL 5.0 62/98] scsi: mpt3sas: Fix kernel panic during expander reset Sasha Levin
2019-04-22 19:41 ` [PATCH AUTOSEL 5.0 63/98] scsi: aacraid: Insure we don't access PCIe space during AER/EEH Sasha Levin
2019-04-22 19:41 ` [PATCH AUTOSEL 5.0 64/98] scsi: qla4xxx: fix a potential NULL pointer dereference Sasha Levin
2019-04-22 19:41 ` [PATCH AUTOSEL 5.0 65/98] usb: usb251xb: fix to avoid " Sasha Levin
2019-04-22 19:41 ` [PATCH AUTOSEL 5.0 66/98] leds: trigger: netdev: fix refcnt leak on interface rename Sasha Levin
2019-04-22 19:41 ` [PATCH AUTOSEL 5.0 67/98] SUNRPC: fix uninitialized variable warning Sasha Levin
2019-04-22 19:41 ` [PATCH AUTOSEL 5.0 68/98] x86/realmode: Don't leak the trampoline kernel address Sasha Levin
2019-04-22 19:41 ` [PATCH AUTOSEL 5.0 69/98] usb: u132-hcd: fix resource leak Sasha Levin
2019-04-22 19:41 ` [PATCH AUTOSEL 5.0 70/98] tty: fix NULL pointer issue when tty_port ops is not set Sasha Levin
2019-04-22 20:40   ` Greg Kroah-Hartman
2019-05-02 12:53     ` Sasha Levin
2019-04-22 19:41 ` [PATCH AUTOSEL 5.0 71/98] ceph: fix use-after-free on symlink traversal Sasha Levin
2019-04-22 19:41 ` [PATCH AUTOSEL 5.0 72/98] scsi: zfcp: reduce flood of fcrscn1 trace records on multi-element RSCN Sasha Levin
2019-04-22 19:41 ` Sasha Levin [this message]
2019-04-22 19:41 ` [PATCH AUTOSEL 5.0 74/98] libata: fix using DMA buffers on stack Sasha Levin
2019-04-22 19:41 ` [PATCH AUTOSEL 5.0 75/98] kbuild: skip parsing pre sub-make code for recursion Sasha Levin
2019-04-22 19:41 ` [PATCH AUTOSEL 5.0 76/98] afs: Fix StoreData op marshalling Sasha Levin
2019-04-22 19:41 ` [PATCH AUTOSEL 5.0 77/98] gpio: of: Check propname before applying "cs-gpios" quirks Sasha Levin
2019-04-22 19:41 ` [PATCH AUTOSEL 5.0 78/98] gpio: of: Check for "spi-cs-high" in child instead of parent node Sasha Levin
2019-04-22 19:41 ` [PATCH AUTOSEL 5.0 79/98] KVM: nVMX: Do not inherit quadrant and invalid for the root shadow EPT Sasha Levin
2019-04-22 19:41 ` [PATCH AUTOSEL 5.0 80/98] KVM: SVM: Workaround errata#1096 (insn_len maybe zero on SMAP violation) Sasha Levin
2019-04-22 19:41 ` [PATCH AUTOSEL 5.0 81/98] kvm/x86: Move MSR_IA32_ARCH_CAPABILITIES to array emulated_msrs Sasha Levin
2019-04-22 19:41 ` [PATCH AUTOSEL 5.0 82/98] x86/kvm/hyper-v: avoid spurious pending stimer on vCPU init Sasha Levin
2019-04-22 19:41 ` [PATCH AUTOSEL 5.0 83/98] KVM: selftests: assert on exit reason in CR4/cpuid sync test Sasha Levin
2019-04-22 19:41 ` [PATCH AUTOSEL 5.0 84/98] KVM: selftests: explicitly disable PIE for tests Sasha Levin
2019-04-22 19:41 ` [PATCH AUTOSEL 5.0 85/98] KVM: selftests: disable stack protector for all KVM tests Sasha Levin
2019-04-22 19:41 ` [PATCH AUTOSEL 5.0 86/98] KVM: selftests: complete IO before migrating guest state Sasha Levin
2019-04-22 19:41 ` [PATCH AUTOSEL 5.0 87/98] gpio: of: Fix of_gpiochip_add() error path Sasha Levin
2019-04-22 19:41 ` [PATCH AUTOSEL 5.0 88/98] nvme-multipath: relax ANA state check Sasha Levin
2019-04-22 19:41 ` [PATCH AUTOSEL 5.0 89/98] nvmet: fix building bvec from sg list Sasha Levin
2019-04-22 19:41 ` [PATCH AUTOSEL 5.0 90/98] nvmet: fix error flow during ns enable Sasha Levin
2019-04-22 19:41 ` [PATCH AUTOSEL 5.0 91/98] perf cs-etm: Add missing case value Sasha Levin
2019-04-22 19:41 ` [PATCH AUTOSEL 5.0 92/98] perf machine: Update kernel map address and re-order properly Sasha Levin
2019-04-22 19:42 ` [PATCH AUTOSEL 5.0 93/98] kconfig/[mn]conf: handle backspace (^H) key Sasha Levin
2019-04-22 19:42 ` [PATCH AUTOSEL 5.0 94/98] iommu/amd: Reserve exclusion range in iova-domain Sasha Levin
2019-04-22 19:42 ` [PATCH AUTOSEL 5.0 95/98] kasan: fix variable 'tag' set but not used warning Sasha Levin
2019-04-22 19:42 ` [PATCH AUTOSEL 5.0 96/98] ptrace: take into account saved_sigmask in PTRACE{GET,SET}SIGMASK Sasha Levin
2019-04-22 19:42 ` [PATCH AUTOSEL 5.0 97/98] leds: pca9532: fix a potential NULL pointer dereference Sasha Levin
2019-04-22 19:42 ` [PATCH AUTOSEL 5.0 98/98] leds: trigger: netdev: use memcpy in device_name_store Sasha Levin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190422194205.10404-73-sashal@kernel.org \
    --to=sashal@kernel.org \
    --cc=boris.ostrovsky@oracle.com \
    --cc=craigb@google.com \
    --cc=fengguang.wu@intel.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=hans.verkuil@cisco.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@eikelenboom.it \
    --cc=mchehab@s-opensource.com \
    --cc=peterz@infradead.org \
    --cc=rcampbell@nvidia.com \
    --cc=sean@mess.org \
    --cc=stable@vger.kernel.org \
    --cc=tglx@linutronix.de \
    --cc=torvalds@linux-foundation.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).