MIPS: Loongson64: Add KASLR support
authorJinyang He <hejinyang@loongson.cn>
Wed, 25 Nov 2020 10:07:46 +0000 (18:07 +0800)
committerThomas Bogendoerfer <tsbogend@alpha.franken.de>
Fri, 27 Nov 2020 09:20:25 +0000 (10:20 +0100)
commita307a4ce9ecd2e23c71318201330d9d648b3f818
treee2b26a56a7076629a7e05e6ecb560466641b8dec
parent74a2810b7c1fcd60c87a8c47f95660628e00e97c
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 <hejinyang@loongson.cn>
Signed-off-by: Thomas Bogendoerfer <tsbogend@alpha.franken.de>
arch/mips/Kconfig
arch/mips/kernel/relocate.c