Re: [PATCH] MIPS: relocatable: Provide kaslr_offset() to get the kernel offset
From: Thomas Bogendoerfer <tsbogend@alpha.franken.de>
Date: 2021-02-01 14:00:09
Also in:
lkml
On Wed, Jan 27, 2021 at 12:12:25PM +0800, Jinyang He wrote:
quoted hunk ↗ jump to hunk
Use kimage_vaddr to indicate kernel start address. Provide kaslr_offset() to get the kernel offset when KASLR is enabled. Error may occur before update_kimage_vaddr(), so put it at the end of the offset branch. Fixes: a307a4ce9ecd ("MIPS: Loongson64: Add KASLR support") Reported-by: kernel test robot <redacted> Signed-off-by: Jinyang He <redacted> --- arch/mips/include/asm/page.h | 6 ++++++ arch/mips/kernel/relocate.c | 12 ++++++++++++ arch/mips/kernel/setup.c | 3 +++ 3 files changed, 21 insertions(+)diff --git a/arch/mips/include/asm/page.h b/arch/mips/include/asm/page.h index 6a77bc4..9429520 100644 --- a/arch/mips/include/asm/page.h +++ b/arch/mips/include/asm/page.h@@ -255,6 +255,12 @@ extern bool __virt_addr_valid(const volatile void *kaddr); #define VM_DATA_DEFAULT_FLAGS VM_DATA_FLAGS_TSK_EXEC +extern unsigned long kimage_vaddr; +static inline unsigned long kaslr_offset(void) +{ + return kimage_vaddr - VMLINUX_LOAD_ADDRESS; +}
this breaks for 32bit kernels:
<command-line>:0:22: error: large integer implicitly truncated to unsigned type [-Werror=overflow]
/local/tbogendoerfer/korg/linux/arch/mips/kernel/setup.c:87:41: note: in expansion of macro ‘VMLINUX_LOAD_ADDRESS’
unsigned long kimage_vaddr __initdata = VMLINUX_LOAD_ADDRESS;
^~~~~~~~~~~~~~~~~~~~
cc1: all warnings being treated as errors
--
Crap can work. Given enough thrust pigs will fly, but it's not necessarily a
good idea. [ RFC1925, 2.3 ]