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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id CD460C433EF for ; Wed, 13 Oct 2021 15:27:01 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 9E9A760F21 for ; Wed, 13 Oct 2021 15:27:01 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 9E9A760F21 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.infradead.org 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:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=njGh8/QEtPAO9qtt52r7DIXLG0VzceklzIZmEXxGbMM=; b=gtIfsmV8dIzsAA nYYIpQNZHRWAgqeALMiyvqWCLKl3u8WTCWsJyC3UJTgLoPxfen3CrFk6EE8TqIAcIgdiAQlCXkomT jnWDrjIrnXHg2s7X08bryb/ZhjjklRpj/WPHT5RbOSXdY4apDp+bpkVCc6kSIfAiC/EWD76mgRjFY 7idZlGRxFgkF5ErpF4/BmLKsBzKhyrxcT3VqE1qSxdsnHO042FDX/KooU2jwp67HGT5iA69aATC52 7TKtmRx0laZjAQVqAHOOJ41/whZo2iCRi9g1KvdZ1jcIq2YcXWoCnIeCsfliMD8BrFcEnn6c+Jd1t YAHbLEDARAdTxY0ufvlA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mag7j-00HLJQ-1w; Wed, 13 Oct 2021 15:24:55 +0000 Received: from mail.kernel.org ([198.145.29.99]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mag60-00HKi5-0w for linux-arm-kernel@lists.infradead.org; Wed, 13 Oct 2021 15:23:09 +0000 Received: by mail.kernel.org (Postfix) with ESMTPSA id 51BC261151; Wed, 13 Oct 2021 15:23:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1634138587; bh=WAUPlo+6rkxh20C/Rd3ch6Ny8CbqlBcV9dvmBueVhJc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=rydVf2ZGqPUhh8gXLX+BLmUJKyj2OPvFwDS5Xg0Htl5WbXoml3sP3XUgRJpSTQsPj D5tR9TZx5SQaIMp25PCPU5LkOdLbnrMjzaE+8hPT2Up6VvDWVrTl7epVfraOqDhu8d bvPnxIirWIralEu7PksYEN1BANaHw4Tv5W/L3L1/9wYW1/y+rT46III0OW/1PO/OPs YhnAao6Raji9ay6merftk6FkoxwF7xMWlnTWbZ0eZrq1HLicSxP5CP3HQLs/qdLgsv 5XrX14PTKJTIvzSK+1t8AoBI8w66mkfgkCqiCfLuwKSrFCxRp1lQbO+5BLuIW/8rTk nUzVagDxFEbLw== From: Ard Biesheuvel To: linux-arm-kernel@lists.infradead.org Cc: linux-hardening@vger.kernel.org, mark.rutland@arm.com, catalin.marinas@arm.com, will@kernel.org, Ard Biesheuvel Subject: [RFC PATCH 7/9] arm64: assembler: add unwind annotations to frame push/pop macros Date: Wed, 13 Oct 2021 17:22:41 +0200 Message-Id: <20211013152243.2216899-8-ardb@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20211013152243.2216899-1-ardb@kernel.org> References: <20211013152243.2216899-1-ardb@kernel.org> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=4153; h=from:subject; bh=WAUPlo+6rkxh20C/Rd3ch6Ny8CbqlBcV9dvmBueVhJc=; b=owEB7QES/pANAwAKAcNPIjmS2Y8kAcsmYgBhZvm+f+lPsOaLzrEcFZ+XSixPrrCB/OfJN0rxMhvG 39kq5QqJAbMEAAEKAB0WIQT72WJ8QGnJQhU3VynDTyI5ktmPJAUCYWb5vgAKCRDDTyI5ktmPJHBfC/ 9OkG6Igq017oaBMCAEjx3/AiCKQMrbpzgwdfz9dG43g4m6sv+kOaGkVS7e0mTgzkY6WMprx8oK7Pty 7dexFNDKaeVKwgsfOQDTG4aw9IPmYin6BBoohz0Aen3JnkNUXSmHZI2hftinPr1JHJNciqi04zCCAw gQiXFE47ZTwkqofmsA78KbS1e8i/KQA5PYlBfthuXl0HTp5pvHoU79KG/rdNU+vN57zlfGOZlKCUNb TG6Nn6hFDYjcMIP68RMdHIwXTJchgW/xqNFrlbHMQbrFnysJlDzVj3SsundzCmXCOeSs0fH6ffHGRk hYNKNI46VoadcwjttB4ULrjROO6yR25+lZnBlGFurUgpe0lRiiNf0dH2KpT5gcSiG+lu63xv/F38U9 QaYut8C4ryl+BsMDCAA2s4Mjs/5ZnO7jGBlVcN31/DrIAcm+BRtt0Ed8N9O2QsIGTGW/nW78gMM3tL tIo8K0EQqYUWAmAILNS+PZDeqoc08/XTkmW+yROezSU3E= X-Developer-Key: i=ardb@kernel.org; a=openpgp; fpr=F43D03328115A198C90016883D200E9CA6329909 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211013_082308_129173_9351D3AF X-CRM114-Status: GOOD ( 10.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 In order to ensure that we can unwind from hand rolled assembly routines, decorate the frame push/pop helper macros that are used by non-leaf assembler routines with the appropriate annotations. Signed-off-by: Ard Biesheuvel --- arch/arm64/include/asm/assembler.h | 26 +++++++++++++++++++- arch/arm64/include/asm/linkage.h | 16 +++++++++++- 2 files changed, 40 insertions(+), 2 deletions(-) diff --git a/arch/arm64/include/asm/assembler.h b/arch/arm64/include/asm/assembler.h index ceed84ac4005..cebb6c8c489b 100644 --- a/arch/arm64/include/asm/assembler.h +++ b/arch/arm64/include/asm/assembler.h @@ -664,9 +664,10 @@ alternative_endif * the new value of sp. Add @extra bytes of stack space * for locals. */ - .macro frame_push, regcount:req, extra + .macro frame_push, regcount:req, extra=0 #ifdef CONFIG_ARM64_PTR_AUTH_KERNEL paciasp + .cfi_negate_ra_state #endif __frame st, \regcount, \extra .endm @@ -681,14 +682,29 @@ alternative_endif __frame ld #ifdef CONFIG_ARM64_PTR_AUTH_KERNEL autiasp + .cfi_negate_ra_state #endif .endm .macro __frame_regs, reg1, reg2, op, num .if .Lframe_regcount == \num \op\()r \reg1, [sp, #(\num + 1) * 8] + .ifc \op, st + .cfi_offset \reg1, -.Lframe_cfa_offset + .set .Lframe_cfa_offset, .Lframe_cfa_offset - 8 + .else + .cfi_restore \reg1 + .endif .elseif .Lframe_regcount > \num \op\()p \reg1, \reg2, [sp, #(\num + 1) * 8] + .ifc \op, st + .cfi_offset \reg1, -.Lframe_cfa_offset + .cfi_offset \reg2, -.Lframe_cfa_offset + 8 + .set .Lframe_cfa_offset, .Lframe_cfa_offset - 16 + .else + .cfi_restore \reg1 + .cfi_restore \reg2 + .endif .endif .endm @@ -708,7 +724,12 @@ alternative_endif .set .Lframe_regcount, \regcount .set .Lframe_extra, \extra .set .Lframe_local_offset, ((\regcount + 3) / 2) * 16 + .set .Lframe_cfa_offset, .Lframe_local_offset + .Lframe_extra stp x29, x30, [sp, #-.Lframe_local_offset - .Lframe_extra]! + .cfi_def_cfa_offset .Lframe_cfa_offset + .cfi_offset x29, -.Lframe_cfa_offset + .cfi_offset x30, -.Lframe_cfa_offset + 8 + .set .Lframe_cfa_offset, .Lframe_cfa_offset - 16 mov x29, sp .endif @@ -723,6 +744,9 @@ alternative_endif .error "frame_push/frame_pop may not be nested" .endif ldp x29, x30, [sp], #.Lframe_local_offset + .Lframe_extra + .cfi_restore x29 + .cfi_restore x30 + .cfi_def_cfa_offset 0 .set .Lframe_regcount, -1 .endif .endm diff --git a/arch/arm64/include/asm/linkage.h b/arch/arm64/include/asm/linkage.h index 9906541a6861..d984a6750b01 100644 --- a/arch/arm64/include/asm/linkage.h +++ b/arch/arm64/include/asm/linkage.h @@ -4,6 +4,9 @@ #define __ALIGN .align 2 #define __ALIGN_STR ".align 2" +#define SYM_FUNC_CFI_START .cfi_startproc ; +#define SYM_FUNC_CFI_END .cfi_endproc ; + #if defined(CONFIG_ARM64_BTI_KERNEL) && defined(__aarch64__) /* @@ -12,6 +15,9 @@ * instead. */ #define BTI_C hint 34 ; +#else +#define BTI_C +#endif /* * When using in-kernel BTI we need to ensure that PCS-conformant assembly @@ -20,29 +26,37 @@ */ #define SYM_FUNC_START(name) \ SYM_START(name, SYM_L_GLOBAL, SYM_A_ALIGN) \ + SYM_FUNC_CFI_START \ BTI_C #define SYM_FUNC_START_NOALIGN(name) \ SYM_START(name, SYM_L_GLOBAL, SYM_A_NONE) \ + SYM_FUNC_CFI_START \ BTI_C #define SYM_FUNC_START_LOCAL(name) \ SYM_START(name, SYM_L_LOCAL, SYM_A_ALIGN) \ + SYM_FUNC_CFI_START \ BTI_C #define SYM_FUNC_START_LOCAL_NOALIGN(name) \ SYM_START(name, SYM_L_LOCAL, SYM_A_NONE) \ + SYM_FUNC_CFI_START \ BTI_C #define SYM_FUNC_START_WEAK(name) \ SYM_START(name, SYM_L_WEAK, SYM_A_ALIGN) \ + SYM_FUNC_CFI_START \ BTI_C #define SYM_FUNC_START_WEAK_NOALIGN(name) \ SYM_START(name, SYM_L_WEAK, SYM_A_NONE) \ + SYM_FUNC_CFI_START \ BTI_C -#endif +#define SYM_FUNC_END(name) \ + SYM_FUNC_CFI_END \ + SYM_END(name, SYM_T_FUNC) /* * Annotate a function as position independent, i.e., safe to be called before -- 2.30.2 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel