linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 5.10.y v2] Revert "arm64: Stash shadow stack pointer in the task struct on interrupt"
@ 2024-02-19 13:21 Xiang Yang
  2024-02-19 16:57 ` Ard Biesheuvel
  2024-02-20 15:31 ` Patch "Revert "arm64: Stash shadow stack pointer in the task struct on interrupt"" has been added to the 5.10-stable tree gregkh
  0 siblings, 2 replies; 4+ messages in thread
From: Xiang Yang @ 2024-02-19 13:21 UTC (permalink / raw)
  To: ardb, mark.rutland, catalin.marinas, will
  Cc: keescook, linux-arm-kernel, stable, gregkh, xiangyang3,
	xiujianfeng, liaochang1

This reverts commit 3f225f29c69c13ce1cbdb1d607a42efeef080056.

The shadow call stack for irq now is stored in current task's thread info
in irq_stack_entry. There is a possibility that we have some soft irqs
pending at the end of hard irq, and when we process softirq with the irq
enabled, irq_stack_entry will enter again and overwrite the shadow call
stack whitch stored in current task's thread info, leading to the
incorrect shadow call stack restoration for the first entry of the hard
IRQ, then the system end up with a panic.

task A                               |  task A
-------------------------------------+------------------------------------
el1_irq        //irq1 enter          |
  irq_handler  //save scs_sp1        |
    gic_handle_irq                   |
    irq_exit                         |
      __do_softirq                   |
                                     | el1_irq         //irq2 enter
                                     |   irq_handler   //save scs_sp2
                                     |                 //overwrite scs_sp1
                                     |   ...
                                     |   irq_stack_exit //restore scs_sp2
  irq_stack_exit //restore wrong     |
                 //scs_sp2           |

So revert this commit to fix it.

Fixes: 3f225f29c69c ("arm64: Stash shadow stack pointer in the task struct on interrupt")

Signed-off-by: Xiang Yang <xiangyang3@huawei.com>
---
 arch/arm64/kernel/entry.S | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/arch/arm64/kernel/entry.S b/arch/arm64/kernel/entry.S
index a94acea770c7..020a455824be 100644
--- a/arch/arm64/kernel/entry.S
+++ b/arch/arm64/kernel/entry.S
@@ -431,7 +431,9 @@ SYM_CODE_END(__swpan_exit_el0)
 
 	.macro	irq_stack_entry
 	mov	x19, sp			// preserve the original sp
-	scs_save tsk			// preserve the original shadow stack
+#ifdef CONFIG_SHADOW_CALL_STACK
+	mov	x24, scs_sp		// preserve the original shadow stack
+#endif
 
 	/*
 	 * Compare sp with the base of the task stack.
@@ -465,7 +467,9 @@ SYM_CODE_END(__swpan_exit_el0)
 	 */
 	.macro	irq_stack_exit
 	mov	sp, x19
-	scs_load_current
+#ifdef CONFIG_SHADOW_CALL_STACK
+	mov	scs_sp, x24
+#endif
 	.endm
 
 /* GPRs used by entry code */
-- 
2.34.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH 5.10.y v2] Revert "arm64: Stash shadow stack pointer in the task struct on interrupt"
  2024-02-19 13:21 [PATCH 5.10.y v2] Revert "arm64: Stash shadow stack pointer in the task struct on interrupt" Xiang Yang
@ 2024-02-19 16:57 ` Ard Biesheuvel
  2024-02-20 15:31   ` Greg KH
  2024-02-20 15:31 ` Patch "Revert "arm64: Stash shadow stack pointer in the task struct on interrupt"" has been added to the 5.10-stable tree gregkh
  1 sibling, 1 reply; 4+ messages in thread
From: Ard Biesheuvel @ 2024-02-19 16:57 UTC (permalink / raw)
  To: Xiang Yang
  Cc: mark.rutland, catalin.marinas, will, keescook, linux-arm-kernel,
	stable, gregkh, xiujianfeng, liaochang1

On Mon, 19 Feb 2024 at 14:24, Xiang Yang <xiangyang3@huawei.com> wrote:
>
> This reverts commit 3f225f29c69c13ce1cbdb1d607a42efeef080056.
>
> The shadow call stack for irq now is stored in current task's thread info
> in irq_stack_entry. There is a possibility that we have some soft irqs
> pending at the end of hard irq, and when we process softirq with the irq
> enabled, irq_stack_entry will enter again and overwrite the shadow call
> stack whitch stored in current task's thread info, leading to the
> incorrect shadow call stack restoration for the first entry of the hard
> IRQ, then the system end up with a panic.
>
> task A                               |  task A
> -------------------------------------+------------------------------------
> el1_irq        //irq1 enter          |
>   irq_handler  //save scs_sp1        |
>     gic_handle_irq                   |
>     irq_exit                         |
>       __do_softirq                   |
>                                      | el1_irq         //irq2 enter
>                                      |   irq_handler   //save scs_sp2
>                                      |                 //overwrite scs_sp1
>                                      |   ...
>                                      |   irq_stack_exit //restore scs_sp2
>   irq_stack_exit //restore wrong     |
>                  //scs_sp2           |
>
> So revert this commit to fix it.
>
> Fixes: 3f225f29c69c ("arm64: Stash shadow stack pointer in the task struct on interrupt")
>
> Signed-off-by: Xiang Yang <xiangyang3@huawei.com>

Acked-by: Ard Biesheuvel <ardb@kernel.org>



> ---
>  arch/arm64/kernel/entry.S | 8 ++++++--
>  1 file changed, 6 insertions(+), 2 deletions(-)
>
> diff --git a/arch/arm64/kernel/entry.S b/arch/arm64/kernel/entry.S
> index a94acea770c7..020a455824be 100644
> --- a/arch/arm64/kernel/entry.S
> +++ b/arch/arm64/kernel/entry.S
> @@ -431,7 +431,9 @@ SYM_CODE_END(__swpan_exit_el0)
>
>         .macro  irq_stack_entry
>         mov     x19, sp                 // preserve the original sp
> -       scs_save tsk                    // preserve the original shadow stack
> +#ifdef CONFIG_SHADOW_CALL_STACK
> +       mov     x24, scs_sp             // preserve the original shadow stack
> +#endif
>
>         /*
>          * Compare sp with the base of the task stack.
> @@ -465,7 +467,9 @@ SYM_CODE_END(__swpan_exit_el0)
>          */
>         .macro  irq_stack_exit
>         mov     sp, x19
> -       scs_load_current
> +#ifdef CONFIG_SHADOW_CALL_STACK
> +       mov     scs_sp, x24
> +#endif
>         .endm
>
>  /* GPRs used by entry code */
> --
> 2.34.1
>

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Patch "Revert "arm64: Stash shadow stack pointer in the task struct on interrupt"" has been added to the 5.10-stable tree
  2024-02-19 13:21 [PATCH 5.10.y v2] Revert "arm64: Stash shadow stack pointer in the task struct on interrupt" Xiang Yang
  2024-02-19 16:57 ` Ard Biesheuvel
@ 2024-02-20 15:31 ` gregkh
  1 sibling, 0 replies; 4+ messages in thread
From: gregkh @ 2024-02-20 15:31 UTC (permalink / raw)
  To: ardb, catalin.marinas, gregkh, keescook, liaochang1,
	linux-arm-kernel, mark.rutland, will, xiangyang3, xiujianfeng
  Cc: stable-commits


This is a note to let you know that I've just added the patch titled

    Revert "arm64: Stash shadow stack pointer in the task struct on interrupt"

to the 5.10-stable tree which can be found at:
    http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary

The filename of the patch is:
     revert-arm64-stash-shadow-stack-pointer-in-the-task-struct-on-interrupt.patch
and it can be found in the queue-5.10 subdirectory.

If you, or anyone else, feels it should not be added to the stable tree,
please let <stable@vger.kernel.org> know about it.


From xiangyang3@huawei.com  Tue Feb 20 16:30:54 2024
From: Xiang Yang <xiangyang3@huawei.com>
Date: Mon, 19 Feb 2024 21:21:53 +0800
Subject: Revert "arm64: Stash shadow stack pointer in the task struct on interrupt"
To: <ardb@kernel.org>, <mark.rutland@arm.com>, <catalin.marinas@arm.com>, <will@kernel.org>
Cc: <keescook@chromium.org>, <linux-arm-kernel@lists.infradead.org>, <stable@vger.kernel.org>, <gregkh@linuxfoundation.org>, <xiangyang3@huawei.com>, <xiujianfeng@huawei.com>, <liaochang1@huawei.com>
Message-ID: <20240219132153.378265-1-xiangyang3@huawei.com>


This reverts commit 3f225f29c69c13ce1cbdb1d607a42efeef080056 which is
commit 59b37fe52f49955791a460752c37145f1afdcad1 upstream.

The shadow call stack for irq now is stored in current task's thread info
in irq_stack_entry. There is a possibility that we have some soft irqs
pending at the end of hard irq, and when we process softirq with the irq
enabled, irq_stack_entry will enter again and overwrite the shadow call
stack whitch stored in current task's thread info, leading to the
incorrect shadow call stack restoration for the first entry of the hard
IRQ, then the system end up with a panic.

task A                               |  task A
-------------------------------------+------------------------------------
el1_irq        //irq1 enter          |
  irq_handler  //save scs_sp1        |
    gic_handle_irq                   |
    irq_exit                         |
      __do_softirq                   |
                                     | el1_irq         //irq2 enter
                                     |   irq_handler   //save scs_sp2
                                     |                 //overwrite scs_sp1
                                     |   ...
                                     |   irq_stack_exit //restore scs_sp2
  irq_stack_exit //restore wrong     |
                 //scs_sp2           |

So revert this commit to fix it.

Fixes: 3f225f29c69c ("arm64: Stash shadow stack pointer in the task struct on interrupt")
Signed-off-by: Xiang Yang <xiangyang3@huawei.com>
Acked-by: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
 arch/arm64/kernel/entry.S |    8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

--- a/arch/arm64/kernel/entry.S
+++ b/arch/arm64/kernel/entry.S
@@ -431,7 +431,9 @@ SYM_CODE_END(__swpan_exit_el0)
 
 	.macro	irq_stack_entry
 	mov	x19, sp			// preserve the original sp
-	scs_save tsk			// preserve the original shadow stack
+#ifdef CONFIG_SHADOW_CALL_STACK
+	mov	x24, scs_sp		// preserve the original shadow stack
+#endif
 
 	/*
 	 * Compare sp with the base of the task stack.
@@ -465,7 +467,9 @@ SYM_CODE_END(__swpan_exit_el0)
 	 */
 	.macro	irq_stack_exit
 	mov	sp, x19
-	scs_load_current
+#ifdef CONFIG_SHADOW_CALL_STACK
+	mov	scs_sp, x24
+#endif
 	.endm
 
 /* GPRs used by entry code */


Patches currently in stable-queue which might be from xiangyang3@huawei.com are

queue-5.10/revert-arm64-stash-shadow-stack-pointer-in-the-task-struct-on-interrupt.patch

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH 5.10.y v2] Revert "arm64: Stash shadow stack pointer in the task struct on interrupt"
  2024-02-19 16:57 ` Ard Biesheuvel
@ 2024-02-20 15:31   ` Greg KH
  0 siblings, 0 replies; 4+ messages in thread
From: Greg KH @ 2024-02-20 15:31 UTC (permalink / raw)
  To: Ard Biesheuvel
  Cc: Xiang Yang, mark.rutland, catalin.marinas, will, keescook,
	linux-arm-kernel, stable, xiujianfeng, liaochang1

On Mon, Feb 19, 2024 at 05:57:07PM +0100, Ard Biesheuvel wrote:
> On Mon, 19 Feb 2024 at 14:24, Xiang Yang <xiangyang3@huawei.com> wrote:
> >
> > This reverts commit 3f225f29c69c13ce1cbdb1d607a42efeef080056.
> >
> > The shadow call stack for irq now is stored in current task's thread info
> > in irq_stack_entry. There is a possibility that we have some soft irqs
> > pending at the end of hard irq, and when we process softirq with the irq
> > enabled, irq_stack_entry will enter again and overwrite the shadow call
> > stack whitch stored in current task's thread info, leading to the
> > incorrect shadow call stack restoration for the first entry of the hard
> > IRQ, then the system end up with a panic.
> >
> > task A                               |  task A
> > -------------------------------------+------------------------------------
> > el1_irq        //irq1 enter          |
> >   irq_handler  //save scs_sp1        |
> >     gic_handle_irq                   |
> >     irq_exit                         |
> >       __do_softirq                   |
> >                                      | el1_irq         //irq2 enter
> >                                      |   irq_handler   //save scs_sp2
> >                                      |                 //overwrite scs_sp1
> >                                      |   ...
> >                                      |   irq_stack_exit //restore scs_sp2
> >   irq_stack_exit //restore wrong     |
> >                  //scs_sp2           |
> >
> > So revert this commit to fix it.
> >
> > Fixes: 3f225f29c69c ("arm64: Stash shadow stack pointer in the task struct on interrupt")
> >
> > Signed-off-by: Xiang Yang <xiangyang3@huawei.com>
> 
> Acked-by: Ard Biesheuvel <ardb@kernel.org>

Now queued up, thanks.

greg k-h

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

end of thread, other threads:[~2024-02-20 15:32 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-02-19 13:21 [PATCH 5.10.y v2] Revert "arm64: Stash shadow stack pointer in the task struct on interrupt" Xiang Yang
2024-02-19 16:57 ` Ard Biesheuvel
2024-02-20 15:31   ` Greg KH
2024-02-20 15:31 ` Patch "Revert "arm64: Stash shadow stack pointer in the task struct on interrupt"" has been added to the 5.10-stable tree gregkh

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