Commit 0fb1c25a authored by Christophe Leroy's avatar Christophe Leroy Committed by Michael Ellerman

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: default avatarChristophe Leroy <christophe.leroy@c-s.fr>
[mpe: Don't split strings, use pr_crit_ratelimited()]
Signed-off-by: default avatarMichael Ellerman <mpe@ellerman.id.au>
parent 69795cab
...@@ -2843,7 +2843,7 @@ ...@@ -2843,7 +2843,7 @@
Disable SMAP (Supervisor Mode Access Prevention) Disable SMAP (Supervisor Mode Access Prevention)
even if it is supported by processor. even if it is supported by processor.
nosmep [X86] nosmep [X86,PPC]
Disable SMEP (Supervisor Mode Execution Prevention) Disable SMEP (Supervisor Mode Execution Prevention)
even if it is supported by processor. even if it is supported by processor.
......
...@@ -6,6 +6,12 @@ ...@@ -6,6 +6,12 @@
void setup_kup(void); void setup_kup(void);
#ifdef CONFIG_PPC_KUEP
void setup_kuep(bool disabled);
#else
static inline void setup_kuep(bool disabled) { }
#endif /* CONFIG_PPC_KUEP */
#endif /* !__ASSEMBLY__ */ #endif /* !__ASSEMBLY__ */
#endif /* _ASM_POWERPC_KUP_H_ */ #endif /* _ASM_POWERPC_KUP_H_ */
...@@ -229,11 +229,10 @@ static bool bad_kernel_fault(bool is_exec, unsigned long error_code, ...@@ -229,11 +229,10 @@ static bool bad_kernel_fault(bool is_exec, unsigned long error_code,
/* NX faults set DSISR_PROTFAULT on the 8xx, DSISR_NOEXEC_OR_G on others */ /* NX faults set DSISR_PROTFAULT on the 8xx, DSISR_NOEXEC_OR_G on others */
if (is_exec && (error_code & (DSISR_NOEXEC_OR_G | DSISR_KEYFAULT | if (is_exec && (error_code & (DSISR_NOEXEC_OR_G | DSISR_KEYFAULT |
DSISR_PROTFAULT))) { DSISR_PROTFAULT))) {
printk_ratelimited(KERN_CRIT "kernel tried to execute" pr_crit_ratelimited("kernel tried to execute %s page (%lx) - exploit attempt? (uid: %d)\n",
" exec-protected page (%lx) -" address >= TASK_SIZE ? "exec-protected" : "user",
"exploit attempt? (uid: %d)\n", address,
address, from_kuid(&init_user_ns, from_kuid(&init_user_ns, current_uid()));
current_uid()));
} }
return is_exec || (address >= TASK_SIZE); return is_exec || (address >= TASK_SIZE);
} }
......
...@@ -26,8 +26,19 @@ ...@@ -26,8 +26,19 @@
#include <asm/pgtable.h> #include <asm/pgtable.h>
#include <asm/kup.h> #include <asm/kup.h>
static bool disable_kuep = !IS_ENABLED(CONFIG_PPC_KUEP);
static int __init parse_nosmep(char *p)
{
disable_kuep = true;
pr_warn("Disabling Kernel Userspace Execution Prevention\n");
return 0;
}
early_param("nosmep", parse_nosmep);
void __init setup_kup(void) void __init setup_kup(void)
{ {
setup_kuep(disable_kuep);
} }
#define CTOR(shift) static void ctor_##shift(void *addr) \ #define CTOR(shift) static void ctor_##shift(void *addr) \
......
...@@ -345,6 +345,18 @@ config PPC_RADIX_MMU_DEFAULT ...@@ -345,6 +345,18 @@ config PPC_RADIX_MMU_DEFAULT
If you're unsure, say Y. If you're unsure, say Y.
config PPC_HAVE_KUEP
bool
config PPC_KUEP
bool "Kernel Userspace Execution Prevention"
depends on PPC_HAVE_KUEP
default y
help
Enable support for Kernel Userspace Execution Prevention (KUEP)
If you're unsure, say Y.
config ARCH_ENABLE_HUGEPAGE_MIGRATION config ARCH_ENABLE_HUGEPAGE_MIGRATION
def_bool y def_bool y
depends on PPC_BOOK3S_64 && HUGETLB_PAGE && MIGRATION depends on PPC_BOOK3S_64 && HUGETLB_PAGE && MIGRATION
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment