From: Ard Biesheuvel
maillist inclusion
commit 7e279c05992a88d0517df371a48e72d060b2ca21
category: feature
feature: ARM kaslr support
issue: #I3ZXZF
CVE: NA
Reference: https://git.kernel.org/pub/scm/linux/kernel/git/ardb/linux.git/commit/?h=arm-kaslr-latest&id=7e279c05992a88d0517df371a48e72d060b2ca21
-------------------------------------------------
To prepare for adding support for KASLR, which relocates all absolute
symbol references at runtime after the caches have been enabled,
update the MMU switch code to avoid using absolute symbol references
where possible. This ensures these quantities are invariant under
runtime relocation.
Cc: Russell King
Signed-off-by: Ard Biesheuvel
Signed-off-by: Cui GaoSheng
Reviewed-by: Xiu Jianfeng
Signed-off-by: Chen Jun
Signed-off-by: Yu Changchun
---
arch/arm/kernel/head-common.S | 61 +++++++++++------------------------
1 file changed, 18 insertions(+), 43 deletions(-)
diff --git a/arch/arm/kernel/head-common.S b/arch/arm/kernel/head-common.S
index 29b2eda136bb..69fcbf8876b3 100644
--- a/arch/arm/kernel/head-common.S
+++ b/arch/arm/kernel/head-common.S
@@ -80,70 +80,45 @@ __mmap_switched:
mov r8, r2
mov r10, r0
- adr r4, __mmap_switched_data
mov fp, #0
#if defined(CONFIG_XIP_DEFLATED_DATA)
- ARM( ldr sp, [r4], #4 )
- THUMB( ldr sp, [r4] )
- THUMB( add r4, #4 )
+ adr_l r4, __bss_stop
+ mov sp, r4 @ sp (temporary stack in .bss)
bl __inflate_kernel_data @ decompress .data to RAM
teq r0, #0
bne __error
#elif defined(CONFIG_XIP_KERNEL)
- ARM( ldmia r4!, {r0, r1, r2, sp} )
- THUMB( ldmia r4!, {r0, r1, r2, r3} )
- THUMB( mov sp, r3 )
+ adr_l r0, _sdata
+ adr_l r1, __data_loc
+ adr_l r2, _edata_loc
+ adr_l r3, __bss_stop
+ mov sp, r3 @ sp (temporary stack in .bss)
sub r2, r2, r1
bl __memcpy @ copy .data to RAM
#endif
- ARM( ldmia r4!, {r0, r1, sp} )
- THUMB( ldmia r4!, {r0, r1, r3} )
- THUMB( mov sp, r3 )
+ adr_l r0, __bss_start
+ adr_l r1, __bss_stop
+ adr_l r3, init_thread_union + THREAD_START_SP
+ mov sp, r3
sub r2, r1, r0
mov r1, #0
bl __memset @ clear .bss
- ldmia r4, {r0, r1, r2, r3}
- str r9, [r0] @ Save processor ID
- str r7, [r1] @ Save machine type
- str r8, [r2] @ Save atags pointer
- cmp r3, #0
- strne r10, [r3] @ Save control register values
#ifdef CONFIG_KASAN
bl kasan_early_init
#endif
- mov lr, #0
- b start_kernel
-ENDPROC(__mmap_switched)
-
- .align 2
- .type __mmap_switched_data, %object
-__mmap_switched_data:
-#ifdef CONFIG_XIP_KERNEL
-#ifndef CONFIG_XIP_DEFLATED_DATA
- .long _sdata @ r0
- .long __data_loc @ r1
- .long _edata_loc @ r2
-#endif
- .long __bss_stop @ sp (temporary stack in .bss)
-#endif
- .long __bss_start @ r0
- .long __bss_stop @ r1
- .long init_thread_union + THREAD_START_SP @ sp
-
- .long processor_id @ r0
- .long __machine_arch_type @ r1
- .long __atags_pointer @ r2
+ str_l r9, processor_id, r4 @ Save processor ID
+ str_l r7, __machine_arch_type, r4 @ Save machine type
+ str_l r8, __atags_pointer, r4 @ Save atags pointer
#ifdef CONFIG_CPU_CP15
- .long cr_alignment @ r3
-#else
-M_CLASS(.long exc_ret) @ r3
-AR_CLASS(.long 0) @ r3
+ str_l r10, cr_alignment, r4 @ Save control register values
#endif
- .size __mmap_switched_data, . - __mmap_switched_data
+ mov lr, #0
+ b start_kernel
+ENDPROC(__mmap_switched)
__FINIT
.text
--
2.22.0