[RFC PATCH 6/6] powerpc/dexcr: Add enforced userspace ROP protection config
Benjamin Gray
bgray at linux.ibm.com
Mon Oct 9 16:54:06 AEDT 2023
The DEXCR Non-Privileged Hash Instruction Enable (NPHIE) aspect controls
whether the hashst and hashchk instructions are treated as no-ops by the
CPU.
NPHIE behaviour per ISA 3.1B:
0: hashst and hashchk instructions are executed as no-ops
(even when allowed by PCR)
1: hashst and hashchk instructions are executed normally
(if allowed by PCR)
Currently this aspect may be set per-process by prctl() or enforced
globally by the hypervisor.
Add a kernel config option PPC_USER_ENFORCE_ROP_PROTECT to enforce
DEXCR[NPHIE] globally regardless of prctl() or hypervisor. If set, don't
report NPHIE as editable via prctl(), as the prctl() value can never
take effect.
Signed-off-by: Benjamin Gray <bgray at linux.ibm.com>
---
arch/powerpc/Kconfig | 5 +++++
arch/powerpc/kernel/dexcr.c | 7 ++++++-
2 files changed, 11 insertions(+), 1 deletion(-)
diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
index 3aaadfd2c8eb..4851cb463dc0 100644
--- a/arch/powerpc/Kconfig
+++ b/arch/powerpc/Kconfig
@@ -473,6 +473,11 @@ config PGTABLE_LEVELS
default 2 if !PPC64
default 4
+config PPC_USER_ENFORCE_ROP_PROTECT
+ bool
+ depends on PPC_BOOK3S_64
+ default y
+
source "arch/powerpc/sysdev/Kconfig"
source "arch/powerpc/platforms/Kconfig"
diff --git a/arch/powerpc/kernel/dexcr.c b/arch/powerpc/kernel/dexcr.c
index e790f76787db..01d8fa28ca17 100644
--- a/arch/powerpc/kernel/dexcr.c
+++ b/arch/powerpc/kernel/dexcr.c
@@ -1,6 +1,8 @@
+#include <linux/cache.h>
#include <linux/capability.h>
#include <linux/cpu.h>
#include <linux/init.h>
+#include <linux/kconfig.h>
#include <linux/prctl.h>
#include <linux/sched.h>
#include <linux/sysctl.h>
@@ -14,7 +16,7 @@
#define DEXCR_PRCTL_EDITABLE ( \
DEXCR_PR_IBRTPD | \
DEXCR_PR_SRAPD | \
- DEXCR_PR_NPHIE)
+ (!IS_ENABLED(CONFIG_PPC_USER_ENFORCE_ROP_PROTECT) ? DEXCR_PR_NPHIE : 0))
static unsigned long dexcr_supported __ro_after_init = 0;
@@ -45,6 +47,9 @@ unsigned long get_thread_dexcr(struct thread_struct const *thread)
{
unsigned long dexcr = thread->dexcr_enabled;
+ if (IS_ENABLED(CONFIG_PPC_USER_ENFORCE_ROP_PROTECT))
+ dexcr |= DEXCR_PR_NPHIE;
+
/*
* spec_branch_hint_enable may be written to concurrently via sysctl.
* The sysctl handler is careful to use WRITE_ONCE, so we avoid
--
2.41.0
More information about the Linuxppc-dev
mailing list