Commit 88072baa authored by Ard Biesheuvel's avatar Ard Biesheuvel Committed by Zheng Zengkai
Browse files

ARM: kernel: make vmlinux buildable as a PIE executable

maillist inclusion
commit 04be01192973461cdd00ab47908a78f0e2f55ef8
category: feature
feature: ARM kaslr support
bugzilla: 47952
CVE: NA

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/ardb/linux.git/commit/?h=arm-kaslr-latest&id=04be01192973461cdd00ab47908a78f0e2f55ef8



Update the Kconfig RELOCATABLE depends on !JUMP_LABEL to resolve
compilation conflicts between fpic and JUMP_LABEL

-------------------------------------------------

Update the build flags and linker script to allow vmlinux to be built
as a PIE  binary, which retains relocation information about absolute
symbol references so that they can be fixed up at runtime. This will
be used for implementing KASLR,

Cc: Russell King <linux@armlinux.org.uk>
Acked-by: default avatarNicolas Pitre <nico@linaro.org>
Signed-off-by: default avatarArd Biesheuvel <ard.biesheuvel@linaro.org>
Signed-off-by: default avatarCui GaoSheng <cuigaosheng1@huawei.com>
Reviewed-by: default avatarXiu Jianfeng <xiujianfeng@huawei.com>
Signed-off-by: default avatarZheng Zengkai <zhengzengkai@huawei.com>
parent 30080059
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -1678,6 +1678,11 @@ config STACKPROTECTOR_PER_TASK
	  Enable this option to switch to a different method that uses a
	  different canary value for each task.

config RELOCATABLE
	bool
	depends on !XIP_KERNEL && !JUMP_LABEL
	select HAVE_ARCH_PREL32_RELOCATIONS

endmenu

menu "Boot options"
+5 −0
Original line number Diff line number Diff line
@@ -48,6 +48,11 @@ CHECKFLAGS += -D__ARMEL__
KBUILD_LDFLAGS	+= -EL
endif

ifeq ($(CONFIG_RELOCATABLE),y)
KBUILD_CFLAGS		+= -fpic -include $(srctree)/include/linux/hidden.h
LDFLAGS_vmlinux		+= -pie -shared -Bsymbolic
endif

#
# The Scalar Replacement of Aggregates (SRA) optimization pass in GCC 4.9 and
# later may result in code being generated that handles signed short and signed
+1 −1
Original line number Diff line number Diff line
@@ -528,7 +528,7 @@ THUMB( orr \reg , \reg , #PSR_T_BIT )
	 * mov_l - move a constant value or [relocated] address into a register
	 */
	.macro		mov_l, dst:req, imm:req
	.if		__LINUX_ARM_ARCH__ < 7
	.if		CONFIG_RELOCATABLE == 1 || __LINUX_ARM_ARCH__ < 7
	ldr		\dst, =\imm
	.else
	movw		\dst, #:lower16:\imm
+5 −1
Original line number Diff line number Diff line
@@ -50,7 +50,11 @@
		EXIT_CALL						\
		ARM_MMU_DISCARD(*(.text.fixup))				\
		ARM_MMU_DISCARD(*(__ex_table))				\
		COMMON_DISCARDS
		COMMON_DISCARDS						\
		*(.ARM.exidx.discard.text)				\
		*(.interp .dynamic)					\
		*(.dynsym .dynstr .hash)


/*
 * Sections that should stay zero sized, which is safer to explicitly
+6 −0
Original line number Diff line number Diff line
@@ -115,6 +115,12 @@ SECTIONS
		__smpalt_end = .;
	}
#endif
	.rel.dyn : ALIGN(8) {
		__rel_begin = .;
		*(.rel .rel.* .rel.dyn)
	}
	__rel_end = ADDR(.rel.dyn) + SIZEOF(.rel.dyn);

	.init.pv_table : {
		__pv_table_begin = .;
		*(.pv_table)
Loading