lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <1678186653-27659-1-git-send-email-tangyouling@loongson.cn>
Date:   Tue,  7 Mar 2023 18:57:33 +0800
From:   Youling Tang <tangyouling@...ngson.cn>
To:     Huacai Chen <chenhuacai@...ngson.cn>,
        Ard Biesheuvel <ardb@...nel.org>
Cc:     Xuerui Wang <kernel@...0n.name>, linux-efi@...r.kernel.org,
        loongarch@...ts.linux.dev, linux-kernel@...r.kernel.org,
        loongson-kernel@...ts.loongnix.cn
Subject: [PATCH] efistub: LoongArch: Reimplement kernel_entry_address()

When EFI_KIMG_PREFERRED_ADDRESS is not equal to PHYS_LINK_KADDR, we
should not jump to the link address but the actual load address, so
fix the processing of kernel_entry_address().

Signed-off-by: Youling Tang <tangyouling@...ngson.cn>
---
- EFI_KIMG_PREFERRED_ADDRESS = PHYS_LINK_KADDR:
/ # cat /proc/iomem 
00000000-0fffffff : System RAM
  00000000-001fffff : Reserved
  00200000-0113ffff : Kernel code
  01140000-01a0e5ff : Kernel data
  01a0e600-01b0b337 : Kernel bss

- EFI_KIMG_PREFERRED_ADDRESS = PHYS_LINK_KADDR + 0x4000000 (Enable CONFIG_RELOCATABLE):
 # cat /proc/iomem 
00000000-0fffffff : System RAM
  00000000-041fffff : Reserved
  04200000-0513ffff : Kernel code
  05140000-05a0e5ff : Kernel data
  05a0e600-05b0b337 : Kernel bss

 arch/loongarch/include/asm/efi.h              |  2 --
 drivers/firmware/efi/libstub/loongarch-stub.c |  7 -------
 drivers/firmware/efi/libstub/loongarch.c      | 14 ++++++++++++--
 3 files changed, 12 insertions(+), 11 deletions(-)

diff --git a/arch/loongarch/include/asm/efi.h b/arch/loongarch/include/asm/efi.h
index 091897d40b03..eddc8e79b3fa 100644
--- a/arch/loongarch/include/asm/efi.h
+++ b/arch/loongarch/include/asm/efi.h
@@ -32,6 +32,4 @@ static inline unsigned long efi_get_kimg_min_align(void)
 
 #define EFI_KIMG_PREFERRED_ADDRESS	PHYSADDR(VMLINUX_LOAD_ADDRESS)
 
-unsigned long kernel_entry_address(void);
-
 #endif /* _ASM_LOONGARCH_EFI_H */
diff --git a/drivers/firmware/efi/libstub/loongarch-stub.c b/drivers/firmware/efi/libstub/loongarch-stub.c
index eee7ed43cdfb..71d178f87274 100644
--- a/drivers/firmware/efi/libstub/loongarch-stub.c
+++ b/drivers/firmware/efi/libstub/loongarch-stub.c
@@ -44,10 +44,3 @@ efi_status_t handle_kernel_image(unsigned long *image_addr,
 
 	return status;
 }
-
-unsigned long kernel_entry_address(void)
-{
-	unsigned long base = (unsigned long)&kernel_offset - kernel_offset;
-
-	return (unsigned long)&kernel_entry - base + VMLINUX_LOAD_ADDRESS;
-}
diff --git a/drivers/firmware/efi/libstub/loongarch.c b/drivers/firmware/efi/libstub/loongarch.c
index 807cba2693fc..79fa16a765ce 100644
--- a/drivers/firmware/efi/libstub/loongarch.c
+++ b/drivers/firmware/efi/libstub/loongarch.c
@@ -37,9 +37,19 @@ static efi_status_t exit_boot_func(struct efi_boot_memmap *map, void *priv)
 	return EFI_SUCCESS;
 }
 
-unsigned long __weak kernel_entry_address(void)
+/*
+ * Get the offset of EFI_KIMG_PREFERRED_ADDRESS relative to the physical
+ * link address.
+ */
+static long get_kernel_offset(void)
+{
+	return EFI_KIMG_PREFERRED_ADDRESS - PHYS_LINK_KADDR;
+}
+
+unsigned long kernel_entry_address(void)
 {
-	return *(unsigned long *)(PHYSADDR(VMLINUX_LOAD_ADDRESS) + 8);
+	return *(unsigned long *)(EFI_KIMG_PREFERRED_ADDRESS + 8) +
+		get_kernel_offset();
 }
 
 efi_status_t efi_boot_kernel(void *handle, efi_loaded_image_t *image,
-- 
2.37.3

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ