Commit a307a4ce authored by Jinyang He's avatar Jinyang He Committed by Thomas Bogendoerfer

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: default avatarJinyang He <hejinyang@loongson.cn>
Signed-off-by: default avatarThomas Bogendoerfer <tsbogend@alpha.franken.de>
parent 74a2810b
...@@ -488,6 +488,7 @@ config MACH_LOONGSON64 ...@@ -488,6 +488,7 @@ config MACH_LOONGSON64
select SYS_SUPPORTS_HIGHMEM select SYS_SUPPORTS_HIGHMEM
select SYS_SUPPORTS_LITTLE_ENDIAN select SYS_SUPPORTS_LITTLE_ENDIAN
select SYS_SUPPORTS_ZBOOT select SYS_SUPPORTS_ZBOOT
select SYS_SUPPORTS_RELOCATABLE
select ZONE_DMA32 select ZONE_DMA32
select NUMA select NUMA
select SMP select SMP
...@@ -2778,7 +2779,8 @@ config RELOCATABLE ...@@ -2778,7 +2779,8 @@ config RELOCATABLE
depends on CPU_MIPS32_R2 || CPU_MIPS64_R2 || \ depends on CPU_MIPS32_R2 || CPU_MIPS64_R2 || \
CPU_MIPS32_R5 || CPU_MIPS64_R5 || \ CPU_MIPS32_R5 || CPU_MIPS64_R5 || \
CPU_MIPS32_R6 || CPU_MIPS64_R6 || \ CPU_MIPS32_R6 || CPU_MIPS64_R6 || \
CPU_P5600 || CAVIUM_OCTEON_SOC CPU_P5600 || CAVIUM_OCTEON_SOC || \
CPU_LOONGSON64
help help
This builds a kernel image that retains relocation information This builds a kernel image that retains relocation information
so it can be loaded someplace besides the default 1MB. so it can be loaded someplace besides the default 1MB.
...@@ -2789,6 +2791,7 @@ config RELOCATION_TABLE_SIZE ...@@ -2789,6 +2791,7 @@ config RELOCATION_TABLE_SIZE
hex "Relocation table size" hex "Relocation table size"
depends on RELOCATABLE depends on RELOCATABLE
range 0x0 0x01000000 range 0x0 0x01000000
default "0x00200000" if CPU_LOONGSON64
default "0x00100000" default "0x00100000"
help help
A table of relocation data will be appended to the kernel binary A table of relocation data will be appended to the kernel binary
......
...@@ -294,6 +294,13 @@ static inline int __init relocation_addr_valid(void *loc_new) ...@@ -294,6 +294,13 @@ static inline int __init relocation_addr_valid(void *loc_new)
return 1; return 1;
} }
#if defined(CONFIG_USE_OF)
void __weak *plat_get_fdt(void)
{
return NULL;
}
#endif
void *__init relocate_kernel(void) void *__init relocate_kernel(void)
{ {
void *loc_new; void *loc_new;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment