-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
powerpc/fsl_booke/32: implement KASLR infrastructure
This patch add support to boot kernel from places other than KERNELBASE. Since CONFIG_RELOCATABLE has already supported, what we need to do is map or copy kernel to a proper place and relocate. Freescale Book-E parts expect lowmem to be mapped by fixed TLB entries(TLB1). The TLB1 entries are not suitable to map the kernel directly in a randomized region, so we chose to copy the kernel to a proper place and restart to relocate. The offset of the kernel was not randomized yet(a fixed 64M is set). We will randomize it in the next patch. Signed-off-by: Jason Yan <yanaijie@huawei.com> Tested-by: Diana Craciun <diana.craciun@nxp.com> Reviewed-by: Christophe Leroy <christophe.leroy@c-s.fr> Signed-off-by: Scott Wood <oss@buserror.net> [mpe: Use PTRRELOC() in early_init()] Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
- Loading branch information
Jason Yan
authored and
Michael Ellerman
committed
Nov 13, 2019
1 parent
c061b38
commit 2b0e86c
Showing
9 changed files
with
109 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
// SPDX-License-Identifier: GPL-2.0-only | ||
// | ||
// Copyright (C) 2019 Jason Yan <yanaijie@huawei.com> | ||
|
||
#include <linux/kernel.h> | ||
#include <linux/errno.h> | ||
#include <linux/string.h> | ||
#include <linux/types.h> | ||
#include <linux/mm.h> | ||
#include <linux/swap.h> | ||
#include <linux/stddef.h> | ||
#include <linux/init.h> | ||
#include <linux/delay.h> | ||
#include <linux/memblock.h> | ||
#include <asm/pgalloc.h> | ||
#include <asm/prom.h> | ||
#include <mm/mmu_decl.h> | ||
|
||
static unsigned long __init kaslr_choose_location(void *dt_ptr, phys_addr_t size, | ||
unsigned long kernel_sz) | ||
{ | ||
/* return a fixed offset of 64M for now */ | ||
return SZ_64M; | ||
} | ||
|
||
/* | ||
* To see if we need to relocate the kernel to a random offset | ||
* void *dt_ptr - address of the device tree | ||
* phys_addr_t size - size of the first memory block | ||
*/ | ||
notrace void __init kaslr_early_init(void *dt_ptr, phys_addr_t size) | ||
{ | ||
unsigned long tlb_virt; | ||
phys_addr_t tlb_phys; | ||
unsigned long offset; | ||
unsigned long kernel_sz; | ||
|
||
kernel_sz = (unsigned long)_end - (unsigned long)_stext; | ||
|
||
offset = kaslr_choose_location(dt_ptr, size, kernel_sz); | ||
if (offset == 0) | ||
return; | ||
|
||
kernstart_virt_addr += offset; | ||
kernstart_addr += offset; | ||
|
||
is_second_reloc = 1; | ||
|
||
if (offset >= SZ_64M) { | ||
tlb_virt = round_down(kernstart_virt_addr, SZ_64M); | ||
tlb_phys = round_down(kernstart_addr, SZ_64M); | ||
|
||
/* Create kernel map to relocate in */ | ||
create_kaslr_tlb_entry(1, tlb_virt, tlb_phys); | ||
} | ||
|
||
/* Copy the kernel to it's new location and run */ | ||
memcpy((void *)kernstart_virt_addr, (void *)_stext, kernel_sz); | ||
flush_icache_range(kernstart_virt_addr, kernstart_virt_addr + kernel_sz); | ||
|
||
reloc_kernel_entry(dt_ptr, kernstart_virt_addr); | ||
} |