#include <linux/jump_label.h>
+extern struct static_key_false disable_kuap_key;
extern struct static_key_false disable_kuep_key;
static __always_inline bool kuap_is_disabled(void)
{
- return !IS_ENABLED(CONFIG_PPC_KUAP);
+ return !IS_ENABLED(CONFIG_PPC_KUAP) || static_branch_unlikely(&disable_kuap_key);
}
static __always_inline bool kuep_is_disabled(void)
u32 addr = kuap & 0xf0000000;
u32 end = kuap << 28;
+ if (kuap_is_disabled())
+ return;
+
regs->kuap = kuap;
if (unlikely(!kuap))
return;
u32 addr = regs->kuap & 0xf0000000;
u32 end = regs->kuap << 28;
+ if (kuap_is_disabled())
+ return;
+
current->thread.kuap = regs->kuap;
if (unlikely(regs->kuap == kuap))
{
unsigned long kuap = current->thread.kuap;
+ if (kuap_is_disabled())
+ return 0;
+
WARN_ON_ONCE(IS_ENABLED(CONFIG_PPC_KUAP_DEBUG) && kuap != 0);
return kuap;
{
u32 addr, end;
+ if (kuap_is_disabled())
+ return;
+
BUILD_BUG_ON(!__builtin_constant_p(dir));
BUILD_BUG_ON(dir & ~KUAP_READ_WRITE);
{
u32 addr, end;
+ if (kuap_is_disabled())
+ return;
+
BUILD_BUG_ON(!__builtin_constant_p(dir));
if (dir & KUAP_CURRENT_WRITE) {
unsigned long end = flags << 28;
void __user *to = (__force void __user *)addr;
+ if (kuap_is_disabled())
+ return 0;
+
if (flags)
prevent_user_access(to, to, end - addr, KUAP_READ_WRITE);
unsigned long end = flags << 28;
void __user *to = (__force void __user *)addr;
+ if (kuap_is_disabled())
+ return;
+
if (flags)
allow_user_access(to, to, end - addr, KUAP_READ_WRITE);
}
unsigned long begin = regs->kuap & 0xf0000000;
unsigned long end = regs->kuap << 28;
+ if (kuap_is_disabled())
+ return false;
+
return is_write && (address < begin || address >= end);
}
#include <asm/kup.h>
#include <asm/smp.h>
+struct static_key_false disable_kuap_key;
+EXPORT_SYMBOL(disable_kuap_key);
+
void __init setup_kuap(bool disabled)
{
- kuap_update_sr(mfsr(0) | SR_KS, 0, TASK_SIZE);
+ if (!disabled)
+ kuap_update_sr(mfsr(0) | SR_KS, 0, TASK_SIZE);
if (smp_processor_id() != boot_cpuid)
return;
- pr_info("Activating Kernel Userspace Access Protection\n");
-
if (disabled)
- pr_warn("KUAP cannot be disabled yet on 6xx when compiled in\n");
+ static_branch_enable(&disable_kuap_key);
+ else
+ pr_info("Activating Kernel Userspace Access Protection\n");
}