Skip to content

Commit 2edb16e

Browse files
chleroympe
authored andcommitted
powerpc/32: Add KASAN support
This patch adds KASAN support for PPC32. The following patch will add an early activation of hash table for book3s. Until then, a warning will be raised if trying to use KASAN on an hash 6xx. To support KASAN, this patch initialises that MMU mapings for accessing to the KASAN shadow area defined in a previous patch. An early mapping is set as soon as the kernel code has been relocated at its definitive place. Then the definitive mapping is set once paging is initialised. For modules, the shadow area is allocated at module_alloc(). Signed-off-by: Christophe Leroy <christophe.leroy@c-s.fr> Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
1 parent f072015 commit 2edb16e

File tree

11 files changed

+188
-0
lines changed

11 files changed

+188
-0
lines changed

arch/powerpc/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ config PPC
173173
select GENERIC_TIME_VSYSCALL
174174
select HAVE_ARCH_AUDITSYSCALL
175175
select HAVE_ARCH_JUMP_LABEL
176+
select HAVE_ARCH_KASAN if PPC32
176177
select HAVE_ARCH_KGDB
177178
select HAVE_ARCH_MMAP_RND_BITS
178179
select HAVE_ARCH_MMAP_RND_COMPAT_BITS if COMPAT

arch/powerpc/include/asm/kasan.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,14 @@
2727

2828
#define KASAN_SHADOW_SIZE (KASAN_SHADOW_END - KASAN_SHADOW_START)
2929

30+
#ifdef CONFIG_KASAN
31+
void kasan_early_init(void);
32+
void kasan_mmu_init(void);
33+
void kasan_init(void);
34+
#else
35+
static inline void kasan_init(void) { }
36+
static inline void kasan_mmu_init(void) { }
37+
#endif
38+
3039
#endif /* __ASSEMBLY */
3140
#endif

arch/powerpc/kernel/head_32.S

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -969,6 +969,9 @@ start_here:
969969
* Do early platform-specific initialization,
970970
* and set up the MMU.
971971
*/
972+
#ifdef CONFIG_KASAN
973+
bl kasan_early_init
974+
#endif
972975
li r3,0
973976
mr r4,r31
974977
bl machine_init

arch/powerpc/kernel/head_40x.S

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -848,6 +848,9 @@ start_here:
848848
/*
849849
* Decide what sort of machine this is and initialize the MMU.
850850
*/
851+
#ifdef CONFIG_KASAN
852+
bl kasan_early_init
853+
#endif
851854
li r3,0
852855
mr r4,r31
853856
bl machine_init

arch/powerpc/kernel/head_44x.S

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,9 @@ _ENTRY(_start);
203203
/*
204204
* Decide what sort of machine this is and initialize the MMU.
205205
*/
206+
#ifdef CONFIG_KASAN
207+
bl kasan_early_init
208+
#endif
206209
li r3,0
207210
mr r4,r31
208211
bl machine_init

arch/powerpc/kernel/head_8xx.S

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -853,6 +853,9 @@ start_here:
853853
/*
854854
* Decide what sort of machine this is and initialize the MMU.
855855
*/
856+
#ifdef CONFIG_KASAN
857+
bl kasan_early_init
858+
#endif
856859
li r3,0
857860
mr r4,r31
858861
bl machine_init

arch/powerpc/kernel/head_fsl_booke.S

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,9 @@ set_ivor:
268268
/*
269269
* Decide what sort of machine this is and initialize the MMU.
270270
*/
271+
#ifdef CONFIG_KASAN
272+
bl kasan_early_init
273+
#endif
271274
mr r3,r30
272275
mr r4,r31
273276
bl machine_init

arch/powerpc/kernel/setup-common.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@
6767
#include <asm/livepatch.h>
6868
#include <asm/mmu_context.h>
6969
#include <asm/cpu_has_feature.h>
70+
#include <asm/kasan.h>
7071

7172
#include "setup.h"
7273

@@ -871,6 +872,8 @@ static void smp_setup_pacas(void)
871872
*/
872873
void __init setup_arch(char **cmdline_p)
873874
{
875+
kasan_init();
876+
874877
*cmdline_p = boot_command_line;
875878

876879
/* Set a half-reasonable default so udelay does something sensible */

arch/powerpc/mm/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,4 @@ obj-$(CONFIG_NOT_COHERENT_CACHE) += dma-noncoherent.o
2626
obj-$(CONFIG_HIGHMEM) += highmem.o
2727
obj-$(CONFIG_PPC_COPRO_BASE) += copro_fault.o
2828
obj-$(CONFIG_PPC_PTDUMP) += ptdump/
29+
obj-$(CONFIG_KASAN) += kasan/

arch/powerpc/mm/init_32.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
#include <asm/sections.h>
4747
#include <asm/hugetlb.h>
4848
#include <asm/kup.h>
49+
#include <asm/kasan.h>
4950

5051
#include <mm/mmu_decl.h>
5152

@@ -179,6 +180,8 @@ void __init MMU_init(void)
179180
btext_unmap();
180181
#endif
181182

183+
kasan_mmu_init();
184+
182185
setup_kup();
183186

184187
/* Shortly after that, the entire linear mapping will be available */

0 commit comments

Comments
 (0)