From: Mark Rutland <mark.rutland@arm.com>
To: Ard Biesheuvel <ardb@kernel.org>
Cc: linux-arm-kernel@lists.infradead.org, will@kernel.org,
catalin.marinas@arm.com, Sami Tolvanen <samitolvanen@google.com>,
Kees Cook <keescook@chromium.org>
Subject: Re: [PATCH v2 2/2] arm64: Stash shadow stack pointer in the task struct on interrupt
Date: Tue, 10 Jan 2023 14:57:33 +0000 [thread overview]
Message-ID: <Y7183WGtZgvGzPOj@FVFF77S0Q05N> (raw)
In-Reply-To: <20230109174800.3286265-3-ardb@kernel.org>
On Mon, Jan 09, 2023 at 06:48:00PM +0100, Ard Biesheuvel wrote:
> Instead of reloading the shadow call stack pointer from the ordinary
> stack, which may be vulnerable to the kind of gadget based attacks
> shadow call stacks were designed to prevent, let's store a task's shadow
> call stack pointer in the task struct when switching to the shadow IRQ
> stack.
>
> Given that currently, the task_struct::scs_sp field is only used to
> preserve the shadow call stack pointer while a task is scheduled out or
> running in user space, reusing this field to preserve and restore it
> while running off the IRQ stack must be safe, as those occurrences are
> guaranteed to never overlap. (The stack switching logic only switches
> stacks when running from the task stack, and so the value being saved
> here always corresponds to the task mode shadow stack)
>
> While at it, fold a mov/add/mov sequence into a single add.
>
> Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
Acked-by: Mark Rutland <mark.rutland@arm.com>
Mark.
> ---
> arch/arm64/kernel/entry.S | 12 +++++-------
> 1 file changed, 5 insertions(+), 7 deletions(-)
>
> diff --git a/arch/arm64/kernel/entry.S b/arch/arm64/kernel/entry.S
> index 546f7773238ea45d..80d763e165fc5856 100644
> --- a/arch/arm64/kernel/entry.S
> +++ b/arch/arm64/kernel/entry.S
> @@ -876,19 +876,19 @@ NOKPROBE(ret_from_fork)
> */
> SYM_FUNC_START(call_on_irq_stack)
> #ifdef CONFIG_SHADOW_CALL_STACK
> - stp scs_sp, xzr, [sp, #-16]!
> + get_current_task x16
> + scs_save x16
> ldr_this_cpu scs_sp, irq_shadow_call_stack_ptr, x17
> #endif
> +
> /* Create a frame record to save our LR and SP (implicit in FP) */
> stp x29, x30, [sp, #-16]!
> mov x29, sp
>
> ldr_this_cpu x16, irq_stack_ptr, x17
> - mov x15, #IRQ_STACK_SIZE
> - add x16, x16, x15
>
> /* Move to the new stack and call the function there */
> - mov sp, x16
> + add sp, x16, #IRQ_STACK_SIZE
> blr x1
>
> /*
> @@ -897,9 +897,7 @@ SYM_FUNC_START(call_on_irq_stack)
> */
> mov sp, x29
> ldp x29, x30, [sp], #16
> -#ifdef CONFIG_SHADOW_CALL_STACK
> - ldp scs_sp, xzr, [sp], #16
> -#endif
> + scs_load_current
> ret
> SYM_FUNC_END(call_on_irq_stack)
> NOKPROBE(call_on_irq_stack)
> --
> 2.39.0
>
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
next prev parent reply other threads:[~2023-01-10 14:58 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-01-09 17:47 [PATCH v2 0/2] arm64: harden shadow call stack pointer handling Ard Biesheuvel
2023-01-09 17:47 ` [PATCH v2 1/2] arm64: Always load shadow stack pointer directly from the task struct Ard Biesheuvel
2023-01-10 14:55 ` Mark Rutland
2023-01-12 22:18 ` Kees Cook
2023-01-09 17:48 ` [PATCH v2 2/2] arm64: Stash shadow stack pointer in the task struct on interrupt Ard Biesheuvel
2023-01-10 14:57 ` Mark Rutland [this message]
2023-01-12 22:18 ` Kees Cook
2023-01-20 16:59 ` [PATCH v2 0/2] arm64: harden shadow call stack pointer handling Catalin Marinas
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=Y7183WGtZgvGzPOj@FVFF77S0Q05N \
--to=mark.rutland@arm.com \
--cc=ardb@kernel.org \
--cc=catalin.marinas@arm.com \
--cc=keescook@chromium.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=samitolvanen@google.com \
--cc=will@kernel.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