Skip to content

Commit a307a4c

Browse files
MQ-mengqingtsbogend
authored andcommitted
MIPS: Loongson64: Add KASLR support
Provide a weak plat_get_fdt() in relocate.c in case some platform enable USE_OF while plat_get_fdt() is useless. 1MB RELOCATION_TABLE_SIZE is small for Loongson64 because too many instructions should be relocated. 2MB is enough in present. Add KASLR support for Loongson64. KASLR(kernel address space layout randomization) To enable KASLR on Loongson64: First, make loongson3_defconfig. Then, enable CONFIG_RELOCATABLE and CONFIG_RANDOMIZE_BASE. Finally, compile the kernel. To test KASLR on Loongson64: Start machine with KASLR kernel. The first time: # cat /proc/iomem 00200000-0effffff : System RAM 02f30000-03895e9f : Kernel code 03895ea0-03bc7fff : Kernel data 03e30000-04f43f7f : Kernel bss The second time: # cat /proc/iomem 00200000-0effffff : System RAM 022f0000-02c55e9f : Kernel code 02c55ea0-02f87fff : Kernel data 031f0000-04303f7f : Kernel bss We see that code, data and bss sections become randomize. Signed-off-by: Jinyang He <[email protected]> Signed-off-by: Thomas Bogendoerfer <[email protected]>
1 parent 74a2810 commit a307a4c

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

arch/mips/Kconfig

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -488,6 +488,7 @@ config MACH_LOONGSON64
488488
select SYS_SUPPORTS_HIGHMEM
489489
select SYS_SUPPORTS_LITTLE_ENDIAN
490490
select SYS_SUPPORTS_ZBOOT
491+
select SYS_SUPPORTS_RELOCATABLE
491492
select ZONE_DMA32
492493
select NUMA
493494
select SMP
@@ -2778,7 +2779,8 @@ config RELOCATABLE
27782779
depends on CPU_MIPS32_R2 || CPU_MIPS64_R2 || \
27792780
CPU_MIPS32_R5 || CPU_MIPS64_R5 || \
27802781
CPU_MIPS32_R6 || CPU_MIPS64_R6 || \
2781-
CPU_P5600 || CAVIUM_OCTEON_SOC
2782+
CPU_P5600 || CAVIUM_OCTEON_SOC || \
2783+
CPU_LOONGSON64
27822784
help
27832785
This builds a kernel image that retains relocation information
27842786
so it can be loaded someplace besides the default 1MB.
@@ -2789,6 +2791,7 @@ config RELOCATION_TABLE_SIZE
27892791
hex "Relocation table size"
27902792
depends on RELOCATABLE
27912793
range 0x0 0x01000000
2794+
default "0x00200000" if CPU_LOONGSON64
27922795
default "0x00100000"
27932796
help
27942797
A table of relocation data will be appended to the kernel binary

arch/mips/kernel/relocate.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,13 @@ static inline int __init relocation_addr_valid(void *loc_new)
294294
return 1;
295295
}
296296

297+
#if defined(CONFIG_USE_OF)
298+
void __weak *plat_get_fdt(void)
299+
{
300+
return NULL;
301+
}
302+
#endif
303+
297304
void *__init relocate_kernel(void)
298305
{
299306
void *loc_new;

0 commit comments

Comments
 (0)