linux-stable/arch/arm/include/asm
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
..
hardware ARM: riscpc: use GENERIC_IRQ_MULTI_HANDLER 2021-12-03 18:43:38 +01:00
mach ARM: remove old-style irq entry 2021-12-06 12:49:11 +01:00
vdso vdso/treewide: Add vdso_data pointer argument to __arch_get_hw_counter() 2020-08-06 10:57:30 +02:00
xen xen/arm: introduce XENFEAT_direct_mapped and XENFEAT_not_direct_mapped 2021-04-23 11:33:50 +02:00
arch_gicv3.h arm: Remove GICv3 vgic compatibility macros 2020-03-24 10:56:05 +00:00
arch_timer.h clocksource/drivers/arm_arch_timer: Drop unnecessary ISB on CVAL programming 2021-10-17 21:47:44 +02:00
archrandom.h firmware: smccc: Introduce SMCCC TRNG framework 2021-01-21 17:42:46 +00:00
arm-cci.h treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 234 2019-06-19 17:09:07 +02:00
asm-offsets.h
assembler.h ARM development updates for 5.18: 2022-03-23 17:35:57 -07:00
atomic.h locking/atomic: arm: move to ARCH_ATOMIC 2021-05-26 13:20:50 +02:00
auxvec.h
barrier.h
bitops.h include: move find.h from asm_generic to linux 2022-01-15 08:47:31 -08:00
bitrev.h
bL_switcher.h treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 500 2019-06-19 17:09:55 +02:00
bug.h arm: print alloc free paths for address in registers 2021-05-07 00:26:34 -07:00
bugs.h treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 500 2019-06-19 17:09:55 +02:00
cache.h treewide: Convert macro and uses of __section(foo) to __section("foo") 2020-10-25 14:51:49 -07:00
cacheflush.h ARM development updates for 5.18: 2022-03-23 17:35:57 -07:00
cachetype.h
checksum.h arm: propagate the calling convention changes down to csum_partial_copy_from_user() 2020-08-20 15:45:16 -04:00
clocksource.h arm: Introduce asm/vdso/clocksource.h 2020-03-21 15:23:54 +01:00
cmpxchg.h locking/atomic: arm: move to ARCH_ATOMIC 2021-05-26 13:20:50 +02:00
compiler.h
cp15.h arm: vdso: Enable arm to use common headers 2020-03-21 15:24:03 +01:00
cpu.h treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 500 2019-06-19 17:09:55 +02:00
cpufeature.h treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 500 2019-06-19 17:09:55 +02:00
cpuidle.h arm64 updates for 5.14 2021-06-28 14:04:24 -07:00
cputype.h
cti.h
current.h ARM: make get_current() and __my_cpu_offset() __always_inline 2022-01-31 16:06:35 +01:00
dcc.h treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 284 2019-06-05 17:36:37 +02:00
delay.h
device.h arm: Remove dev->archdata.iommu pointer 2020-06-30 11:59:48 +02:00
div64.h ARM: 9118/1: div64: Remove always-true __div64_const32_is_OK() duplicate 2021-08-20 11:39:28 +01:00
dma-direct.h ARM/omap1: switch to use dma_direct_set_offset for lbus DMA offsets 2020-09-25 06:15:32 +02:00
dma-iommu.h dma-mapping: move dma-debug.h to kernel/dma/ 2020-10-06 07:07:05 +02:00
dma-mapping.h dma-mapping: move dma-debug.h to kernel/dma/ 2020-10-06 07:07:05 +02:00
dma.h
dmi.h treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 500 2019-06-19 17:09:55 +02:00
domain.h ARM: 8908/1: add __always_inline to functions called from __get_user_check() 2019-10-10 22:23:19 +01:00
ecard.h
edac.h treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 201 2019-05-30 11:29:52 -07:00
efi.h efi: Move efifb_setup_from_dmi() prototype from arch headers 2021-12-13 15:07:16 +01:00
elf.h ARM: module: implement support for PC-relative group relocations 2021-12-06 12:49:16 +01:00
exception.h
fb.h
fiq.h
firmware.h treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 500 2019-06-19 17:09:55 +02:00
fixmap.h ARM updates for 5.11: 2020-12-22 13:34:27 -08:00
floppy.h floppy: split the base port from the register in I/O accesses 2020-05-12 19:34:52 +03:00
fncpy.h treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 333 2019-06-05 17:37:06 +02:00
fpstate.h ARM: ep93xx: remove MaverickCrunch support 2021-08-04 13:30:04 +02:00
ftrace.h ARM: 9184/1: return_address: disable again for CONFIG_ARM_UNWIND=y 2022-03-07 11:43:12 +00:00
futex.h ARM: futex: Address build warning 2020-05-07 00:41:47 +02:00
glue-cache.h treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 500 2019-06-19 17:09:55 +02:00
glue-df.h treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 500 2019-06-19 17:09:55 +02:00
glue-pf.h treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 500 2019-06-19 17:09:55 +02:00
glue-proc.h treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 500 2019-06-19 17:09:55 +02:00
glue.h treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 500 2019-06-19 17:09:55 +02:00
gpio.h ARM: 9103/1: Drop ARCH_NR_GPIOS definition 2021-08-10 12:16:07 +01:00
hardirq.h ARM: irqstat: Get rid of duplicated declaration 2020-11-23 10:31:05 +01:00
highmem.h ARM: highmem: Fix cache_is_vivt() reference 2020-12-04 23:35:34 +01:00
hugetlb-3level.h treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 333 2019-06-05 17:37:06 +02:00
hugetlb.h mm/hugetlb: define a generic fallback for arch_clear_hugepage_flags() 2020-06-03 20:09:46 -07:00
hw_breakpoint.h ARM: 8927/1: ARM/hw_breakpoint: add more ARMv8 debug architecture versions support 2019-11-15 22:21:08 +00:00
hw_irq.h
hwcap.h
hypervisor.h arm/arm64: Probe for the presence of KVM hypervisor 2021-03-31 09:16:55 +01:00
ide.h
idmap.h treewide: Convert macro and uses of __section(foo) to __section("foo") 2020-10-25 14:51:49 -07:00
insn.h ARM: 9176/1: avoid literal references in inline assembly 2022-01-06 12:58:58 +00:00
io.h arm[64]/memremap: don't abuse pfn_valid() to ensure presence of linear map 2022-05-09 17:34:28 -07:00
irq.h ARM: remove old-style irq entry 2021-12-06 12:49:11 +01:00
irq_work.h
irqflags.h
jump_label.h
kasan.h ARM: 9016/2: Initialize the mapping of KASan shadow memory 2020-10-27 12:11:10 +00:00
kasan_def.h ARM: 9015/2: Define the virtual space of KASan's shadow region 2020-10-27 12:11:08 +00:00
Kbuild local64.h: make <asm/local64.h> mandatory 2020-12-29 15:36:49 -08:00
kexec-internal.h ARM: kexec: fix oops after TLB are invalidated 2021-02-05 10:23:29 +00:00
kexec.h ARM: 9060/1: kexec: Remove unused kexec_reinit callback 2021-03-09 10:25:35 +00:00
kfence.h ARM: 9166/1: Support KFENCE for ARM 2021-12-17 11:34:38 +00:00
kgdb.h
kprobes.h ARM: 9019/1: kprobes: Avoid fortify_panic() when copying optprobe template 2020-10-27 12:11:51 +00:00
krait-l2-accessors.h
linkage.h
mc146818rtc.h
mcpm.h treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 500 2019-06-19 17:09:55 +02:00
mcs_spinlock.h
memblock.h
memory.h ARM: 9104/2: Fix Keystone 2 kernel mapping regression 2021-08-10 12:17:25 +01:00
mmu.h ARM: mm: make vmalloc_seq handling SMP safe 2022-01-25 09:53:52 +01:00
mmu_context.h ARM: mm: make vmalloc_seq handling SMP safe 2022-01-25 09:53:52 +01:00
module.h ARM: 9079/1: ftrace: Add MODULE_PLTS support 2021-06-07 12:56:20 +01:00
module.lds.h kbuild: preprocess module linker script 2020-09-25 00:36:41 +09:00
mpu.h
mtd-xip.h treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 500 2019-06-19 17:09:55 +02:00
neon.h treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 500 2019-06-19 17:09:55 +02:00
nwflash.h misc: move FLASH_MINOR into miscdevice.h and fix conflicts 2020-03-18 12:27:04 +01:00
opcodes-sec.h treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 174 2019-05-30 11:26:41 -07:00
opcodes-virt.h treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 1 2019-05-21 11:28:39 +02:00
opcodes.h ARM: 9145/1: patch: fix BE32 compilation 2021-10-25 13:12:36 +01:00
outercache.h treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 333 2019-06-05 17:37:06 +02:00
page-nommu.h treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 500 2019-06-19 17:09:55 +02:00
page.h ARM: mm: make vmalloc_seq handling SMP safe 2022-01-25 09:53:52 +01:00
paravirt.h x86/paravirt: Switch time pvops functions to use static_call() 2021-03-11 16:17:52 +01:00
paravirt_api_clock.h sched/headers: ARM needs asm/paravirt_api_clock.h too 2022-03-22 08:53:10 +01:00
patch.h
pci.h ARM: 8911/1: move pcibios_report_status to <asm/pci.h> 2019-10-27 21:14:40 +00:00
percpu.h ARM: make get_current() and __my_cpu_offset() __always_inline 2022-01-31 16:06:35 +01:00
perf_event.h treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 500 2019-06-19 17:09:55 +02:00
pgalloc.h mm/thp: define default pmd_pgtable() 2021-07-01 11:06:03 -07:00
pgtable-2level-hwdef.h treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 500 2019-06-19 17:09:55 +02:00
pgtable-2level-types.h treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 333 2019-06-05 17:37:06 +02:00
pgtable-2level.h arch: Add pmd_pfn() where it is missing 2022-03-21 12:59:02 -04:00
pgtable-3level-hwdef.h treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 333 2019-06-05 17:37:06 +02:00
pgtable-3level-types.h treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 333 2019-06-05 17:37:06 +02:00
pgtable-3level.h mm: rename pud_page_vaddr to pud_pgtable and make it return pmd_t * 2021-07-08 11:48:22 -07:00
pgtable-hwdef.h treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 500 2019-06-19 17:09:55 +02:00
pgtable-nommu.h mm: consolidate pte_index() and pte_offset_*() definitions 2020-06-09 09:39:14 -07:00
pgtable.h ARM: update __swp_entry_to_pte() to use PTE_TYPE_FAULT 2021-06-07 12:55:30 +01:00
probes.h treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 174 2019-05-30 11:26:41 -07:00
proc-fns.h treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 500 2019-06-19 17:09:55 +02:00
processor.h ARM: 9180/1: Thumb2: align ALT_UP() sections in modules sufficiently 2022-01-19 11:10:54 +00:00
procinfo.h treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 500 2019-06-19 17:09:55 +02:00
prom.h ARM: 9011/1: centralize phys-to-virt conversion of DT/ATAGS address 2020-10-27 12:10:59 +00:00
psci.h treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 174 2019-05-30 11:26:41 -07:00
ptdump.h arm: dump: no need to check return value of debugfs_create functions 2019-06-03 15:49:07 +02:00
ptrace.h ARM: 9113/1: uaccess: remove set_fs() implementation 2021-08-20 11:39:27 +01:00
seccomp.h arm: Enable seccomp architecture tracking 2020-11-20 11:16:34 -08:00
sections.h arm: Remove HYP/Stage-2 page-table support 2020-03-24 10:56:05 +00:00
secure_cntvoff.h
set_memory.h ARM: 9164/1: mm: Provide set_memory_valid() 2021-12-17 11:34:36 +00:00
setup.h ARM: 9147/1: add printf format attribute to early_print() 2021-10-25 13:12:37 +01:00
shmparam.h
signal.h signal: clear non-uapi flag bits when passing/returning sa_flags 2020-11-23 10:31:05 -06:00
smp.h ARM: remove some dead code 2021-12-03 15:11:31 +01:00
smp_plat.h
smp_scu.h
smp_twd.h
sparsemem.h
spectre.h ARM: Spectre-BHB: provide empty stub for non-config 2022-03-11 12:42:49 -08:00
spinlock.h locking: Fix typos in comments 2021-03-22 02:45:52 +01:00
spinlock_types.h locking: Allow to include asm/spinlock_types.h from linux/spinlock_types_raw.h 2021-12-07 15:14:12 +01:00
stackprotector.h gcc-plugins: arm-ssp: Prepare for THREAD_INFO_IN_TASK support 2021-09-27 16:54:01 +02:00
stacktrace.h ARM: Revert "unwind: dump exception stack from calling frame" 2022-03-11 13:00:55 +00:00
string.h ARM: 9014/2: Replace string mem* functions for KASan 2020-10-27 12:11:06 +00:00
suspend.h ARM: 8847/1: pm: fix HYP/SVC mode mismatch when MCPM is used 2019-02-26 11:32:54 +00:00
swab.h
switch_to.h ARM development updates for 5.18: 2022-03-23 17:35:57 -07:00
sync_bitops.h locking/atomic: arm: move to ARCH_ATOMIC 2021-05-26 13:20:50 +02:00
syscall.h arch: remove unused function syscall_set_arguments() 2021-09-14 16:06:20 +02:00
system_info.h
system_misc.h ARM: 9096/1: Remove arm_pm_restart() 2021-06-13 18:16:48 +01:00
tcm.h treewide: Convert macro and uses of __section(foo) to __section("foo") 2020-10-25 14:51:49 -07:00
therm.h
thread_info.h ARM: implement THREAD_INFO_IN_TASK for uniprocessor systems 2021-12-06 12:49:17 +01:00
thread_notify.h treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 500 2019-06-19 17:09:55 +02:00
timex.h treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 500 2019-06-19 17:09:55 +02:00
tlb.h mm: account PMD tables like PTE tables 2020-10-13 18:38:31 -07:00
tlbflush.h mm: update legacy flush_tlb_* to use vma 2021-06-29 10:53:52 -07:00
tls.h ARM: smp: elide HWCAP_TLS checks or __entry_task updates on SMP+v6 2022-01-25 09:53:52 +01:00
topology.h arch_topology: Remove unused topology_set_thermal_pressure() and related 2021-11-23 15:10:26 +05:30
traps.h arm/asm: add loglvl to c_backtrace() 2020-06-09 09:39:10 -07:00
uaccess-asm.h ARM: 9113/1: uaccess: remove set_fs() implementation 2021-08-20 11:39:27 +01:00
uaccess.h uaccess: generalize access_ok() 2022-02-25 09:36:05 +01:00
ucontext.h ARM: ep93xx: remove MaverickCrunch support 2021-08-04 13:30:04 +02:00
unified.h ARM: 9116/1: unified: Remove check for gcc < 4 2021-08-20 11:39:28 +01:00
unistd.h clone3-v5.3 2019-07-11 10:09:44 -07:00
unwind.h arm: add loglvl to unwind_backtrace() 2020-06-09 09:39:10 -07:00
uprobes.h treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 500 2019-06-19 17:09:55 +02:00
user.h asm/user.h: killed unused macros 2022-01-30 21:17:00 -05:00
v7m.h irqchip: nvic: Use GENERIC_IRQ_MULTI_HANDLER 2021-12-06 12:49:16 +01:00
vdso.h
vdso_datapage.h ARM: 8930/1: Add support for generic vDSO 2019-11-15 22:21:12 +00:00
vermagic.h arch: split MODULE_ARCH_VERMAGIC definitions out to <asm/vermagic.h> 2020-04-23 10:50:26 +09:00
vfp.h ARM: 8991/1: use VFP assembler mnemonics if available 2020-07-21 16:33:39 +01:00
vfpmacros.h ARM: 8991/1: use VFP assembler mnemonics if available 2020-07-21 16:33:39 +01:00
vga.h
virt.h arm: Remove the ability to set HYP vectors outside of the decompressor 2020-03-24 10:56:05 +00:00
vmalloc.h mm/vmalloc: Add empty <asm/vmalloc.h> headers and use them from <linux/vmalloc.h> 2019-12-10 10:12:55 +01:00
vmlinux.lds.h ARM: Do not use NOCROSSREFS directive with ld.lld 2022-03-09 14:14:16 -08:00
word-at-a-time.h
xor.h lib/xor: make xor prototypes more friendly to compiler vectorization 2022-02-11 20:39:39 +11:00