stable.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 5.10.y] powerpc/rtas: Prevent Spectre v1 gadget construction in sys_rtas()
@ 2025-04-11  2:26 Cliff Liu
  2025-04-13 16:46 ` Sasha Levin
  0 siblings, 1 reply; 2+ messages in thread
From: Cliff Liu @ 2025-04-11  2:26 UTC (permalink / raw)
  To: stable
  Cc: mpe, benh, paulus, leitao, nathanl, donghua.liu, Zhe.He,
	linuxppc-dev, linux-kernel

From: Nathan Lynch <nathanl@linux.ibm.com>

[ Upstream commit 0974d03eb479384466d828d65637814bee6b26d7 ]

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
Signed-off-by: Cliff Liu <donghua.liu@windriver.com>
Signed-off-by: He Zhe <Zhe.He@windriver.com>
---
Verified the powerpc build test.
---
 arch/powerpc/kernel/rtas.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/arch/powerpc/kernel/rtas.c b/arch/powerpc/kernel/rtas.c
index 5976a25c6264..a8299981798a 100644
--- a/arch/powerpc/kernel/rtas.c
+++ b/arch/powerpc/kernel/rtas.c
@@ -16,6 +16,7 @@
 #include <linux/capability.h>
 #include <linux/delay.h>
 #include <linux/cpu.h>
+#include <linux/nospec.h>
 #include <linux/sched.h>
 #include <linux/smp.h>
 #include <linux/completion.h>
@@ -1173,6 +1174,9 @@ SYSCALL_DEFINE1(rtas, struct rtas_args __user *, uargs)
 	    || nargs + nret > ARRAY_SIZE(args.args))
 		return -EINVAL;
 
+	nargs = array_index_nospec(nargs, ARRAY_SIZE(args.args));
+	nret = array_index_nospec(nret, ARRAY_SIZE(args.args) - nargs);
+
 	/* Copy in args. */
 	if (copy_from_user(args.args, uargs->args,
 			   nargs * sizeof(rtas_arg_t)) != 0)
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH 5.10.y] powerpc/rtas: Prevent Spectre v1 gadget construction in sys_rtas()
  2025-04-11  2:26 [PATCH 5.10.y] powerpc/rtas: Prevent Spectre v1 gadget construction in sys_rtas() Cliff Liu
@ 2025-04-13 16:46 ` Sasha Levin
  0 siblings, 0 replies; 2+ messages in thread
From: Sasha Levin @ 2025-04-13 16:46 UTC (permalink / raw)
  To: stable; +Cc: Cliff Liu, Sasha Levin

[ Sasha's backport helper bot ]

Hi,

✅ All tests passed successfully. No issues detected.
No action required from the submitter.

The upstream commit SHA1 provided is correct: 0974d03eb479384466d828d65637814bee6b26d7

WARNING: Author mismatch between patch and upstream commit:
Backport author: Cliff Liu<donghua.liu@windriver.com>
Commit author: Nathan Lynch<nathanl@linux.ibm.com>

Status in newer kernel trees:
6.14.y | Present (exact SHA1)
6.13.y | Present (exact SHA1)
6.12.y | Present (exact SHA1)
6.6.y | Not found
6.1.y | Not found
5.15.y | Not found

Note: The patch differs from the upstream commit:
---
1:  0974d03eb4793 ! 1:  4d5f35b16ee3f powerpc/rtas: Prevent Spectre v1 gadget construction in sys_rtas()
    @@ Metadata
      ## Commit message ##
         powerpc/rtas: Prevent Spectre v1 gadget construction in sys_rtas()
     
    +    [ Upstream commit 0974d03eb479384466d828d65637814bee6b26d7 ]
    +
         Smatch warns:
     
           arch/powerpc/kernel/rtas.c:1932 __do_sys_rtas() warn: potential
    @@ Commit message
         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
    +    Signed-off-by: Cliff Liu <donghua.liu@windriver.com>
    +    Signed-off-by: He Zhe <Zhe.He@windriver.com>
     
      ## arch/powerpc/kernel/rtas.c ##
     @@
    - #include <linux/lockdep.h>
    - #include <linux/memblock.h>
    - #include <linux/mutex.h>
    + #include <linux/capability.h>
    + #include <linux/delay.h>
    + #include <linux/cpu.h>
     +#include <linux/nospec.h>
    - #include <linux/of.h>
    - #include <linux/of_fdt.h>
    - #include <linux/reboot.h>
    + #include <linux/sched.h>
    + #include <linux/smp.h>
    + #include <linux/completion.h>
     @@ arch/powerpc/kernel/rtas.c: SYSCALL_DEFINE1(rtas, struct rtas_args __user *, uargs)
      	    || nargs + nret > ARRAY_SIZE(args.args))
      		return -EINVAL;
---

Results of testing on various branches:

| Branch                    | Patch Apply | Build Test |
|---------------------------|-------------|------------|
| stable/linux-5.10.y       |  Success    |  Success   |

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2025-04-13 16:46 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-04-11  2:26 [PATCH 5.10.y] powerpc/rtas: Prevent Spectre v1 gadget construction in sys_rtas() Cliff Liu
2025-04-13 16:46 ` Sasha Levin

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).