powerpc/pseries: restrict error injection and DT changes when locked down
Subsystems (2)
v2 cover powerpc/pseries: restrict error injection and DT changes when locked down
Add two new lockdown reasons for use in powerpc's pseries platform code.
The pseries platform allows hardware-level error injection via certain calls to the RTAS (Run Time Abstraction Services) firmware. ACPI-based error injection is already restricted in lockdown; this facility should be restricted for the same reasons.
pseries also allows nearly arbitrary device tree changes via /proc/powerpc/ofdt. Just as overriding ACPI tables is not allowed while locked down, so should this facility be restricted.
Changes since v1:
* Move LOCKDOWN_DEVICE_TREE next to LOCKDOWN_ACPI_TABLES.
Nathan Lynch (2):
powerpc/pseries: block untrusted device tree changes when locked down powerpc/rtas: block error injection when locked down
arch/powerpc/kernel/rtas.c | 25 ++++++++++++++++++++++- arch/powerpc/platforms/pseries/reconfig.c | 5 +++++ include/linux/security.h | 2 ++ security/security.c | 2 ++ 4 files changed, 33 insertions(+), 1 deletion(-)
Signature · 1 line
2.37.3
PATCH v2 1/2 powerpc/pseries: block untrusted device tree changes when locked down
The /proc/powerpc/ofdt interface allows the root user to freely alter the in-kernel device tree, enabling arbitrary physical address writes via drivers that could bind to malicious device nodes, thus making it possible to disable lockdown.
Historically this interface has been used on the pseries platform to facilitate the runtime addition and removal of processor, memory, and device resources (aka Dynamic Logical Partitioning or DLPAR). Years ago, the processor and memory use cases were migrated to designs that happen to be lockdown-friendly: device tree updates are communicated directly to the kernel from firmware without passing through untrusted user space. I/O device DLPAR via the "drmgr" command in powerpc-utils remains the sole legitimate user of /proc/powerpc/ofdt, but it is already broken in lockdown since it uses /dev/mem to allocate argument buffers for the rtas syscall. So only illegitimate uses of the interface should see a behavior change when running on a locked down kernel.
--- arch/powerpc/platforms/pseries/reconfig.c | 5 +++++ include/linux/security.h | 1 + security/security.c | 1 + 3 files changed, 7 insertions(+)
arch/powerpc/platforms/pseries/reconfig.c +5 -0
@@ -10,6 +10,7 @@#include <linux/kernel.h> #include <linux/notifier.h> #include <linux/proc_fs.h> +#include <linux/security.h> #include <linux/slab.h> #include <linux/of.h>
@@ -361,6 +362,10 @@ static ssize_t ofdt_write(struct file *file, const char __user *buf, size_t counchar *kbuf;char *tmp; + rv =security_locked_down (LOCKDOWN_DEVICE_TREE ); +if (rv) +return rv; + kbuf =memdup_user_nul (buf, count);if (IS_ERR (kbuf))return PTR_ERR (kbuf);
include/linux/security.h +1 -0
@@ -114,6 +114,7 @@ enum lockdown_reason {LOCKDOWN_IOPORT ,LOCKDOWN_MSR ,LOCKDOWN_ACPI_TABLES , +LOCKDOWN_DEVICE_TREE ,LOCKDOWN_PCMCIA_CIS ,LOCKDOWN_TIOCSSERIAL , LOCKDOWN_MODULE_PARAMETERS,
security/security.c +1 -0
@@ -52,6 +52,7 @@ const char *const lockdown_reasons[LOCKDOWN_CONFIDENTIALITY_MAX+1] = { [LOCKDOWN_IOPORT] = "raw io port access", [LOCKDOWN_MSR] = "raw MSR access", [LOCKDOWN_ACPI_TABLES] = "modifying ACPI tables", + [LOCKDOWN_DEVICE_TREE] = "modifying device tree contents", [LOCKDOWN_PCMCIA_CIS] = "direct PCMCIA CIS storage", [LOCKDOWN_TIOCSSERIAL] = "reconfiguration of serial port IO", [LOCKDOWN_MODULE_PARAMETERS] = "unsafe module parameters",
Signature · 1 line
2.37.3
Re: [PATCH v2 1/2] powerpc/pseries: block untrusted device tree changes when locked down
Quoted 19 lines · Nathan Lynch
The
/proc/powerpc/ofdtinterface allows the root user to freely alter the in-kernel device tree, enabling arbitrary physical address writes via drivers that could bind to malicious device nodes, thus making it possible to disable lockdown.Historically this interface has been used on the pseries platform to facilitate the runtime addition and removal of processor, memory, and device resources (aka Dynamic Logical Partitioning or DLPAR). Years ago, the processor and memory use cases were migrated to designs that happen to be lockdown-friendly: device tree updates are communicated directly to the kernel from firmware without passing through untrusted user space. I/O device DLPAR via the "drmgr" command in powerpc-utils remains the sole legitimate user of
/proc/powerpc/ofdt, but it is already broken in lockdown since it uses/dev/memto allocate argument buffers for the rtas syscall. So only illegitimate uses of the interface should see a behavior change when running on a locked down kernel.
Quoted 6 lines
Signed-off-by Nathan Lynch <[email protected]>--- arch/powerpc/platforms/pseries/reconfig.c | 5 +++++ include/linux/security.h | 1 + security/security.c | 1 + 3 files changed, 7 insertions(+)
Thanks for moving the definitions.
Quoted 50 lines
arch/powerpc/platforms/pseries/reconfig.c +5
-0@@ -10,6 +10,7 @@#include <linux/kernel.h> #include <linux/notifier.h> #include <linux/proc_fs.h> +#include <linux/security.h> #include <linux/slab.h> #include <linux/of.h> @@ -361,6 +362,10 @@ static ssize_t ofdt_write(struct file *file, const char __user *buf, size_t counchar *kbuf;char *tmp; + rv =security_locked_down (LOCKDOWN_DEVICE_TREE ); +if (rv) +return rv; + kbuf =memdup_user_nul (buf, count);if (IS_ERR (kbuf))return PTR_ERR (kbuf);include/linux/security.h +1
-0@@ -114,6 +114,7 @@ enum lockdown_reason {LOCKDOWN_IOPORT ,LOCKDOWN_MSR ,LOCKDOWN_ACPI_TABLES , +LOCKDOWN_DEVICE_TREE ,LOCKDOWN_PCMCIA_CIS ,LOCKDOWN_TIOCSSERIAL , LOCKDOWN_MODULE_PARAMETERS,security/security.c +1
-1@@ -52,6 +52,7 @@ const char *const lockdown_reasons[LOCKDOWN_CONFIDENTIALITY_MAX+1] = { [LOCKDOWN_IOPORT] = "raw io port access", [LOCKDOWN_MSR] = "raw MSR access", [LOCKDOWN_ACPI_TABLES] = "modifying ACPI tables", + [LOCKDOWN_DEVICE_TREE] = "modifying device tree contents", [LOCKDOWN_PCMCIA_CIS] = "direct PCMCIA CIS storage", [LOCKDOWN_TIOCSSERIAL] = "reconfiguration of serial port IO", [LOCKDOWN_MODULE_PARAMETERS] = "unsafe module parameters", --2.37.3
Signature · 1 line
paul-moore.com
Re: [PATCH v2 1/2] powerpc/pseries: block untrusted device tree changes when locked down
In reply to Nathan LynchQuoted 20 lines · Nathan Lynch
The
/proc/powerpc/ofdtinterface allows the root user to freely alter the in-kernel device tree, enabling arbitrary physical address writes via drivers that could bind to malicious device nodes, thus making it possible to disable lockdown.Historically this interface has been used on the pseries platform to facilitate the runtime addition and removal of processor, memory, and device resources (aka Dynamic Logical Partitioning or DLPAR). Years ago, the processor and memory use cases were migrated to designs that happen to be lockdown-friendly: device tree updates are communicated directly to the kernel from firmware without passing through untrusted
user space. I/O device DLPAR via the "drmgr" command in powerpc-utils remains the sole legitimate user of/proc/powerpc/ofdt, but it is already broken in lockdown since it uses/dev/memto allocate argument
buffers for the rtas syscall. So only illegitimate uses of the interface should see a behavior change when running on a locked down kernel.
Quoted 1 line
Signed-off-by Nathan Lynch <[email protected]>
Seems sensible to me.
Quoted 56 lines
---
arch/powerpc/platforms/pseries/reconfig.c | 5 +++++ include/linux/security.h | 1 + security/security.c | 1 +3 files changed, 7 insertions(+)arch/powerpc/platforms/pseries/reconfig.c +1
-0@@ -10,6 +10,7 @@ #include <linux/kernel.h> #include <linux/notifier.h> #include <linux/proc_fs.h> +#include <linux/security.h> #include <linux/slab.h> #include <linux/of.h>arch/powerpc/platforms/pseries/reconfig.c +0
-0@@ -361,6 +362,10 @@ static ssize_t ofdt_write(struct file *file,const char
__user*buf,size_tcoun
char *kbuf;
char *tmp;
+ rv =security_locked_down(LOCKDOWN_DEVICE_TREE); + if (rv)
+ return rv;
+
kbuf =memdup_user_nul(buf, count);
if (IS_ERR(kbuf))
returnPTR_ERR(kbuf);include/linux/security.h +1
-0@@ -114,6 +114,7 @@ enum lockdown_reason { LOCKDOWN_IOPORT, LOCKDOWN_MSR, LOCKDOWN_ACPI_TABLES, + LOCKDOWN_DEVICE_TREE, LOCKDOWN_PCMCIA_CIS, LOCKDOWN_TIOCSSERIAL, LOCKDOWN_MODULE_PARAMETERS,security/security.c +1
-0@@ -52,6 +52,7 @@ const char *const lockdown_reasons[LOCKDOWN_CONFIDENTIALITY_MAX+1] = { [LOCKDOWN_IOPORT] = "raw io port access", [LOCKDOWN_MSR] = "raw MSR access", [LOCKDOWN_ACPI_TABLES] = "modifying ACPI tables", + [LOCKDOWN_DEVICE_TREE] = "modifying device tree contents", [LOCKDOWN_PCMCIA_CIS] = "direct PCMCIA CIS storage", [LOCKDOWN_TIOCSSERIAL] = "reconfiguration of serial port IO",[LOCKDOWN_MODULE_PARAMETERS] = "unsafe module parameters",
Signature · 2 lines
Andrew Donnellan OzLabs, ADL Canberra [email protected] IBM Australia Limited
PATCH v2 2/2 powerpc/rtas: block error injection when locked down
In reply to Nathan LynchThe error injection facility on pseries VMs allows corruption of arbitrary guest memory, potentially enabling a sufficiently privileged user to disable lockdown or perform other modifications of the running kernel via the rtas syscall.
Block the PAPR error injection facility from being opened or called when locked down.
--- arch/powerpc/kernel/rtas.c | 25 ++++++++++++++++++++++++- include/linux/security.h | 1 + security/security.c | 1 + 3 files changed, 26 insertions(+), 1 deletion(-)
arch/powerpc/kernel/rtas.c +24 -1
@@ -23,6 +23,7 @@#include <linux/memblock.h> #include <linux/slab.h> #include <linux/reboot.h> +#include <linux/security.h> #include <linux/syscalls.h> #include <linux/of.h> #include <linux/of_fdt.h>
@@ -464,6 +465,9 @@ void rtas_call_unlocked(struct rtas_args *args, int token, int nargs, int nret,va_end (list); } +static int ibm_open_errinjct_token; +static int ibm_errinjct_token; +int rtas_call (int token,int nargs,int nret,int *outputs, ...) {va_list list;
@@ -476,6 +480,16 @@ int rtas_call(int token, int nargs, int nret, int *outputs, ...)if (!rtas.entry || token ==RTAS_UNKNOWN_SERVICE )return -1 ; +if (token == ibm_open_errinjct_token || token == ibm_errinjct_token) { +/* +* It would be nicer to not discard the error value +* from security_locked_down(), but callers expect an +* RTAS status, not an errno. +*/ +if (security_locked_down (LOCKDOWN_RTAS_ERROR_INJECTION )) +return -1 ; + } +if ((mfmsr () & (MSR_IR |MSR_DR )) != (MSR_IR |MSR_DR )) {WARN_ON_ONCE (1 );return -1 ;
@@ -1227,6 +1241,14 @@ SYSCALL_DEFINE1(rtas, struct rtas_args __user *, uargs)if (block_rtas_call (token, nargs, &args))return -EINVAL ; +if (token == ibm_open_errinjct_token || token == ibm_errinjct_token) { +int err; + + err =security_locked_down (LOCKDOWN_RTAS_ERROR_INJECTION ); +if (err) +return err; + } +/* Need to handle ibm,suspend_me call specially */ if (token ==rtas_token ("ibm,suspend-me" )) {
@@ -1325,7 +1347,8 @@ void __init rtas_initialize(void)#ifdef CONFIG_RTAS_ERROR_LOGGING rtas_last_error_token =rtas_token ("rtas-last-error" );#endif - + ibm_open_errinjct_token =rtas_token ("ibm,open-errinjct" ); + ibm_errinjct_token =rtas_token ("ibm,errinjct" );rtas_syscall_filter_init (); }
include/linux/security.h +1 -0
@@ -123,6 +123,7 @@ enum lockdown_reason {LOCKDOWN_XMON_WR ,LOCKDOWN_BPF_WRITE_USER ,LOCKDOWN_DBG_WRITE_KERNEL , +LOCKDOWN_RTAS_ERROR_INJECTION ,LOCKDOWN_INTEGRITY_MAX ,LOCKDOWN_KCORE , LOCKDOWN_KPROBES,
security/security.c +1 -0
@@ -61,6 +61,7 @@ const char *const lockdown_reasons[LOCKDOWN_CONFIDENTIALITY_MAX+1] = { [LOCKDOWN_XMON_WR] = "xmon write access", [LOCKDOWN_BPF_WRITE_USER] = "use of bpf to write user RAM", [LOCKDOWN_DBG_WRITE_KERNEL] = "use of kgdb/kdb to write kernel RAM", + [LOCKDOWN_RTAS_ERROR_INJECTION] = "RTAS error injection", [LOCKDOWN_INTEGRITY_MAX] = "integrity", [LOCKDOWN_KCORE] = "/proc/kcore access", [LOCKDOWN_KPROBES] = "use of kprobes",
Signature · 1 line
2.37.3
Re: [PATCH v2 2/2] powerpc/rtas: block error injection when locked down
Quoted 9 lines · Nathan Lynch
The error injection facility on pseries VMs allows corruption of arbitrary guest memory, potentially enabling a sufficiently privileged user to disable lockdown or perform other modifications of the running kernel via the rtas syscall.
Block the PAPR error injection facility from being opened or called when locked down.
Quoted 6 lines
Signed-off-by Nathan Lynch <[email protected]>--- arch/powerpc/kernel/rtas.c | 25 ++++++++++++++++++++++++- include/linux/security.h | 1 + security/security.c | 1 + 3 files changed, 26 insertions(+), 1 deletion(-)
The lockdown changes are trivial, but they look fine to me.
Signature · 1 line
paul-moore.com
Re: [PATCH v2 2/2] powerpc/rtas: block error injection when locked down
In reply to Nathan LynchQuoted 11 lines · Nathan Lynch
The error injection facility on pseries VMs allows corruption of arbitrary guest memory, potentially enabling a sufficiently privileged
user to disable lockdown or perform other modifications of the running
kernel via the rtas syscall.Block the PAPR error injection facility from being opened or called when locked down.
Signed-off-by Nathan Lynch <[email protected]>
Is there any circumstance (short of arbitrary code execution etc) where the rtas_call() check will actually trigger rather than the sys_rtas() check? (Not that it matters, defence in depth is good.)
Quoted 103 lines
---
arch/powerpc/kernel/rtas.c | 25 ++++++++++++++++++++++++- include/linux/security.h | 1 + security/security.c | 1 +3 files changed, 26 insertions(+), 1 deletion(-)arch/powerpc/kernel/rtas.c +1
-0@@ -23,6 +23,7 @@ #include <linux/memblock.h> #include <linux/slab.h> #include <linux/reboot.h> +#include <linux/security.h> #include <linux/syscalls.h> #include <linux/of.h> #include <linux/of_fdt.h>@@ -464,6 +465,9 @@ void rtas_call_unlocked(struct rtas_args *args, int token, int nargs, int nret, va_end(list); }arch/powerpc/kernel/rtas.c +3
-0+static int ibm_open_errinjct_token; +static int ibm_errinjct_token; +int
rtas_call(int token, int nargs, int nret, int *outputs, ...){
va_list list;arch/powerpc/kernel/rtas.c +0
-0@@ -476,6 +480,16 @@ int rtas_call(int token, int nargs, int nret, int *outputs, ...) if (!rtas.entry || token == RTAS_UNKNOWN_SERVICE) return -1;
+ if (token ==ibm_open_errinjct_token|| token ==ibm_errinjct_token) {
+ /*
+ * It would be nicer to not discard the error value + * fromsecurity_locked_down(), but callers expect an + * RTAS status, not an errno.
+ */
+ if (security_locked_down(LOCKDOWN_RTAS_ERROR_INJECTION))
+ return -1;
+ }
+
if ((mfmsr()& (MSR_IR|MSR_DR)) != (MSR_IR|MSR_DR)) {WARN_ON_ONCE(1);
return -1;arch/powerpc/kernel/rtas.c +0
-0@@ -1227,6 +1241,14 @@ SYSCALL_DEFINE1(rtas, struct rtas_args __user *, uargs) if (block_rtas_call(token, nargs, &args)) return -EINVAL;
+ if (token ==ibm_open_errinjct_token|| token ==ibm_errinjct_token) {
+ int err;
+
+ err =security_locked_down(LOCKDOWN_RTAS_ERROR_INJECTION); + if (err)
+ return err;
+ }
+
/* Need to handle ibm,suspend_me call specially */ if (token ==rtas_token("ibm,suspend-me")) {arch/powerpc/kernel/rtas.c +2
-1@@ -1325,7 +1347,8 @@ void __init rtas_initialize(void) #ifdef CONFIG_RTAS_ERROR_LOGGING rtas_last_error_token = rtas_token("rtas-last-error"); #endif - + ibm_open_errinjct_token = rtas_token("ibm,open-errinjct"); + ibm_errinjct_token = rtas_token("ibm,errinjct"); rtas_syscall_filter_init(); }include/linux/security.h +1
-0@@ -123,6 +123,7 @@ enum lockdown_reason { LOCKDOWN_XMON_WR, LOCKDOWN_BPF_WRITE_USER, LOCKDOWN_DBG_WRITE_KERNEL, + LOCKDOWN_RTAS_ERROR_INJECTION, LOCKDOWN_INTEGRITY_MAX, LOCKDOWN_KCORE, LOCKDOWN_KPROBES,security/security.c +0
-0@@ -61,6 +61,7 @@ const char *const lockdown_reasons[LOCKDOWN_CONFIDENTIALITY_MAX+1] = { [LOCKDOWN_XMON_WR] = "xmon write access", [LOCKDOWN_BPF_WRITE_USER] = "use of bpf to write user RAM",[LOCKDOWN_DBG_WRITE_KERNEL] = "use of kgdb/kdb to write kernel RAM",
+ [LOCKDOWN_RTAS_ERROR_INJECTION] = "RTAS error injection", [LOCKDOWN_INTEGRITY_MAX] = "integrity", [LOCKDOWN_KCORE] = "/proc/kcoreaccess", [LOCKDOWN_KPROBES] = "use of kprobes",
Signature · 2 lines
Andrew Donnellan OzLabs, ADL Canberra [email protected] IBM Australia Limited
Re: [PATCH v2 2/2] powerpc/rtas: block error injection when locked down
Quoted 8 lines · Andrew Donnellan
Quoted 7 lines · Nathan Lynch
The error injection facility on pseries VMs allows corruption of arbitrary guest memory, potentially enabling a sufficiently privileged
user to disable lockdown or perform other modifications of the running
kernel via the rtas syscall.
Quoted 8 lines
Quoted 4 lines
Block the PAPR error injection facility from being opened or called when locked down.
Signed-off-by Nathan Lynch <[email protected]>Is there any circumstance (short of arbitrary code execution etc) where the
rtas_call()check will actually trigger rather than thesys_rtas()check? (Not that it matters, defence in depth is good.)
Fair question! There are no in-kernel users of rtas_call() that pass the error injection tokens as far as I could tell. Nor am I aware of any out-of-tree users, for that matter. But rtas_call() is the likely most appropriate place to have the lockdown gate should that situation change (as it might, see https://github.com/ibm-power-utilities/librtas/issues/29).
Michael Ellerman
AppliedQuoted 9 lines · Nathan Lynch
Add two new lockdown reasons for use in powerpc's pseries platform code.
The pseries platform allows hardware-level error injection via certain calls to the RTAS (Run Time Abstraction Services) firmware. ACPI-based error injection is already restricted in lockdown; this facility should be restricted for the same reasons.
[...]
Applied to powerpc/next.
[1/2] powerpc/pseries: block untrusted device tree changes when locked down
https://git.kernel.org/powerpc/c/99df7a2810b6d24651d4887ab61a142e042fb235 [2/2] powerpc/rtas: block error injection when locked down https://git.kernel.org/powerpc/c/b8f3e48834fe8c86b4f21739c6effd160e2c2c19
cheers