linux-stable/arch/arm64/kernel
Mark Rutland de32e15180 arm64: head: avoid over-mapping in map_memory
commit 90268574a3 upstream.

The `compute_indices` and `populate_entries` macros operate on inclusive
bounds, and thus the `map_memory` macro which uses them also operates
on inclusive bounds.

We pass `_end` and `_idmap_text_end` to `map_memory`, but these are
exclusive bounds, and if one of these is sufficiently aligned (as a
result of kernel configuration, physical placement, and KASLR), then:

* In `compute_indices`, the computed `iend` will be in the page/block *after*
  the final byte of the intended mapping.

* In `populate_entries`, an unnecessary entry will be created at the end
  of each level of table. At the leaf level, this entry will map up to
  SWAPPER_BLOCK_SIZE bytes of physical addresses that we did not intend
  to map.

As we may map up to SWAPPER_BLOCK_SIZE bytes more than intended, we may
violate the boot protocol and map physical address past the 2MiB-aligned
end address we are permitted to map. As we map these with Normal memory
attributes, this may result in further problems depending on what these
physical addresses correspond to.

The final entry at each level may require an additional table at that
level. As EARLY_ENTRIES() calculates an inclusive bound, we allocate
enough memory for this.

Avoid the extraneous mapping by having map_memory convert the exclusive
end address to an inclusive end address by subtracting one, and do
likewise in EARLY_ENTRIES() when calculating the number of required
tables. For clarity, comments are updated to more clearly document which
boundaries the macros operate on.  For consistency with the other
macros, the comments in map_memory are also updated to describe `vstart`
and `vend` as virtual addresses.

Fixes: 0370b31e48 ("arm64: Extend early page table code to allow for larger kernels")
Cc: <stable@vger.kernel.org> # 4.16.x
Signed-off-by: Mark Rutland <mark.rutland@arm.com>
Cc: Anshuman Khandual <anshuman.khandual@arm.com>
Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Cc: Steve Capper <steve.capper@arm.com>
Cc: Will Deacon <will@kernel.org>
Acked-by: Will Deacon <will@kernel.org>
Link: https://lore.kernel.org/r/20210823101253.55567-1-mark.rutland@arm.com
Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2021-09-18 13:40:08 +02:00
..
probes arm64: kprobes: Restore local irqflag if kprobes is cancelled 2021-04-28 13:40:02 +02:00
vdso arm64/vdso: Discard .note.gnu.property sections in vDSO 2021-05-11 14:47:33 +02:00
vdso32 arm64: vdso32: Allow ld.lld to properly link the VDSO 2020-10-26 13:17:41 +00:00
.gitignore .gitignore: add SPDX License Identifier 2020-03-25 11:50:48 +01:00
acpi.c arm64: permit ACPI core to map kernel memory used for table overrides 2020-09-30 22:27:51 +01:00
acpi_numa.c
acpi_parking_protocol.c
alternative.c arm64/alternatives: don't patch up internal branches 2020-07-09 14:57:59 +01:00
armv8_deprecated.c sysctl: pass kernel pointers to ->proc_handler 2020-04-27 02:07:40 -04:00
asm-offsets.c KVM: arm64: Make struct kvm_regs userspace-only 2020-07-07 09:28:38 +01:00
cacheinfo.c
cpu-reset.h
cpu-reset.S arm64/relocate_kernel: remove redundant code 2020-09-11 19:06:25 +01:00
cpu_errata.c arm64: cpu_errata: Apply Erratum 845719 to KRYO2XX Silver 2020-11-13 09:47:08 +00:00
cpu_ops.c arm64: Introduce get_cpu_ops() helper function 2020-03-24 17:24:19 +00:00
cpufeature.c KVM: arm64: Hide system instruction access to Trace registers 2021-04-16 11:43:19 +02:00
cpuidle.c arm64: Introduce get_cpu_ops() helper function 2020-03-24 17:24:19 +00:00
cpuinfo.c arm64: avoid -Woverride-init warning 2020-10-28 13:38:36 +00:00
crash_core.c arm64/crash_core: Export TCR_EL1.T1SZ in vmcoreinfo 2020-07-02 17:56:49 +01:00
crash_dump.c arm64: kdump: update ppos when reading elfcorehdr 2021-03-30 14:32:03 +02:00
debug-monitors.c arm64: Improve diagnostics when trapping BRK with FAULT_BRK_IMM 2020-09-18 16:35:54 +01:00
efi-entry.S arm64 updates for 5.8 2020-06-01 15:18:27 -07:00
efi-header.S arm64: efi: increase EFI PE/COFF header padding to 64 KB 2020-10-28 14:02:03 +00:00
efi-rt-wrapper.S Merge branch 'for-next/scs' into for-next/core 2020-05-28 18:03:40 +01:00
efi.c treewide: Convert macro and uses of __section(foo) to __section("foo") 2020-10-25 14:51:49 -07:00
entry-common.c arm64: entry: always set GIC_PRIO_PSR_I_SET during entry 2021-05-19 10:13:07 +02:00
entry-fpsimd.S arm64/sve: Implement a helper to load SVE registers from FPSIMD state 2020-09-21 18:06:33 +01:00
entry-ftrace.S arm64: entry-ftrace.S: Update comment to indicate that x18 is live 2020-05-18 17:47:50 +01:00
entry.S arm64: consistently use reserved_pg_dir 2021-07-14 16:56:06 +02:00
fpsimd.c arm64: reject prctl(PR_PAC_RESET_KEYS) on compat tasks 2020-10-15 10:50:09 +01:00
ftrace.c arm64: ftrace: Change CONFIG_FTRACE_WITH_REGS to CONFIG_DYNAMIC_FTRACE_WITH_REGS 2020-06-08 15:44:59 +01:00
head.S arm64: head: avoid over-mapping in map_memory 2021-09-18 13:40:08 +02:00
hibernate-asm.S arm64: kernel: Convert to modern annotations for assembly functions 2020-05-04 12:46:03 +01:00
hibernate.c Merge branch 'for-next/mte' into for-next/core 2020-10-02 12:16:11 +01:00
hw_breakpoint.c treewide: Use fallthrough pseudo-keyword 2020-08-23 17:36:59 -05:00
hyp-stub.S arm64: kernel: Convert to modern annotations for assembly functions 2020-05-04 12:46:03 +01:00
image-vars.h KVM/arm64 fixes for 5.10, take #1 2020-10-30 13:25:09 -04:00
image.h arm64: get rid of TEXT_OFFSET 2020-09-07 15:00:52 +01:00
insn.c arm64: kprobe: disable probe of fault prone ptrauth instruction 2020-09-14 12:07:02 +01:00
io.c
irq.c arm64: entry: move el1 irq/nmi logic to C 2020-11-30 12:11:38 +00:00
jump_label.c
kaslr.c arm64: kaslr: Use standard early random function 2020-08-07 09:10:11 -07:00
kexec_image.c arm64: kexec_file: Fix sparse warning 2020-11-10 13:11:44 +00:00
kgdb.c arm64: kgdb: Fix single-step exception handling oops 2020-07-08 22:18:54 +01:00
kuser32.S docs: arm: convert docs to ReST and rename to *.rst 2019-07-15 09:20:24 -03:00
machine_kexec.c arm64: fix the flush_icache_range arguments in machine_kexec 2020-05-11 12:02:14 +01:00
machine_kexec_file.c arm64: kexec_file: fix memory leakage in create_dtb() when fdt_open_into() fails 2021-03-04 11:38:36 +01:00
Makefile Merge branch 'for-next/mte' into for-next/core 2020-10-02 12:16:11 +01:00
module-plts.c arm64/module: set trampoline section flags regardless of CONFIG_DYNAMIC_FTRACE 2020-09-02 08:35:33 +01:00
module.c treewide: Use fallthrough pseudo-keyword 2020-08-23 17:36:59 -05:00
mte.c arm64: mte: Allow PTRACE_PEEKMTETAGS access to the zero page 2021-02-17 11:02:28 +01:00
paravirt.c arm64: paravirt: Initialize steal time when cpu is online 2020-09-17 18:12:18 +01:00
pci.c PCI: Constify struct pci_ecam_ops 2020-05-01 16:28:59 +01:00
perf_callchain.c arm64: stacktrace: Make stack walk callback consistent with generic code 2020-09-18 14:24:16 +01:00
perf_event.c arm64: perf: Convert snprintf to sysfs_emit 2021-07-14 16:55:52 +02:00
perf_regs.c perf/arch: Remove perf_sample_data::regs_user_copy 2020-11-09 18:12:34 +01:00
pointer_auth.c arm64: reject prctl(PR_PAC_RESET_KEYS) on compat tasks 2020-10-15 10:50:09 +01:00
process.c arm64 fixes for -rc7 2020-12-02 12:27:37 -08:00
proton-pack.c arm64: proton-pack: Add KRYO2XX silver CPUs to spectre-v2 safe-list 2020-11-13 09:47:08 +00:00
psci.c arm64: psci: Avoid printing in cpu_psci_cpu_die() 2020-11-10 13:11:44 +00:00
ptrace.c arm64: fix compat syscall return truncation 2021-08-12 13:22:20 +02:00
reloc_test_core.c
reloc_test_syms.S arm64: kernel: Convert to modern annotations for assembly functions 2020-05-04 12:46:03 +01:00
relocate_kernel.S arm64/relocate_kernel: remove redundant code 2020-09-11 19:06:25 +01:00
return_address.c arm64: stacktrace: Make stack walk callback consistent with generic code 2020-09-18 14:24:16 +01:00
scs.c scs: Move DEFINE_SCS macro into core code 2020-05-18 17:47:48 +01:00
sdei.c arm64: entry: fix NMI {user, kernel}->kernel transitions 2020-11-30 12:11:38 +00:00
setup.c arm64/mm: Fix ttbr0 values stored in struct thread_info for software-pan 2021-07-14 16:56:07 +02:00
signal.c arm64: fix compat syscall return truncation 2021-08-12 13:22:20 +02:00
signal32.c arm64: compat: Always use sigpage for sigreturn trampoline 2020-06-23 14:56:24 +01:00
sigreturn32.S
sleep.S Merge branch 'for-next/bti' into for-next/core 2020-05-28 18:00:51 +01:00
smccc-call.S arm64/kernel: Remove needless Call Frame Information annotations 2020-09-01 09:50:36 +02:00
smp.c sched/core: Initialize the idle task with preemption disabled 2021-07-14 16:55:50 +02:00
smp_spin_table.c treewide: Convert macro and uses of __section(foo) to __section("foo") 2020-10-25 14:51:49 -07:00
stacktrace.c arm64: stacktrace: avoid tracing arch_stack_walk() 2021-08-12 13:22:12 +02:00
suspend.c arm64: spectre: Prevent lockdep splat on v4 mitigation enable path 2021-03-04 11:38:36 +01:00
sys.c
sys32.c
sys_compat.c arm64: Silence clang warning on mismatched value/register sizes 2019-10-28 09:13:21 +00:00
syscall.c arm64: fix compat syscall return truncation 2021-08-12 13:22:20 +02:00
time.c arm64: time: Replace <linux/clk-provider.h> by <linux/of_clk.h> 2020-02-12 17:26:38 +00:00
topology.c Power management updates for 5.10-rc1 2020-10-14 10:45:41 -07:00
trace-events-emulation.h
traps.c arm64: entry: fix NMI {user, kernel}->kernel transitions 2020-11-30 12:11:38 +00:00
vdso.c arm64: vdso: Fix unusual formatting in *setup_additional_pages() 2020-09-01 13:37:57 +01:00
vmlinux.lds.S arm64: consistently use reserved_pg_dir 2021-07-14 16:56:06 +02:00