Commit affea797 authored by Gaosheng Cui's avatar Gaosheng Cui Committed by Cui GaoSheng
Browse files

efi/libstub: arm64: Add macro isolation memmap detection code

hulk inclusion
category: feature
bugzilla: https://gitee.com/openeuler/kernel/issues/I9K8D1



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

Kaslr will randomizes the physical address at which the kernel
image is loaded, we will check and skip the memmap reserved memory,
add config CONFIG_UEFI_KASLR_SKIP_MEMMAP to isolation memmap detection
code.

Signed-off-by: default avatarGaosheng Cui <cuigaosheng1@huawei.com>
parent 43993247
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
@@ -2111,6 +2111,16 @@ config RANDOMIZE_MODULE_REGION_FULL
	  a limited range that contains the [_stext, _etext] interval of the
	  core kernel, so branch relocations are always in range.

config UEFI_KASLR_SKIP_MEMMAP
	bool "Skip the memmap address when randomize the kernel image"
	depends on RANDOMIZE_BASE
	default n
	help
	  In some cases we hopes to reserve memory by memmap for other
	  features, the reserved memory may conflict with the kernel
	  image, so we need skip the memmap reserved memory when randomize
	  the kernel image to avoid it.

config CC_HAVE_STACKPROTECTOR_SYSREG
	def_bool $(cc-option,-mstack-protector-guard=sysreg -mstack-protector-guard-reg=sp_el0 -mstack-protector-guard-offset=0)

+1 −0
Original line number Diff line number Diff line
@@ -548,6 +548,7 @@ CONFIG_ARM64_PSEUDO_NMI=y
CONFIG_RELOCATABLE=y
CONFIG_RANDOMIZE_BASE=y
CONFIG_RANDOMIZE_MODULE_REGION_FULL=y
CONFIG_UEFI_KASLR_SKIP_MEMMAP=y
CONFIG_NOKASLR_MEM_RANGE=y
CONFIG_CC_HAVE_STACKPROTECTOR_SYSREG=y
CONFIG_STACKPROTECTOR_PER_TASK=y
+2 −0
Original line number Diff line number Diff line
@@ -32,7 +32,9 @@ __efistub_strnlen = __pi_strnlen;
__efistub_strcmp		= __pi_strcmp;
__efistub_strncmp		= __pi_strncmp;
__efistub_strrchr		= __pi_strrchr;
#if defined(CONFIG_UEFI_KASLR_SKIP_MEMMAP) || defined(CONFIG_NOKASLR_MEM_RANGE)
__efistub_strchr		= __pi_strchr;
#endif
__efistub___clean_dcache_area_poc = __pi___clean_dcache_area_poc;

__efistub__text			= _text;
+8 −0
Original line number Diff line number Diff line
@@ -18,7 +18,11 @@
 * Returns:
 *	x0 - address of first occurrence of 'c' or 0
 */
#if defined(CONFIG_UEFI_KASLR_SKIP_MEMMAP) || defined(CONFIG_NOKASLR_MEM_RANGE)
SYM_FUNC_START_WEAK_PI(strchr)
#else
SYM_FUNC_START_WEAK(strchr)
#endif
	and	w1, w1, #0xff
1:	ldrb	w2, [x0], #1
	cmp	w2, w1
@@ -28,5 +32,9 @@ SYM_FUNC_START_WEAK_PI(strchr)
	cmp	w2, w1
	csel	x0, x0, xzr, eq
	ret
#if defined(CONFIG_UEFI_KASLR_SKIP_MEMMAP) || defined(CONFIG_NOKASLR_MEM_RANGE)
SYM_FUNC_END_PI(strchr)
#else
SYM_FUNC_END(strchr)
#endif
EXPORT_SYMBOL_NOKASAN(strchr)
+2 −0
Original line number Diff line number Diff line
@@ -15,6 +15,7 @@

#include "efistub.h"

#ifdef CONFIG_UEFI_KASLR_SKIP_MEMMAP
#define MAX_MEMMAP_REGIONS 32

struct mem_vector {
@@ -103,6 +104,7 @@ void free_avoid_memmap(void)
		efi_free(mem_avoid[i].size, mem_avoid[i].start);
	}
}
#endif

#ifdef CONFIG_NOKASLR_MEM_RANGE
#define MAX_MEM_NOKASLR_REGIONS 4
Loading