From: Breno Leitao <leitao@debian.org>
To: linuxppc-dev@lists.ozlabs.org
Cc: Breno Leitao <leitao@debian.org>
Subject: [PATCH] powerpc/kernel: Fix potential spectre v1 in syscall
Date: Tue, 21 Aug 2018 15:42:06 -0300 [thread overview]
Message-ID: <1534876926-21849-1-git-send-email-leitao@debian.org> (raw)
The rtas syscall reads a value from a user-provided structure and uses it
to index an array, being a possible area for a potential spectre v1 attack.
This is the code that exposes this problem.
args.rets = &args.args[nargs];
The nargs is an user provided value, and the below code is an example where
the 'nargs' value would be set to XX.
struct rtas_args ra;
ra.nargs = htobe32(XX);
syscall(__NR_rtas, &ra);
Signed-off-by: Breno Leitao <leitao@debian.org>
---
arch/powerpc/kernel/rtas.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/arch/powerpc/kernel/rtas.c b/arch/powerpc/kernel/rtas.c
index 8afd146bc9c7..5ef3c863003d 100644
--- a/arch/powerpc/kernel/rtas.c
+++ b/arch/powerpc/kernel/rtas.c
@@ -27,6 +27,7 @@
#include <linux/slab.h>
#include <linux/reboot.h>
#include <linux/syscalls.h>
+#include <linux/nospec.h>
#include <asm/prom.h>
#include <asm/rtas.h>
@@ -1056,7 +1057,7 @@ SYSCALL_DEFINE1(rtas, struct rtas_args __user *, uargs)
struct rtas_args args;
unsigned long flags;
char *buff_copy, *errbuf = NULL;
- int nargs, nret, token;
+ int index, nargs, nret, token;
if (!capable(CAP_SYS_ADMIN))
return -EPERM;
@@ -1084,7 +1085,8 @@ SYSCALL_DEFINE1(rtas, struct rtas_args __user *, uargs)
if (token == RTAS_UNKNOWN_SERVICE)
return -EINVAL;
- args.rets = &args.args[nargs];
+ index = array_index_nospec(nargs, ARRAY_SIZE(args.args));
+ args.rets = &args.args[index];
memset(args.rets, 0, nret * sizeof(rtas_arg_t));
/* Need to handle ibm,suspend_me call specially */
--
2.16.3
next reply other threads:[~2018-08-21 18:42 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-08-21 18:42 Breno Leitao [this message]
2024-03-12 8:17 ` [PATCH] powerpc/kernel: Fix potential spectre v1 in syscall Christophe Leroy
2024-03-12 9:05 ` Breno Leitao
2024-03-12 11:07 ` Michael Ellerman
2024-03-12 13:10 ` Breno Leitao
2024-03-18 15:25 ` Nathan Lynch
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1534876926-21849-1-git-send-email-leitao@debian.org \
--to=leitao@debian.org \
--cc=linuxppc-dev@lists.ozlabs.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).