Skip to content

Commit

Permalink
powerpc/rtas: block error injection when locked down
Browse files Browse the repository at this point in the history
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]>
Acked-by: Paul Moore <[email protected]> (LSM)
Signed-off-by: Michael Ellerman <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
  • Loading branch information
nathanlynch authored and mpe committed Sep 28, 2022
1 parent 99df7a2 commit b8f3e48
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
25 changes: 24 additions & 1 deletion arch/powerpc/kernel/rtas.c
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -463,6 +464,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;
Expand All @@ -475,6 +479,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;
Expand Down Expand Up @@ -1173,6 +1187,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")) {

Expand Down Expand Up @@ -1271,7 +1293,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();
}

Expand Down
1 change: 1 addition & 0 deletions include/linux/security.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions security/security.c
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit b8f3e48

Please sign in to comment.