Received: by 2002:a05:6a10:17d3:0:0:0:0 with SMTP id hz19csp1729185pxb; Mon, 12 Apr 2021 05:29:53 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwjWNqHd7S1P3MP9e29T21sGDkge3fgGnzoGE1aRWkviRUHTAj3KjYa6v3O0rXTeofxgkH9 X-Received: by 2002:a17:906:6dd9:: with SMTP id j25mr26597000ejt.507.1618230593281; Mon, 12 Apr 2021 05:29:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1618230593; cv=none; d=google.com; s=arc-20160816; b=WmcDuePNPlSH794aKRlRbswaD4PeIvIRn0dWPZutd4igVfVMomdK1hzqVDx9l36+nL eibZLdwhtumU9AB23eM6tixQugCmZVZHKfLeTsY/VJjfsOhnZiJlYZsdqEtJDV4i5dJ4 PrzpBYno6r+3WlQjbgWpj3FjlC0RRLnkUvcIolZCbnY6Hz9O8c72vOgRk3XLnLVZprBL RwrWOwhRAaJMUEd5VwKWkEVN2JS85KRDszSMPouKs+jDZckKQ3jMS9DIEUQwl0wn61A4 KNg9SnQPkN6yDGm2w5L1Da+cfARjD1oacKmNoVpreWEmfEwk+lVOPaXAFf0f9oHsfqr/ uaYA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from; bh=200ucmG04fqBFT4+2vm3sGBxeVSPPKJN8KW/dwa6mMc=; b=zbVa45DLqIqvp6RB4DRtNNWyPgflealb/xQVpSofyMwFaF7+aQGvSnZ637hROytV7x Mu86yDH6913mkHzSfTd9kJmywViFQT+LyzEK9ZGom6+McfjxT8CK9XyJJNDTNJOxCosx PPFiT5NaohT2V2/Xa9VVbE/lkgpEhCqpjxu/AwipGG8+dE2eA1s8hxiGZXoxG6k0tCoz n62qg/41A7Boamqxu5vPLLaNdDcDeVMHX8JZfRs+ooH/ePazWHOxBIhDpmaFbS73d/ay ItSJV9Tv/cJiOjJSLZkstddozw6hWufHF/lxL7+sTD66GQ/iVdKXJEHZUaIhuyVSY7fv kKRw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id x6si7537867ejb.380.2021.04.12.05.29.29; Mon, 12 Apr 2021 05:29:53 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240904AbhDLM2z (ORCPT + 99 others); Mon, 12 Apr 2021 08:28:55 -0400 Received: from mail.loongson.cn ([114.242.206.163]:59218 "EHLO loongson.cn" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S239412AbhDLM2w (ORCPT ); Mon, 12 Apr 2021 08:28:52 -0400 Received: from loongson.localdomain (unknown [113.200.148.30]) by mail.loongson.cn (Coremail) with SMTP id AQAAf9AxzcjsPHRgCyoHAA--.9793S4; Mon, 12 Apr 2021 20:28:29 +0800 (CST) From: Jinyang He To: Thomas Bogendoerfer , Paul Burton Cc: linux-mips@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 2/5] MIPS: relocate: Use CONFIG_RANDOMIZE_BASE to enable kaslr Date: Mon, 12 Apr 2021 20:28:11 +0800 Message-Id: <1618230494-6207-3-git-send-email-hejinyang@loongson.cn> X-Mailer: git-send-email 2.1.0 In-Reply-To: <1618230494-6207-1-git-send-email-hejinyang@loongson.cn> References: <1618230494-6207-1-git-send-email-hejinyang@loongson.cn> X-CM-TRANSID: AQAAf9AxzcjsPHRgCyoHAA--.9793S4 X-Coremail-Antisp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uYvjxUyC38DUUUU X-CM-SenderInfo: pkhmx0p1dqwqxorr0wxvrqhubq/ Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Currently, the difference between using CONFIG_RELOCATABLE and CONFIG_RANDOMIZE_BASE is determine_relocation_address(). CONFIG_RANDOMIZE_BASE achieves randomization. CONFIG_RELOCATABLE relocate the kernel is very limited, currently returns a constant. Therefore, drop determine_relocation_address() if CONFIG_RELOCATABLE. Rename relocate.c to kaslr.c and use CONFIG_RANDOMIZE_BASE to enable the kaslr function. Signed-off-by: Jinyang He --- arch/mips/cavium-octeon/smp.c | 8 ++++---- arch/mips/generic/init.c | 4 ++-- arch/mips/include/asm/bootinfo.h | 4 ++-- .../include/asm/mach-cavium-octeon/kernel-entry-init.h | 4 ++-- arch/mips/kernel/Makefile | 2 +- arch/mips/kernel/head.S | 6 +++--- arch/mips/kernel/{relocate.c => kaslr.c} | 15 --------------- 7 files changed, 14 insertions(+), 29 deletions(-) rename arch/mips/kernel/{relocate.c => kaslr.c} (97%) diff --git a/arch/mips/cavium-octeon/smp.c b/arch/mips/cavium-octeon/smp.c index 66ce552..dfdbc79 100644 --- a/arch/mips/cavium-octeon/smp.c +++ b/arch/mips/cavium-octeon/smp.c @@ -28,9 +28,9 @@ volatile unsigned long octeon_processor_boot = 0xff; volatile unsigned long octeon_processor_sp; volatile unsigned long octeon_processor_gp; -#ifdef CONFIG_RELOCATABLE +#ifdef CONFIG_RANDOMIZE_BASE volatile unsigned long octeon_processor_relocated_kernel_entry; -#endif /* CONFIG_RELOCATABLE */ +#endif /* CONFIG_RANDOMIZE_BASE */ #ifdef CONFIG_HOTPLUG_CPU uint64_t octeon_bootloader_entry_addr; @@ -190,7 +190,7 @@ static void __init octeon_smp_setup(void) } -#ifdef CONFIG_RELOCATABLE +#ifdef CONFIG_RANDOMIZE_BASE int plat_post_relocation(long offset) { unsigned long entry = (unsigned long)kernel_entry; @@ -200,7 +200,7 @@ int plat_post_relocation(long offset) return 0; } -#endif /* CONFIG_RELOCATABLE */ +#endif /* CONFIG_RANDOMIZE_BASE */ /** * Firmware CPU startup hook diff --git a/arch/mips/generic/init.c b/arch/mips/generic/init.c index 1842cdd..f7a4e29 100644 --- a/arch/mips/generic/init.c +++ b/arch/mips/generic/init.c @@ -82,7 +82,7 @@ void __init *plat_get_fdt(void) return (void *)fdt; } -#ifdef CONFIG_RELOCATABLE +#ifdef CONFIG_RANDOMIZE_BASE void __init plat_fdt_relocated(void *new_location) { @@ -97,7 +97,7 @@ void __init plat_fdt_relocated(void *new_location) fw_arg1 = (unsigned long)new_location; } -#endif /* CONFIG_RELOCATABLE */ +#endif /* CONFIG_RANDOMIZE_BASE */ void __init plat_mem_setup(void) { diff --git a/arch/mips/include/asm/bootinfo.h b/arch/mips/include/asm/bootinfo.h index 5be10ece..6b37663 100644 --- a/arch/mips/include/asm/bootinfo.h +++ b/arch/mips/include/asm/bootinfo.h @@ -169,7 +169,7 @@ static inline void plat_swiotlb_setup(void) {} */ extern void *plat_get_fdt(void); -#ifdef CONFIG_RELOCATABLE +#ifdef CONFIG_RANDOMIZE_BASE /** * plat_fdt_relocated() - Update platform's information about relocated dtb @@ -180,7 +180,7 @@ extern void *plat_get_fdt(void); */ void plat_fdt_relocated(void *new_location); -#endif /* CONFIG_RELOCATABLE */ +#endif /* CONFIG_RANDOMIZE_BASE */ #endif /* CONFIG_USE_OF */ #endif /* _ASM_BOOTINFO_H */ diff --git a/arch/mips/include/asm/mach-cavium-octeon/kernel-entry-init.h b/arch/mips/include/asm/mach-cavium-octeon/kernel-entry-init.h index c38b38c..e66767d 100644 --- a/arch/mips/include/asm/mach-cavium-octeon/kernel-entry-init.h +++ b/arch/mips/include/asm/mach-cavium-octeon/kernel-entry-init.h @@ -100,7 +100,7 @@ # octeon_spin_wait_boot: -#ifdef CONFIG_RELOCATABLE +#ifdef CONFIG_RANDOMIZE_BASE PTR_LA t0, octeon_processor_relocated_kernel_entry LONG_L t0, (t0) beq zero, t0, 1f @@ -109,7 +109,7 @@ jr t0 nop 1: -#endif /* CONFIG_RELOCATABLE */ +#endif /* CONFIG_RANDOMIZE_BASE */ # This is the variable where the next core to boot is stored PTR_LA t0, octeon_processor_boot diff --git a/arch/mips/kernel/Makefile b/arch/mips/kernel/Makefile index b4a57f1..bf7ac86 100644 --- a/arch/mips/kernel/Makefile +++ b/arch/mips/kernel/Makefile @@ -92,7 +92,7 @@ obj-$(CONFIG_I8253) += i8253.o obj-$(CONFIG_GPIO_TXX9) += gpio_txx9.o -obj-$(CONFIG_RELOCATABLE) += relocate.o +obj-$(CONFIG_RANDOMIZE_BASE) += kaslr.o obj-$(CONFIG_KEXEC) += machine_kexec.o relocate_kernel.o crash.o obj-$(CONFIG_CRASH_DUMP) += crash_dump.o diff --git a/arch/mips/kernel/head.S b/arch/mips/kernel/head.S index b825ed4..a25af1d 100644 --- a/arch/mips/kernel/head.S +++ b/arch/mips/kernel/head.S @@ -118,7 +118,7 @@ NESTED(kernel_entry, 16, sp) # kernel entry point set_saved_sp sp, t0, t1 PTR_SUBU sp, 4 * SZREG # init stack pointer -#ifdef CONFIG_RELOCATABLE +#ifdef CONFIG_RANDOMIZE_BASE /* Copy kernel and apply the relocations */ jal relocate_kernel @@ -136,9 +136,9 @@ NESTED(kernel_entry, 16, sp) # kernel entry point * newly sync'd icache. */ jr.hb v0 -#else /* !CONFIG_RELOCATABLE */ +#else /* !CONFIG_RANDOMIZE_BASE */ j start_kernel -#endif /* !CONFIG_RELOCATABLE */ +#endif /* !CONFIG_RANDOMIZE_BASE */ END(kernel_entry) #ifdef CONFIG_SMP diff --git a/arch/mips/kernel/relocate.c b/arch/mips/kernel/kaslr.c similarity index 97% rename from arch/mips/kernel/relocate.c rename to arch/mips/kernel/kaslr.c index 499a535..6742d58 100644 --- a/arch/mips/kernel/relocate.c +++ b/arch/mips/kernel/kaslr.c @@ -188,8 +188,6 @@ static int __init relocate_exception_table(long offset) return 0; } -#ifdef CONFIG_RANDOMIZE_BASE - static inline __init unsigned long rotate_xor(unsigned long hash, const void *area, size_t size) { @@ -280,19 +278,6 @@ static inline void __init *determine_relocation_address(void) return RELOCATED(dest); } -#else - -static inline void __init *determine_relocation_address(void) -{ - /* - * Choose a new address for the kernel - * For now we'll hard code the destination - */ - return (void *)0xffffffff81000000; -} - -#endif - static inline int __init relocation_addr_valid(void *loc_new) { if ((unsigned long)loc_new & 0x0000ffff) { -- 2.1.0