From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 379D3C46467 for ; Tue, 10 Jan 2023 14:58:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=RnCHepRkVwbkEzdSds7dqli9//NGZgkpDM+Hcsu8FzY=; b=rx3/fiMPIXut/F AJoAzDGyB50gkkHTYdIovkz3s3NHqjsMyYMd7aO1UHd4U5U4Cih6y4CMJXM24arf686b8h1DGICW8 M/Qvi7WnyQ5hYupe25Vq5dj4vlT/3KPLsSgKKwebrTh0z5rhqsHMhB9MJorlVxE2YKGCKLQ/0rq/J ept9jd7erBQt4Gb8SKCLu9yygxmX5S4eSRGlSTcjNglMruHESsJYPpd9Nc2leI5dnqnjEvDjGEt+L s/peW3cW55ZNfS93SU8f2cvzOhYOX2H+4gbruhZeuJmRV5SVWId2+S5tfcJWMM8GcSNWSdbl3DN9l M126zqH2MOHoelUIUpnQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pFG4O-007Qsh-3r; Tue, 10 Jan 2023 14:57:44 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pFG4K-007Qrn-Oo for linux-arm-kernel@lists.infradead.org; Tue, 10 Jan 2023 14:57:42 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id C8A722F4; Tue, 10 Jan 2023 06:58:18 -0800 (PST) Received: from FVFF77S0Q05N (unknown [10.57.46.95]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id B28893F67D; Tue, 10 Jan 2023 06:57:35 -0800 (PST) Date: Tue, 10 Jan 2023 14:57:33 +0000 From: Mark Rutland To: Ard Biesheuvel Cc: linux-arm-kernel@lists.infradead.org, will@kernel.org, catalin.marinas@arm.com, Sami Tolvanen , Kees Cook Subject: Re: [PATCH v2 2/2] arm64: Stash shadow stack pointer in the task struct on interrupt Message-ID: References: <20230109174800.3286265-1-ardb@kernel.org> <20230109174800.3286265-3-ardb@kernel.org> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20230109174800.3286265-3-ardb@kernel.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230110_065740_873152_5DB4FA5D X-CRM114-Status: GOOD ( 20.85 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.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 Acked-by: Mark Rutland 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