Skip to content

Commit 0974d03

Browse files
nathanlynchmpe
authored andcommitted
powerpc/rtas: Prevent Spectre v1 gadget construction in sys_rtas()
Smatch warns: arch/powerpc/kernel/rtas.c:1932 __do_sys_rtas() warn: potential spectre issue 'args.args' [r] (local cap) The 'nargs' and 'nret' locals come directly from a user-supplied buffer and are used as indexes into a small stack-based array and as inputs to copy_to_user() after they are subject to bounds checks. Use array_index_nospec() after the bounds checks to clamp these values for speculative execution. Signed-off-by: Nathan Lynch <nathanl@linux.ibm.com> Reported-by: Breno Leitao <leitao@debian.org> Reviewed-by: Breno Leitao <leitao@debian.org> Signed-off-by: Michael Ellerman <mpe@ellerman.id.au> Link: https://msgid.link/20240530-sys_rtas-nargs-nret-v1-1-129acddd4d89@linux.ibm.com
1 parent d5d1a1a commit 0974d03

1 file changed

Lines changed: 4 additions & 0 deletions

File tree

arch/powerpc/kernel/rtas.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include <linux/lockdep.h>
2020
#include <linux/memblock.h>
2121
#include <linux/mutex.h>
22+
#include <linux/nospec.h>
2223
#include <linux/of.h>
2324
#include <linux/of_fdt.h>
2425
#include <linux/reboot.h>
@@ -1916,6 +1917,9 @@ SYSCALL_DEFINE1(rtas, struct rtas_args __user *, uargs)
19161917
|| nargs + nret > ARRAY_SIZE(args.args))
19171918
return -EINVAL;
19181919

1920+
nargs = array_index_nospec(nargs, ARRAY_SIZE(args.args));
1921+
nret = array_index_nospec(nret, ARRAY_SIZE(args.args) - nargs);
1922+
19191923
/* Copy in args. */
19201924
if (copy_from_user(args.args, uargs->args,
19211925
nargs * sizeof(rtas_arg_t)) != 0)

0 commit comments

Comments
 (0)