Skip to content

Commit 0fb1c25

Browse files
chleroympe
authored andcommitted
powerpc: Add skeleton for Kernel Userspace Execution Prevention
This patch adds a skeleton for Kernel Userspace Execution Prevention. Then subarches implementing it have to define CONFIG_PPC_HAVE_KUEP and provide setup_kuep() function. Signed-off-by: Christophe Leroy <christophe.leroy@c-s.fr> [mpe: Don't split strings, use pr_crit_ratelimited()] Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
1 parent 69795ca commit 0fb1c25

File tree

5 files changed

+34
-6
lines changed

5 files changed

+34
-6
lines changed

Documentation/admin-guide/kernel-parameters.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2843,7 +2843,7 @@
28432843
Disable SMAP (Supervisor Mode Access Prevention)
28442844
even if it is supported by processor.
28452845

2846-
nosmep [X86]
2846+
nosmep [X86,PPC]
28472847
Disable SMEP (Supervisor Mode Execution Prevention)
28482848
even if it is supported by processor.
28492849

arch/powerpc/include/asm/kup.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@
66

77
void setup_kup(void);
88

9+
#ifdef CONFIG_PPC_KUEP
10+
void setup_kuep(bool disabled);
11+
#else
12+
static inline void setup_kuep(bool disabled) { }
13+
#endif /* CONFIG_PPC_KUEP */
14+
915
#endif /* !__ASSEMBLY__ */
1016

1117
#endif /* _ASM_POWERPC_KUP_H_ */

arch/powerpc/mm/fault.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -229,11 +229,10 @@ static bool bad_kernel_fault(bool is_exec, unsigned long error_code,
229229
/* NX faults set DSISR_PROTFAULT on the 8xx, DSISR_NOEXEC_OR_G on others */
230230
if (is_exec && (error_code & (DSISR_NOEXEC_OR_G | DSISR_KEYFAULT |
231231
DSISR_PROTFAULT))) {
232-
printk_ratelimited(KERN_CRIT "kernel tried to execute"
233-
" exec-protected page (%lx) -"
234-
"exploit attempt? (uid: %d)\n",
235-
address, from_kuid(&init_user_ns,
236-
current_uid()));
232+
pr_crit_ratelimited("kernel tried to execute %s page (%lx) - exploit attempt? (uid: %d)\n",
233+
address >= TASK_SIZE ? "exec-protected" : "user",
234+
address,
235+
from_kuid(&init_user_ns, current_uid()));
237236
}
238237
return is_exec || (address >= TASK_SIZE);
239238
}

arch/powerpc/mm/init-common.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,19 @@
2626
#include <asm/pgtable.h>
2727
#include <asm/kup.h>
2828

29+
static bool disable_kuep = !IS_ENABLED(CONFIG_PPC_KUEP);
30+
31+
static int __init parse_nosmep(char *p)
32+
{
33+
disable_kuep = true;
34+
pr_warn("Disabling Kernel Userspace Execution Prevention\n");
35+
return 0;
36+
}
37+
early_param("nosmep", parse_nosmep);
38+
2939
void __init setup_kup(void)
3040
{
41+
setup_kuep(disable_kuep);
3142
}
3243

3344
#define CTOR(shift) static void ctor_##shift(void *addr) \

arch/powerpc/platforms/Kconfig.cputype

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,18 @@ config PPC_RADIX_MMU_DEFAULT
345345

346346
If you're unsure, say Y.
347347

348+
config PPC_HAVE_KUEP
349+
bool
350+
351+
config PPC_KUEP
352+
bool "Kernel Userspace Execution Prevention"
353+
depends on PPC_HAVE_KUEP
354+
default y
355+
help
356+
Enable support for Kernel Userspace Execution Prevention (KUEP)
357+
358+
If you're unsure, say Y.
359+
348360
config ARCH_ENABLE_HUGEPAGE_MIGRATION
349361
def_bool y
350362
depends on PPC_BOOK3S_64 && HUGETLB_PAGE && MIGRATION

0 commit comments

Comments
 (0)