linux/arch/arm64/kernel
Neeraj Upadhyay afd0e5a876 arm64: kaslr: Fix up the kernel image alignment
If kernel image extends across alignment boundary, existing
code increases the KASLR offset by size of kernel image. The
offset is masked after resizing. There are cases, where after
masking, we may still have kernel image extending across
boundary. This eventually results in only 2MB block getting
mapped while creating the page tables. This results in data aborts
while accessing unmapped regions during second relocation (with
kaslr offset) in __primary_switch. To fix this problem, round up the
kernel image size, by swapper block size, before adding it for
correction.

For example consider below case, where kernel image still crosses
1GB alignment boundary, after masking the offset, which is fixed
by rounding up kernel image size.

SWAPPER_TABLE_SHIFT = 30
Swapper using section maps with section size 2MB.
CONFIG_PGTABLE_LEVELS = 3
VA_BITS = 39

_text  : 0xffffff8008080000
_end   : 0xffffff800aa1b000
offset : 0x1f35600000
mask = ((1UL << (VA_BITS - 2)) - 1) & ~(SZ_2M - 1)

(_text + offset) >> SWAPPER_TABLE_SHIFT = 0x3fffffe7c
(_end + offset) >> SWAPPER_TABLE_SHIFT  = 0x3fffffe7d

offset after existing correction (before mask) = 0x1f37f9b000
(_text + offset) >> SWAPPER_TABLE_SHIFT = 0x3fffffe7d
(_end + offset) >> SWAPPER_TABLE_SHIFT  = 0x3fffffe7d

offset (after mask) = 0x1f37e00000
(_text + offset) >> SWAPPER_TABLE_SHIFT = 0x3fffffe7c
(_end + offset) >> SWAPPER_TABLE_SHIFT  = 0x3fffffe7d

new offset w/ rounding up = 0x1f38000000
(_text + offset) >> SWAPPER_TABLE_SHIFT = 0x3fffffe7d
(_end + offset) >> SWAPPER_TABLE_SHIFT  = 0x3fffffe7d

Fixes: f80fb3a3d5 ("arm64: add support for kernel ASLR")
Cc: <stable@vger.kernel.org>
Reviewed-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Signed-off-by: Neeraj Upadhyay <neeraju@codeaurora.org>
Signed-off-by: Srinivas Ramana <sramana@codeaurora.org>
Signed-off-by: Will Deacon <will.deacon@arm.com>
2017-03-22 15:43:11 +00:00
..
probes arm64: kprobes: remove kprobe_exceptions_notify 2017-03-10 17:41:19 +00:00
vdso arm64: Add support for CLOCK_MONOTONIC_RAW in clock_gettime() vDSO 2016-07-12 16:06:32 +01:00
.gitignore
acpi_numa.c arm64/numa: avoid inconsistent information to be printed 2016-09-09 14:59:08 +01:00
acpi_parking_protocol.c arm64: Use __pa_symbol for kernel symbols 2017-01-12 15:05:39 +00:00
acpi.c ACPI / osl: Remove acpi_get_table_with_size()/early_acpi_os_unmap_memory() users 2016-12-21 02:36:38 +01:00
alternative.c arm64: alternative: Add support for patching adrp instructions 2016-09-09 15:03:28 +01:00
arm64ksyms.c arm: kernel: Add SMC structure parameter 2017-02-03 18:46:33 +00:00
armv8_deprecated.c kprobes: move kprobe declarations to asm-generic/kprobes.h 2017-02-27 18:43:45 -08:00
asm-offsets.c arm: kernel: Add SMC structure parameter 2017-02-03 18:46:33 +00:00
cacheinfo.c arm64: cacheinfo: add support to override cache levels via device tree 2017-01-17 12:09:54 +00:00
cpu_errata.c arm64: Work around Falkor erratum 1003 2017-02-10 11:22:12 +00:00
cpu_ops.c arm64: apply __ro_after_init to some objects 2016-08-22 12:32:29 +01:00
cpu-reset.h arm64: Use __pa_symbol for kernel symbols 2017-01-12 15:05:39 +00:00
cpu-reset.S arm64: Add back cpu reset routines 2016-06-27 16:31:25 +01:00
cpufeature.c arm64: cpufeature: correctly handle MRS to XZR 2017-02-15 12:20:29 +00:00
cpuidle.c arm64: kernel: Update kerneldoc for cpu_suspend() rename 2017-03-10 18:06:24 +00:00
cpuinfo.c arm64: Advertise support for Rounding double multiply instructions 2017-01-12 17:19:06 +00:00
debug-monitors.c sched/headers: Prepare for new header dependencies before moving code to <linux/sched/task_stack.h> 2017-03-02 08:42:36 +01:00
efi-entry.S arm64: efi-entry.S: avoid open-coded adr_l 2017-01-17 17:41:14 +00:00
efi.c arm64: mm: replace 'block_mappings_allowed' with 'page_mappings_only' 2016-11-07 18:15:04 +00:00
entry32.S arm64: entry32: remove pointless register assignment 2015-07-10 16:47:13 +01:00
entry-fpsimd.S
entry-ftrace.S arm64: include asm/assembler.h in entry-ftrace.S 2017-02-15 11:34:25 +00:00
entry.S arm64: avoid returning from bad_mode 2017-01-19 15:38:22 +00:00
fpsimd.c sched/headers: Prepare for new header dependencies before moving code to <linux/sched/signal.h> 2017-03-02 08:42:29 +01:00
ftrace.c ftrace: Add return address pointer to ftrace_ret_stack 2016-08-24 12:15:14 +02:00
head.S arm64: head.S: Enable EL1 (host) access to SPE when entered at EL2 2017-02-09 18:31:25 +00:00
hibernate-asm.S arm64: Introduce raw_{d,i}cache_line_size 2016-09-09 15:03:29 +01:00
hibernate.c arm64: Use __pa_symbol for kernel symbols 2017-01-12 15:05:39 +00:00
hw_breakpoint.c cpu/hotplug: Cleanup state names 2016-12-25 10:47:44 +01:00
hyp-stub.S arm64: Add back cpu reset routines 2016-06-27 16:31:25 +01:00
image.h arm64 updates for 4.7: 2016-05-16 17:17:24 -07:00
insn.c kprobes: move kprobe declarations to asm-generic/kprobes.h 2017-02-27 18:43:45 -08:00
io.c
irq.c arm64: remove irq_count and do_softirq_own_stack() 2015-12-21 17:26:01 +00:00
jump_label.c jump_label: Rename JUMP_LABEL_{EN,DIS}ABLE to JUMP_LABEL_{JMP,NOP} 2015-08-03 11:34:12 +02:00
kaslr.c arm64: kaslr: Fix up the kernel image alignment 2017-03-22 15:43:11 +00:00
kgdb.c sched/headers: Prepare for new header dependencies before moving code to <linux/sched/task_stack.h> 2017-03-02 08:42:36 +01:00
kuser32.S
machine_kexec.c arm64/kexec: Add pr_debug output 2016-06-27 16:31:26 +01:00
Makefile efi: arm64: Add vmlinux debug link to the Image binary 2017-02-03 15:22:37 +00:00
module-plts.c arm64: add support for module PLTs 2016-02-24 14:57:24 +00:00
module.c arm64: add support for kernel ASLR 2016-02-24 14:57:27 +00:00
module.lds arm64: add support for module PLTs 2016-02-24 14:57:24 +00:00
paravirt.c arm64: introduce CONFIG_PARAVIRT, PARAVIRT_TIME_ACCOUNTING and pv_time_ops 2015-12-21 14:40:54 +00:00
pci.c PCI/ACPI: Extend pci_mcfg_lookup() to return ECAM config accessors 2016-12-06 13:45:48 -06:00
perf_callchain.c perf core: Add a 'nr' field to perf_event_callchain_context 2016-05-16 23:11:51 -03:00
perf_event.c KVM: arm64: Fix the issues when guest PMCCFILTR is configured 2016-11-18 09:06:58 +00:00
perf_regs.c sched/headers: Prepare for new header dependencies before moving code to <linux/sched/task_stack.h> 2017-03-02 08:42:36 +01:00
process.c sched/headers: Prepare for new header dependencies before moving code to <linux/sched/task_stack.h> 2017-03-02 08:42:36 +01:00
psci.c arm64: Use __pa_symbol for kernel symbols 2017-01-12 15:05:39 +00:00
ptrace.c sched/headers: Prepare for new header dependencies before moving code to <linux/sched/task_stack.h> 2017-03-02 08:42:36 +01:00
relocate_kernel.S arm64: Introduce raw_{d,i}cache_line_size 2016-09-09 15:03:29 +01:00
return_address.c arm64: factor out current_stack_pointer 2016-11-11 18:25:43 +00:00
setup.c sched/headers: Prepare to move 'init_task' and 'init_thread_union' from <linux/sched.h> to <linux/sched/task.h> 2017-03-02 08:42:38 +01:00
signal32.c Replace <asm/uaccess.h> with <linux/uaccess.h> globally 2016-12-24 11:46:01 -08:00
signal.c arm64: Add uprobe support 2016-11-07 18:15:21 +00:00
sleep.S arm64: move sp_el0 and tpidr_el1 into cpu_suspend_ctx 2016-11-11 18:25:44 +00:00
smccc-call.S firmware: qcom: scm: Fix interrupted SCM calls 2017-02-03 18:46:33 +00:00
smp_spin_table.c arm64: Use __pa_symbol for kernel symbols 2017-01-12 15:05:39 +00:00
smp.c sched/headers: Move task->mm handling methods to <linux/sched/mm.h> 2017-03-03 01:43:28 +01:00
stacktrace.c sched/headers: Prepare for new header dependencies before moving code to <linux/sched/task_stack.h> 2017-03-02 08:42:36 +01:00
suspend.c arm64: move sp_el0 and tpidr_el1 into cpu_suspend_ctx 2016-11-11 18:25:44 +00:00
sys32.c arm64: fix implementation of mmap2 compat syscall 2015-03-19 10:43:51 +00:00
sys_compat.c sched/headers: Prepare for the reduction of <linux/sched.h>'s signal API dependency 2017-03-02 08:42:37 +01:00
sys.c arm64: compat: Check for AArch32 state 2016-04-20 12:22:42 +01:00
time.c arm64: ftrace: fix a stack tracer's output under function graph tracer 2015-12-21 17:26:02 +00:00
topology.c sched/headers: Prepare for new header dependencies before moving code to <linux/sched/topology.h> 2017-03-02 08:42:26 +01:00
trace-events-emulation.h arm64: Trace emulation of AArch32 legacy instructions 2014-11-20 16:35:02 +00:00
traps.c sched/headers: Prepare to remove the <linux/mm_types.h> dependency from <linux/sched.h> 2017-03-02 08:42:37 +01:00
vdso.c arm64: Use __pa_symbol for kernel symbols 2017-01-12 15:05:39 +00:00
vmlinux.lds.S arm64: Introduce uaccess_{disable,enable} functionality based on TTBR0_EL1 2016-11-21 18:48:53 +00:00