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 A644CC4332F for ; Fri, 9 Dec 2022 15:22:37 +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: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=LUKGX801dlmIcN0h0YssWP3m/68I1tWZmNz7sa6YgLk=; b=JhT6dQwB+U3hW1 PZEAKxBfSbY+UEWO50mTvrtZi0DsqgLVGa9PIOeW3J9JBBGXYIuZ2YMuJzkIbrWq4qF02pcVaWGUu DxP9rD9db/OGczK2IdfSzDFNU5Y5/Wunx5V04VMho6SBeU0r5lAPo6LudIRoCwom6WrosET/WBQLX gvm7KCZo6gpV/uNGlsyThtNRqvRa4sbb2R8aBUn91GbW3SZftqTWvLzDviWhsL5lY7cxa2j5bng5l drgp9WebYDzi1oXniKHb8ZOLRRi8GtRQTovsJYkJeb7sasS5Br2J33Sl7MoOVnIK9H8cRoghIwr7j ekrCnq1K/QlpOMDtmKPg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1p3fC1-008wNe-RW; Fri, 09 Dec 2022 15:21:41 +0000 Received: from ams.source.kernel.org ([2604:1380:4601:e00::1]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1p3fBT-008wDy-UI for linux-arm-kernel@lists.infradead.org; Fri, 09 Dec 2022 15:21:11 +0000 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id A3E1BB82886; Fri, 9 Dec 2022 15:21:06 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id BCF92C43398; Fri, 9 Dec 2022 15:21:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1670599265; bh=MuAqbMt06XF1iJceDCzI425FTyqaSZ5kb9rVjh9KUm8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=e4LxfsOfk8FSqnuh4b759Q6i/C0qShCFfnUanEWyr9C79Hg9bJ1jFcWkxP0Yma/EX Vqu1tMRg3HGiBcBkfBjSO/2oHJKzOKtuiGbmJacpzHrQOpZi35SG6GFJHrtemOPytO 2G6SujFiAjitGYhbBMkHosN6K3xAaFkJ8wDa4sfGEGcRQqiWvdqFMC+w6FPyKTKUET QQXZrVTZ7zOnfMlEFXER4V7h9FzsMJ3lVJ16G6l0mz6O6IRW+CmZrBi7ep3YX9d2GT Woz2taYAhqF+kInSCFRQk75HFnUu0p63YH/Q3z6IqCg10PvpyfMuw6lpMJHCbtWd6X 2E6KWiojZ66bg== From: Ard Biesheuvel To: linux-arm-kernel@lists.infradead.org Cc: Ard Biesheuvel , Marc Zyngier , Will Deacon , Mark Rutland , Kees Cook , Catalin Marinas , Mark Brown Subject: [PATCH v3 3/4] arm64: ftrace: Preserve original link register value in ftrace_regs Date: Fri, 9 Dec 2022 16:20:47 +0100 Message-Id: <20221209152048.3517080-4-ardb@kernel.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20221209152048.3517080-1-ardb@kernel.org> References: <20221209152048.3517080-1-ardb@kernel.org> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2800; i=ardb@kernel.org; h=from:subject; bh=MuAqbMt06XF1iJceDCzI425FTyqaSZ5kb9rVjh9KUm8=; b=owEB7QES/pANAwAKAcNPIjmS2Y8kAcsmYgBjk1JN0ae0fdChGD/DbFO22B9sFpJ8ohHbw0F8aKnU 8c+9g8CJAbMEAAEKAB0WIQT72WJ8QGnJQhU3VynDTyI5ktmPJAUCY5NSTQAKCRDDTyI5ktmPJB6YC/ 9r6frmWjotANI+43Ki/rxBLsKwHZv2ZWgassGBw/IPSQUuXSQturUcmAnsfQvAPJOpd7eIkhhQZT8E CNCGJH4BqMDWpUKZF5OzxSdqnhQubfhGUdmGiRArXcfxcXp15/E3kFJOCjxgB03kcey+NKlob1WFmJ L0JAw89gPkL5aJ599fYSeMm/Vn2X+iQP2Bnq12WXJE5BonCG2zmW5DIKF0Go+p+GSq+ZMZPmmFy8ae Lj4p5/Jeq7Eti91prP6yWr7uLEXb4g/KIWR7GR+oFpc5oinOSiSTXCyst3PqX4HUCUDLWE9r1ej2Aw YJ1PCiHwaDmRLHL+ZcMBtFL4Ao0RLE/XSFSTnUxQD97cmOhyy9am0nvVXTO4UOXz+dJFrhGzNXtPHP BjFZdO7NCKsaaEPYV99Xg/PIsSq1FNkv0yUTGQmyRGJgggRPaTuGht9TzSl0XenovlEMgvKhS83Qej P1NRBzFfsmVuFRxi5m+fiFS48IAUjPyrpUy1tEsTcjjNc= 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-20221209_072108_284540_CAEB8163 X-CRM114-Status: GOOD ( 16.92 ) 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 be able to add pointer authentication and/or shadow call stack support to the ftrace asm routines, it will need to reason about whether or not the callsite's return address was updated to point to return_to_handler(), as in this case, we want the authentication to occur there and not before returning to the call site. To make this a bit easier, preserve the value of register X9, which carries the callsite's LR value upon entry to ftrace_caller, so in a later patch, we can compare it to the callsite's effective LR upon return, and omit the authentication if the caller will be returning via return_to_handler(). Signed-off-by: Ard Biesheuvel --- arch/arm64/include/asm/ftrace.h | 2 +- arch/arm64/kernel/entry-ftrace.S | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/arch/arm64/include/asm/ftrace.h b/arch/arm64/include/asm/ftrace.h index 5664729800ae1c13..b07501645a74031a 100644 --- a/arch/arm64/include/asm/ftrace.h +++ b/arch/arm64/include/asm/ftrace.h @@ -86,7 +86,7 @@ struct ftrace_ops; struct ftrace_regs { /* x0 - x8 */ unsigned long regs[9]; - unsigned long __unused; + unsigned long orig_lr; // must follow ®s[8] unsigned long fp; unsigned long lr; diff --git a/arch/arm64/kernel/entry-ftrace.S b/arch/arm64/kernel/entry-ftrace.S index 30cc2a9d1757a6a7..bccd525241ab615d 100644 --- a/arch/arm64/kernel/entry-ftrace.S +++ b/arch/arm64/kernel/entry-ftrace.S @@ -42,12 +42,12 @@ SYM_CODE_START(ftrace_caller) /* Make room for ftrace regs, plus two frame records */ sub sp, sp, #(FREGS_SIZE + 32) - /* Save function arguments */ + /* Save function arguments and original callsite LR */ stp x0, x1, [sp, #FREGS_X0] stp x2, x3, [sp, #FREGS_X2] stp x4, x5, [sp, #FREGS_X4] stp x6, x7, [sp, #FREGS_X6] - str x8, [sp, #FREGS_X8] + stp x8, x9, [sp, #FREGS_X8] /* Save the callsite's FP, LR, SP */ str x29, [sp, #FREGS_FP] @@ -78,22 +78,22 @@ SYM_INNER_LABEL(ftrace_call, SYM_L_GLOBAL) * x19-x29 per the AAPCS, and we created frame records upon entry, so we need * to restore x0-x8, x29, and x30. */ - /* Restore function arguments */ + /* Restore function arguments and original callsite LR */ ldp x0, x1, [sp, #FREGS_X0] ldp x2, x3, [sp, #FREGS_X2] ldp x4, x5, [sp, #FREGS_X4] ldp x6, x7, [sp, #FREGS_X6] - ldr x8, [sp, #FREGS_X8] + ldp x8, x9, [sp, #FREGS_X8] /* Restore the callsite's FP, LR, PC */ ldr x29, [sp, #FREGS_FP] ldr x30, [sp, #FREGS_LR] - ldr x9, [sp, #FREGS_PC] + ldr x10, [sp, #FREGS_PC] /* Restore the callsite's SP */ add sp, sp, #FREGS_SIZE + 32 - ret x9 + ret x10 SYM_CODE_END(ftrace_caller) #else /* CONFIG_DYNAMIC_FTRACE_WITH_ARGS */ -- 2.35.1 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel