Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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

authored by

Nathan Lynch and committed by
Michael Ellerman
0974d03e d5d1a1a5

+4
+4
arch/powerpc/kernel/rtas.c
··· 19 19 #include <linux/lockdep.h> 20 20 #include <linux/memblock.h> 21 21 #include <linux/mutex.h> 22 + #include <linux/nospec.h> 22 23 #include <linux/of.h> 23 24 #include <linux/of_fdt.h> 24 25 #include <linux/reboot.h> ··· 1916 1915 || nret > ARRAY_SIZE(args.args) 1917 1916 || nargs + nret > ARRAY_SIZE(args.args)) 1918 1917 return -EINVAL; 1918 + 1919 + nargs = array_index_nospec(nargs, ARRAY_SIZE(args.args)); 1920 + nret = array_index_nospec(nret, ARRAY_SIZE(args.args) - nargs); 1919 1921 1920 1922 /* Copy in args. */ 1921 1923 if (copy_from_user(args.args, uargs->args,