linux/arch/arm
Mike Rapoport 260364d112 arm[64]/memremap: don't abuse pfn_valid() to ensure presence of linear map
The semantics of pfn_valid() is to check presence of the memory map for a
PFN and not whether a PFN is covered by the linear map.  The memory map
may be present for NOMAP memory regions, but they won't be mapped in the
linear mapping.  Accessing such regions via __va() when they are
memremap()'ed will cause a crash.

On v5.4.y the crash happens on qemu-arm with UEFI [1]:

<1>[    0.084476] 8<--- cut here ---
<1>[    0.084595] Unable to handle kernel paging request at virtual address dfb76000
<1>[    0.084938] pgd = (ptrval)
<1>[    0.085038] [dfb76000] *pgd=5f7fe801, *pte=00000000, *ppte=00000000

...

<4>[    0.093923] [<c0ed6ce8>] (memcpy) from [<c16a06f8>] (dmi_setup+0x60/0x418)
<4>[    0.094204] [<c16a06f8>] (dmi_setup) from [<c16a38d4>] (arm_dmi_init+0x8/0x10)
<4>[    0.094408] [<c16a38d4>] (arm_dmi_init) from [<c0302e9c>] (do_one_initcall+0x50/0x228)
<4>[    0.094619] [<c0302e9c>] (do_one_initcall) from [<c16011e4>] (kernel_init_freeable+0x15c/0x1f8)
<4>[    0.094841] [<c16011e4>] (kernel_init_freeable) from [<c0f028cc>] (kernel_init+0x8/0x10c)
<4>[    0.095057] [<c0f028cc>] (kernel_init) from [<c03010e8>] (ret_from_fork+0x14/0x2c)

On kernels v5.10.y and newer the same crash won't reproduce on ARM because
commit b10d6bca87 ("arch, drivers: replace for_each_membock() with
for_each_mem_range()") changed the way memory regions are registered in
the resource tree, but that merely covers up the problem.

On ARM64 memory resources registered in yet another way and there the
issue of wrong usage of pfn_valid() to ensure availability of the linear
map is also covered.

Implement arch_memremap_can_ram_remap() on ARM and ARM64 to prevent access
to NOMAP regions via the linear mapping in memremap().

Link: https://lore.kernel.org/all/Yl65zxGgFzF1Okac@sirena.org.uk
Link: https://lkml.kernel.org/r/20220426060107.7618-1-rppt@kernel.org
Signed-off-by: Mike Rapoport <rppt@linux.ibm.com>
Reported-by: "kernelci.org bot" <bot@kernelci.org>
Tested-by: Mark Brown <broonie@kernel.org>
Reviewed-by: Ard Biesheuvel <ardb@kernel.org>
Acked-by: Catalin Marinas <catalin.marinas@arm.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Mark Brown <broonie@kernel.org>
Cc: Mark-PK Tsai <mark-pk.tsai@mediatek.com>
Cc: Russell King <linux@armlinux.org.uk>
Cc: Tony Lindgren <tony@atomide.com>
Cc: Will Deacon <will@kernel.org>
Cc: <stable@vger.kernel.org>	[5.4+]
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
2022-05-09 17:34:28 -07:00
..
boot ARM: dts: align SPI NOR node name with dtschema 2022-04-14 22:51:22 +02:00
common
configs ARM: config: Update Gemini defconfig 2022-04-14 22:59:24 +02:00
crypto This push fixes the following issues: 2022-03-31 11:17:39 -07:00
include arm[64]/memremap: don't abuse pfn_valid() to ensure presence of linear map 2022-05-09 17:34:28 -07:00
kernel ARM fixes for 5.18-rc1: 2022-04-03 10:17:48 -07:00
lib asm-generic updates for 5.18 2022-03-23 18:03:08 -07:00
mach-actions
mach-airoha ARM: Add basic support for Airoha EN7523 SoC 2022-03-01 09:02:01 +01:00
mach-alpine
mach-artpec
mach-asm9260
mach-aspeed
mach-at91 ARM: at91: Kconfig: select PM_OPP 2022-02-25 12:36:26 +01:00
mach-axxia
mach-bcm ARM: SoC updates for 5.18 2022-03-23 18:20:09 -07:00
mach-berlin
mach-clps711x
mach-cns3xxx
mach-davinci ARM: davinci: da850-evm: Avoid NULL pointer dereference 2022-04-04 16:31:40 +02:00
mach-digicolor
mach-dove
mach-ep93xx ep93xx: clock: Don't use plain integer as NULL pointer 2022-04-07 13:56:49 +02:00
mach-exynos pinctrl: samsung: fix missing GPIOLIB on ARM64 Exynos config 2022-04-21 08:58:54 +02:00
mach-footbridge ARM: SoC updates for 5.18 2022-03-23 18:20:09 -07:00
mach-gemini
mach-highbank
mach-hisi
mach-imx
mach-integrator ARM: remove support for NOMMU ARMv4/v5 2022-03-17 09:13:13 +01:00
mach-iop32x ARM: iop32x: include iop3xx.h header where needed 2022-04-04 17:42:59 +02:00
mach-ixp4xx ARM: ixp4xx: Drop all common code 2022-02-12 18:20:04 +01:00
mach-keystone
mach-lpc18xx
mach-lpc32xx
mach-mediatek
mach-meson
mach-milbeaut
mach-mmp ARM: mmp: Fix failure to remove sram device 2022-02-25 16:38:34 +01:00
mach-moxart
mach-mstar ARM: SoC updates for 5.18 2022-03-23 18:20:09 -07:00
mach-mv78xx0
mach-mvebu
mach-mxs
mach-nomadik
mach-npcm
mach-nspire ARM: remove support for NOMMU ARMv4/v5 2022-03-17 09:13:13 +01:00
mach-omap1
mach-omap2 ARM: OMAP2+: Fix regression for smc calls for vmap stack 2022-03-31 22:41:27 +02:00
mach-orion5x ARM: remove support for NOMMU ARMv4/v5 2022-03-17 09:13:13 +01:00
mach-oxnas
mach-pxa ARM: SoC updates for 5.18 2022-03-23 18:20:09 -07:00
mach-qcom
mach-rda
mach-realtek
mach-realview
mach-rockchip
mach-rpc
mach-s3c ARM fixes for 5.18-rc1: 2022-04-03 10:17:48 -07:00
mach-s5pv210
mach-sa1100
mach-shmobile ARM: remove support for NOMMU ARMv4/v5 2022-03-17 09:13:13 +01:00
mach-socfpga
mach-spear ARM: spear: fix typos in comments 2022-03-19 22:33:59 +01:00
mach-sti
mach-stm32
mach-sunxi
mach-tegra
mach-uniphier
mach-ux500 ARM: remove support for NOMMU ARMv4/v5 2022-03-17 09:13:13 +01:00
mach-versatile
mach-vexpress ARM: vexpress/spc: Fix all the kernel-doc build warnings 2022-04-07 10:50:01 +01:00
mach-vt8500
mach-zynq
mm arm[64]/memremap: don't abuse pfn_valid() to ensure presence of linear map 2022-05-09 17:34:28 -07:00
net bpf, arm: Fix various typos in comments 2022-03-21 16:20:26 +01:00
nwfpe
plat-omap
plat-orion
plat-pxa
plat-versatile
probes ARM development updates for 5.18: 2022-03-23 17:35:57 -07:00
tools arch: syscalls: simplify uapi/kapi directory creation 2022-03-31 12:03:46 +09:00
vdso ARM: 9181/1: vdso: remove -nostdlib compiler flag 2022-02-28 13:59:45 +00:00
vfp
xen arm/xen: Fix some refcount leaks 2022-04-22 13:33:33 -07:00
Kbuild
Kconfig dma-mapping updates for Linux 5.18 2022-03-29 08:50:14 -07:00
Kconfig-nommu
Kconfig.assembler
Kconfig.debug ARM development updates for 5.18: 2022-03-23 17:35:57 -07:00
Makefile ARM: DT updates for 5.18 2022-03-23 18:37:22 -07:00