aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristophe Leroy <christophe.leroy@c-s.fr>2019-04-18 02:51:18 -0400
committerMichael Ellerman <mpe@ellerman.id.au>2019-04-21 09:05:54 -0400
commit69795cabe4cfe5122438d50010ad5310c113a013 (patch)
tree1a6f463d544b6ce25276c05558123d3614a7b6db
parent53a712bae5dd919521a58d7bad773b949358add0 (diff)
powerpc: Add framework for Kernel Userspace Protection
This patch adds a skeleton for Kernel Userspace Protection functionnalities like Kernel Userspace Access Protection and Kernel Userspace Execution Prevention The subsequent implementation of KUAP for radix makes use of a MMU feature in order to patch out assembly when KUAP is disabled or unsupported. This won't work unless there's an entry point for KUP support before the feature magic happens, so for PPC64 setup_kup() is called early in setup. On PPC32, feature_fixup() is done too early to allow the same. Suggested-by: Russell Currey <ruscur@russell.cc> Signed-off-by: Christophe Leroy <christophe.leroy@c-s.fr> Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
-rw-r--r--arch/powerpc/include/asm/kup.h11
-rw-r--r--arch/powerpc/kernel/setup_64.c7
-rw-r--r--arch/powerpc/mm/init-common.c5
-rw-r--r--arch/powerpc/mm/init_32.c3
4 files changed, 26 insertions, 0 deletions
diff --git a/arch/powerpc/include/asm/kup.h b/arch/powerpc/include/asm/kup.h
new file mode 100644
index 000000000000..7a88b8b9b54d
--- /dev/null
+++ b/arch/powerpc/include/asm/kup.h
@@ -0,0 +1,11 @@
1/* SPDX-License-Identifier: GPL-2.0 */
2#ifndef _ASM_POWERPC_KUP_H_
3#define _ASM_POWERPC_KUP_H_
4
5#ifndef __ASSEMBLY__
6
7void setup_kup(void);
8
9#endif /* !__ASSEMBLY__ */
10
11#endif /* _ASM_POWERPC_KUP_H_ */
diff --git a/arch/powerpc/kernel/setup_64.c b/arch/powerpc/kernel/setup_64.c
index ba404dd9ce1d..6179c4200339 100644
--- a/arch/powerpc/kernel/setup_64.c
+++ b/arch/powerpc/kernel/setup_64.c
@@ -68,6 +68,7 @@
68#include <asm/cputhreads.h> 68#include <asm/cputhreads.h>
69#include <asm/hw_irq.h> 69#include <asm/hw_irq.h>
70#include <asm/feature-fixups.h> 70#include <asm/feature-fixups.h>
71#include <asm/kup.h>
71 72
72#include "setup.h" 73#include "setup.h"
73 74
@@ -331,6 +332,12 @@ void __init early_setup(unsigned long dt_ptr)
331 */ 332 */
332 configure_exceptions(); 333 configure_exceptions();
333 334
335 /*
336 * Configure Kernel Userspace Protection. This needs to happen before
337 * feature fixups for platforms that implement this using features.
338 */
339 setup_kup();
340
334 /* Apply all the dynamic patching */ 341 /* Apply all the dynamic patching */
335 apply_feature_fixups(); 342 apply_feature_fixups();
336 setup_feature_keys(); 343 setup_feature_keys();
diff --git a/arch/powerpc/mm/init-common.c b/arch/powerpc/mm/init-common.c
index 1e6910eb70ed..36d28e872289 100644
--- a/arch/powerpc/mm/init-common.c
+++ b/arch/powerpc/mm/init-common.c
@@ -24,6 +24,11 @@
24#include <linux/string.h> 24#include <linux/string.h>
25#include <asm/pgalloc.h> 25#include <asm/pgalloc.h>
26#include <asm/pgtable.h> 26#include <asm/pgtable.h>
27#include <asm/kup.h>
28
29void __init setup_kup(void)
30{
31}
27 32
28#define CTOR(shift) static void ctor_##shift(void *addr) \ 33#define CTOR(shift) static void ctor_##shift(void *addr) \
29{ \ 34{ \
diff --git a/arch/powerpc/mm/init_32.c b/arch/powerpc/mm/init_32.c
index 41a3513cadc9..80cc97cd8878 100644
--- a/arch/powerpc/mm/init_32.c
+++ b/arch/powerpc/mm/init_32.c
@@ -45,6 +45,7 @@
45#include <asm/tlb.h> 45#include <asm/tlb.h>
46#include <asm/sections.h> 46#include <asm/sections.h>
47#include <asm/hugetlb.h> 47#include <asm/hugetlb.h>
48#include <asm/kup.h>
48 49
49#include "mmu_decl.h" 50#include "mmu_decl.h"
50 51
@@ -178,6 +179,8 @@ void __init MMU_init(void)
178 btext_unmap(); 179 btext_unmap();
179#endif 180#endif
180 181
182 setup_kup();
183
181 /* Shortly after that, the entire linear mapping will be available */ 184 /* Shortly after that, the entire linear mapping will be available */
182 memblock_set_current_limit(lowmem_end_addr); 185 memblock_set_current_limit(lowmem_end_addr);
183} 186}