[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20220419070150.254377-3-mawupeng1@huawei.com>
Date: Tue, 19 Apr 2022 15:01:50 +0800
From: Wupeng Ma <mawupeng1@...wei.com>
To: <akpm@...ux-foundation.org>, <catalin.marinas@....com>,
<will@...nel.org>, <corbet@....net>
CC: <ardb@...nel.org>, <tglx@...utronix.de>, <mingo@...hat.com>,
<bp@...en8.de>, <dave.hansen@...ux.intel.com>, <x86@...nel.org>,
<dvhart@...radead.org>, <andy@...radead.org>, <rppt@...nel.org>,
<paulmck@...nel.org>, <peterz@...radead.org>, <jroedel@...e.de>,
<songmuchun@...edance.com>, <macro@...am.me.uk>,
<frederic@...nel.org>, <W_Armin@....de>, <john.garry@...wei.com>,
<seanjc@...gle.com>, <tsbogend@...ha.franken.de>,
<anshuman.khandual@....com>, <chenhuacai@...nel.org>,
<david@...hat.com>, <gpiccoli@...lia.com>, <mark.rutland@....com>,
<wangkefeng.wang@...wei.com>, <mawupeng1@...wei.com>,
<linux-doc@...r.kernel.org>, <linux-kernel@...r.kernel.org>,
<linux-arm-kernel@...ts.infradead.org>,
<linux-efi@...r.kernel.org>, <linux-ia64@...r.kernel.org>,
<platform-driver-x86@...r.kernel.org>, <linux-mm@...ck.org>
Subject: [PATCH 2/2] arm64/boot: Add support to relocate kernel image to mirrored region without kaslr
From: Ma Wupeng <mawupeng1@...wei.com>
Add support to relocate kernel image to mirrord regions if KASLR doesn't
work.
If a suiable mirrored slot if found, call efi_random_alloc() with
random_seed be zero to relocate kernel code and data to the first slot
available.
Signed-off-by: Ma Wupeng <mawupeng1@...wei.com>
---
drivers/firmware/efi/libstub/arm64-stub.c | 10 ++++++++++
drivers/firmware/efi/libstub/randomalloc.c | 1 +
2 files changed, 11 insertions(+)
diff --git a/drivers/firmware/efi/libstub/arm64-stub.c b/drivers/firmware/efi/libstub/arm64-stub.c
index 39b774853b93..851a8948cafb 100644
--- a/drivers/firmware/efi/libstub/arm64-stub.c
+++ b/drivers/firmware/efi/libstub/arm64-stub.c
@@ -190,6 +190,16 @@ efi_status_t handle_kernel_image(unsigned long *image_addr,
}
if (status != EFI_SUCCESS) {
+ if (efi_mirror_found) {
+ status = efi_random_alloc(*reserve_size, min_kimg_align,
+ reserve_addr, 0,
+ efi_mirror_found);
+ if (status == EFI_SUCCESS)
+ goto out;
+
+ efi_err("Failed to relocate kernel to mirrored region\n");
+ }
+
if (!check_image_region((u64)_text, kernel_memsize)) {
efi_err("FIRMWARE BUG: Image BSS overlaps adjacent EFI memory region\n");
} else if (IS_ALIGNED((u64)_text, min_kimg_align)) {
diff --git a/drivers/firmware/efi/libstub/randomalloc.c b/drivers/firmware/efi/libstub/randomalloc.c
index dd81d6c3c406..d5f4249943a7 100644
--- a/drivers/firmware/efi/libstub/randomalloc.c
+++ b/drivers/firmware/efi/libstub/randomalloc.c
@@ -50,6 +50,7 @@ unsigned long get_entry_num_slots(efi_memory_desc_t *md,
*/
#define MD_NUM_SLOTS(md) ((md)->virt_addr)
+/* random_seed == 0 means alloc mem from the first suitable slot */
efi_status_t efi_random_alloc(unsigned long size,
unsigned long align,
unsigned long *addr,
--
2.25.1
Powered by blists - more mailing lists