18c2ecf20Sopenharmony_ci.. SPDX-License-Identifier: GPL-2.0 28c2ecf20Sopenharmony_ci 38c2ecf20Sopenharmony_ci=========================== 48c2ecf20Sopenharmony_ciKASLR for Freescale BookE32 58c2ecf20Sopenharmony_ci=========================== 68c2ecf20Sopenharmony_ci 78c2ecf20Sopenharmony_ciThe word KASLR stands for Kernel Address Space Layout Randomization. 88c2ecf20Sopenharmony_ci 98c2ecf20Sopenharmony_ciThis document tries to explain the implementation of the KASLR for 108c2ecf20Sopenharmony_ciFreescale BookE32. KASLR is a security feature that deters exploit 118c2ecf20Sopenharmony_ciattempts relying on knowledge of the location of kernel internals. 128c2ecf20Sopenharmony_ci 138c2ecf20Sopenharmony_ciSince CONFIG_RELOCATABLE has already supported, what we need to do is 148c2ecf20Sopenharmony_cimap or copy kernel to a proper place and relocate. Freescale Book-E 158c2ecf20Sopenharmony_ciparts expect lowmem to be mapped by fixed TLB entries(TLB1). The TLB1 168c2ecf20Sopenharmony_cientries are not suitable to map the kernel directly in a randomized 178c2ecf20Sopenharmony_ciregion, so we chose to copy the kernel to a proper place and restart to 188c2ecf20Sopenharmony_cirelocate. 198c2ecf20Sopenharmony_ci 208c2ecf20Sopenharmony_ciEntropy is derived from the banner and timer base, which will change every 218c2ecf20Sopenharmony_cibuild and boot. This not so much safe so additionally the bootloader may 228c2ecf20Sopenharmony_cipass entropy via the /chosen/kaslr-seed node in device tree. 238c2ecf20Sopenharmony_ci 248c2ecf20Sopenharmony_ciWe will use the first 512M of the low memory to randomize the kernel 258c2ecf20Sopenharmony_ciimage. The memory will be split in 64M zones. We will use the lower 8 268c2ecf20Sopenharmony_cibit of the entropy to decide the index of the 64M zone. Then we chose a 278c2ecf20Sopenharmony_ci16K aligned offset inside the 64M zone to put the kernel in:: 288c2ecf20Sopenharmony_ci 298c2ecf20Sopenharmony_ci KERNELBASE 308c2ecf20Sopenharmony_ci 318c2ecf20Sopenharmony_ci |--> 64M <--| 328c2ecf20Sopenharmony_ci | | 338c2ecf20Sopenharmony_ci +---------------+ +----------------+---------------+ 348c2ecf20Sopenharmony_ci | |....| |kernel| | | 358c2ecf20Sopenharmony_ci +---------------+ +----------------+---------------+ 368c2ecf20Sopenharmony_ci | | 378c2ecf20Sopenharmony_ci |-----> offset <-----| 388c2ecf20Sopenharmony_ci 398c2ecf20Sopenharmony_ci kernstart_virt_addr 408c2ecf20Sopenharmony_ci 418c2ecf20Sopenharmony_ciTo enable KASLR, set CONFIG_RANDOMIZE_BASE = y. If KASLR is enable and you 428c2ecf20Sopenharmony_ciwant to disable it at runtime, add "nokaslr" to the kernel cmdline. 43