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 A100DC54EBC for ; Tue, 10 Jan 2023 14:56:51 +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=VFCwXPEZXw0pSGJAalu/5aKayiQI0z1bTIKCorTGyp0=; b=LMXC3c9Qs2G59J sl93xAYAcDZo4jMN+SHSdK+qsZmZu3SIqYpyZA+GO5kcW/KrGQ3WUwTDgb/CWD/KaZaQ7PvRJLkoX FpNHwmXf4ZaOAkqtJLrIfiY7sfJDJmvxJlg0wjM7s4bzxmMOCjMsMbN3aL4WKG6sCvL17TiGiT+KN NgzreVKa1U8ftIM8qDrzDOIN1sOjr5Ri/a3P+LrjJFBxc1ZkqmcRUoE3C2+A4+vrJCuDEjAReVg7p 73kIRNQKIaE7zTu6F2dVPitFZSDwY4vx9YcDWT6AtjAdaLulKQUBFy139W4ueSrQu9TO1L59hzJzh q/nXJHYV9KaNzzZWJCpQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pFG2d-007QP7-8o; Tue, 10 Jan 2023 14:55:55 +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 1pFG2Z-007QMQ-8P for linux-arm-kernel@lists.infradead.org; Tue, 10 Jan 2023 14:55:53 +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 770962F4; Tue, 10 Jan 2023 06:56:27 -0800 (PST) Received: from FVFF77S0Q05N (unknown [10.57.46.95]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 53E783F67D; Tue, 10 Jan 2023 06:55:44 -0800 (PST) Date: Tue, 10 Jan 2023 14:55:31 +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 1/2] arm64: Always load shadow stack pointer directly from the task struct Message-ID: References: <20230109174800.3286265-1-ardb@kernel.org> <20230109174800.3286265-2-ardb@kernel.org> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20230109174800.3286265-2-ardb@kernel.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230110_065551_361919_53DB8FDF X-CRM114-Status: GOOD ( 17.56 ) 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:47:59PM +0100, Ard Biesheuvel wrote: > All occurrences of the scs_load macro load the value of the shadow call > stack pointer from the task which is current at that point. So instead > of taking a task struct register argument in the scs_load macro to > specify the task struct to load from, let's always reference the current > task directly. This should make it much harder to exploit any > instruction sequences reloading the shadow call stack pointer register > from memory. > > Signed-off-by: Ard Biesheuvel Makes sense to me. Acked-by: Mark Rutland Mark. > --- > arch/arm64/include/asm/scs.h | 7 ++++--- > arch/arm64/kernel/entry.S | 4 ++-- > arch/arm64/kernel/head.S | 2 +- > 3 files changed, 7 insertions(+), 6 deletions(-) > > diff --git a/arch/arm64/include/asm/scs.h b/arch/arm64/include/asm/scs.h > index ff7da1268a52ab79..13df982a080805e6 100644 > --- a/arch/arm64/include/asm/scs.h > +++ b/arch/arm64/include/asm/scs.h > @@ -10,15 +10,16 @@ > #ifdef CONFIG_SHADOW_CALL_STACK > scs_sp .req x18 > > - .macro scs_load tsk > - ldr scs_sp, [\tsk, #TSK_TI_SCS_SP] > + .macro scs_load_current > + get_current_task scs_sp > + ldr scs_sp, [scs_sp, #TSK_TI_SCS_SP] > .endm > > .macro scs_save tsk > str scs_sp, [\tsk, #TSK_TI_SCS_SP] > .endm > #else > - .macro scs_load tsk > + .macro scs_load_current > .endm > > .macro scs_save tsk > diff --git a/arch/arm64/kernel/entry.S b/arch/arm64/kernel/entry.S > index 11cb99c4d298784d..546f7773238ea45d 100644 > --- a/arch/arm64/kernel/entry.S > +++ b/arch/arm64/kernel/entry.S > @@ -275,7 +275,7 @@ alternative_if ARM64_HAS_ADDRESS_AUTH > alternative_else_nop_endif > 1: > > - scs_load tsk > + scs_load_current > .else > add x21, sp, #PT_REGS_SIZE > get_current_task tsk > @@ -848,7 +848,7 @@ SYM_FUNC_START(cpu_switch_to) > msr sp_el0, x1 > ptrauth_keys_install_kernel x1, x8, x9, x10 > scs_save x0 > - scs_load x1 > + scs_load_current > ret > SYM_FUNC_END(cpu_switch_to) > NOKPROBE(cpu_switch_to) > diff --git a/arch/arm64/kernel/head.S b/arch/arm64/kernel/head.S > index 952e17bd1c0b4f91..b9c1a506798ea315 100644 > --- a/arch/arm64/kernel/head.S > +++ b/arch/arm64/kernel/head.S > @@ -404,7 +404,7 @@ SYM_FUNC_END(create_kernel_mapping) > stp xzr, xzr, [sp, #S_STACKFRAME] > add x29, sp, #S_STACKFRAME > > - scs_load \tsk > + scs_load_current > > adr_l \tmp1, __per_cpu_offset > ldr w\tmp2, [\tsk, #TSK_TI_CPU] > -- > 2.39.0 > _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel