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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1EF68C433FE for ; Mon, 24 Jan 2022 17:49:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244435AbiAXRtX (ORCPT ); Mon, 24 Jan 2022 12:49:23 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56550 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244484AbiAXRtL (ORCPT ); Mon, 24 Jan 2022 12:49:11 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 32933C061744 for ; Mon, 24 Jan 2022 09:49:11 -0800 (PST) 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 dfw.source.kernel.org (Postfix) with ESMTPS id C36C760FDB for ; Mon, 24 Jan 2022 17:49:10 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5CEB4C340EA; Mon, 24 Jan 2022 17:49:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1643046550; bh=sifjNQNJvaYEmpF/TXEf0tvu/5CoVCOTu+0FI2xI1u4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ulH9xi0v36dKdwRPxm0h3KHR/s25UMUrfoclFb0QBcasIcdHh8mWHQNVYdw+v/wFz jt+0jzJzuynSO1pydKeaYM0CoT+b4brAzQYW9aLHE2S97Gle8z9Iik2VcFnKIfzhlW CsTccgTIqFeaV+q17FYVrJXrB/hydJFX4Mp3OcC64HEYvEQWdkJVcPchO8qS4XJGFx C4rTuzBHT6xxP9NXI2j8DNEV0LvpDCqKUI9FIsSs00+Ht+ZvozSCMBfOp83KlDquqJ spqtC2/+LOkxeSeBU7VnPFARS8lKhi0733fScSegcQmm9TIvddTAh+6VY4A1ts4YCN UPyoaNvPd7Org== From: Ard Biesheuvel To: linux@armlinux.org.uk, linux-arm-kernel@lists.infradead.org Cc: linux-hardening@vger.kernel.org, Ard Biesheuvel , Nicolas Pitre , Arnd Bergmann , Kees Cook , Keith Packard , Linus Walleij , Nick Desaulniers , Tony Lindgren , Marc Zyngier , Vladimir Murzin , Jesse Taube Subject: [PATCH v5 23/32] ARM: call_with_stack: add unwind support Date: Mon, 24 Jan 2022 18:47:35 +0100 Message-Id: <20220124174744.1054712-24-ardb@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220124174744.1054712-1-ardb@kernel.org> References: <20220124174744.1054712-1-ardb@kernel.org> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2301; h=from:subject; bh=sifjNQNJvaYEmpF/TXEf0tvu/5CoVCOTu+0FI2xI1u4=; b=owEB7QES/pANAwAKAcNPIjmS2Y8kAcsmYgBh7uYtE3gGvhLgCmUm3gkuPv+muXMmo8Zv0BVJ9wIE WTEKmMaJAbMEAAEKAB0WIQT72WJ8QGnJQhU3VynDTyI5ktmPJAUCYe7mLQAKCRDDTyI5ktmPJBjOC/ 0fJ5EJ7XBT2oHcL3oEgjcm1AMtan3NExCq49rRD8olPqSud5SgGVkNwdHauMJeurvHcaXxwvWbG3mP ptgWdmR8kUlv0mEHqLx+qHF986QjHGaKdNG3c/75z7AhQ0H3/E1tEVzr5tVeVSpwYyE8afKu33sLhH JsDxfKuMR0ySBFXe+ChN9L6wRIQ/p3iHeJ/p5QnlYimv2tcNQDyy4CeuGpd/Oj6PNtuSI0zFBhUs5X +ohLC53Vp52GT3sP17rG6JPphvOkAiETffcX1Rh63cfGzxhki4xTnNOxwblKARSvRhIe1LJ56Z+65p AaI4PVpwBSFD0ONQOTPywkQ1XDOmbSidZ4ij+cleQjA2VeNtchnGMh2D2Vz0WErYtBZQf+hLgGtMWE JQjPfRSlgjngAkUwqBblJfmLf7uwXgQB40mY2ks9pURAxyBr+zvny9UArrc+MgPjyB+hDN8d2tREhr 5+8Hz4B336Cf0my4/sOgPlKwFUaEtUY1eFZtPQyaFb/g4= X-Developer-Key: i=ardb@kernel.org; a=openpgp; fpr=F43D03328115A198C90016883D200E9CA6329909 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-hardening@vger.kernel.org Restructure the code and add the unwind annotations so that both the frame pointer unwinder as well as the EHABI unwind info based unwinder will be able to follow the call stack through call_with_stack(). Since GCC and Clang use different formats for the stack frame, two methods are implemented: a GCC version that pushes fp, sp, lr and pc for compatibility with the frame pointer unwinder, and a second version that works with Clang, as well as with the EHABI unwinder both in ARM and Thumb2 modes. Signed-off-by: Ard Biesheuvel Acked-by: Linus Walleij Tested-by: Keith Packard Reviewed-by: Nick Desaulniers Tested-by: Marc Zyngier Tested-by: Vladimir Murzin # ARMv7M --- arch/arm/lib/call_with_stack.S | 33 +++++++++++++++----- 1 file changed, 25 insertions(+), 8 deletions(-) diff --git a/arch/arm/lib/call_with_stack.S b/arch/arm/lib/call_with_stack.S index 28b0341ae786..0a268a6c513c 100644 --- a/arch/arm/lib/call_with_stack.S +++ b/arch/arm/lib/call_with_stack.S @@ -8,25 +8,42 @@ #include #include +#include /* * void call_with_stack(void (*fn)(void *), void *arg, void *sp) * * Change the stack to that pointed at by sp, then invoke fn(arg) with * the new stack. + * + * The sequence below follows the APCS frame convention for frame pointer + * unwinding, and implements the unwinder annotations needed by the EABI + * unwinder. */ -ENTRY(call_with_stack) - str sp, [r2, #-4]! - str lr, [r2, #-4]! +ENTRY(call_with_stack) +#if defined(CONFIG_UNWINDER_FRAME_POINTER) && defined(CONFIG_CC_IS_GCC) + mov ip, sp + push {fp, ip, lr, pc} + sub fp, ip, #4 +#else +UNWIND( .fnstart ) +UNWIND( .save {fpreg, lr} ) + push {fpreg, lr} +UNWIND( .setfp fpreg, sp ) + mov fpreg, sp +#endif mov sp, r2 mov r2, r0 mov r0, r1 - badr lr, 1f - ret r2 + bl_r r2 -1: ldr lr, [sp] - ldr sp, [sp, #4] - ret lr +#if defined(CONFIG_UNWINDER_FRAME_POINTER) && defined(CONFIG_CC_IS_GCC) + ldmdb fp, {fp, sp, pc} +#else + mov sp, fpreg + pop {fpreg, pc} +UNWIND( .fnend ) +#endif ENDPROC(call_with_stack) -- 2.30.2 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 4FB3AC433FE for ; Mon, 24 Jan 2022 18:08: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: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=OaDNraa7jbChmlp1fWGfhbCZWE7V64GRmmAyS9BzbJs=; b=vpudWg+mGHV1qP s5KKy2DuB/Y6w/wKeFr5IFPnvRGHTUZuN8+Phc+fXHI0XJXSeeKIR2sAHFwzRMqFQxjL0uPgcI0g2 rjqEoNtPr17Ya0hOn6vQ9GOXGopQuC+i2k4FkYkmWNyOXiTr6WAHWt+O9A3exdzS0+AmHUyEVHmLp 3+7hgEvNI0XohdsaibPTUgs3yAfEdiLNbvn9aAmruvH5igc1UvuzSRXzUvZfc0ZjYgVbUUL+VYS0J TX98FzHvVbJvbceqVwVyH6SyKXDzs8BirhokmKPFyA7Wg9PAk2Blf1qVJxRMvNg78EMFHvnwPDf0T B2uo63DvOMN9h6ucZraQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nC3jz-004NRh-Tz; Mon, 24 Jan 2022 18:06:56 +0000 Received: from ams.source.kernel.org ([145.40.68.75]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nC3Sq-004FcK-Pu for linux-arm-kernel@lists.infradead.org; Mon, 24 Jan 2022 17:49:17 +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 7C784B811B1; Mon, 24 Jan 2022 17:49:11 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5CEB4C340EA; Mon, 24 Jan 2022 17:49:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1643046550; bh=sifjNQNJvaYEmpF/TXEf0tvu/5CoVCOTu+0FI2xI1u4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ulH9xi0v36dKdwRPxm0h3KHR/s25UMUrfoclFb0QBcasIcdHh8mWHQNVYdw+v/wFz jt+0jzJzuynSO1pydKeaYM0CoT+b4brAzQYW9aLHE2S97Gle8z9Iik2VcFnKIfzhlW CsTccgTIqFeaV+q17FYVrJXrB/hydJFX4Mp3OcC64HEYvEQWdkJVcPchO8qS4XJGFx C4rTuzBHT6xxP9NXI2j8DNEV0LvpDCqKUI9FIsSs00+Ht+ZvozSCMBfOp83KlDquqJ spqtC2/+LOkxeSeBU7VnPFARS8lKhi0733fScSegcQmm9TIvddTAh+6VY4A1ts4YCN UPyoaNvPd7Org== From: Ard Biesheuvel To: linux@armlinux.org.uk, linux-arm-kernel@lists.infradead.org Cc: linux-hardening@vger.kernel.org, Ard Biesheuvel , Nicolas Pitre , Arnd Bergmann , Kees Cook , Keith Packard , Linus Walleij , Nick Desaulniers , Tony Lindgren , Marc Zyngier , Vladimir Murzin , Jesse Taube Subject: [PATCH v5 23/32] ARM: call_with_stack: add unwind support Date: Mon, 24 Jan 2022 18:47:35 +0100 Message-Id: <20220124174744.1054712-24-ardb@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220124174744.1054712-1-ardb@kernel.org> References: <20220124174744.1054712-1-ardb@kernel.org> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2301; h=from:subject; bh=sifjNQNJvaYEmpF/TXEf0tvu/5CoVCOTu+0FI2xI1u4=; b=owEB7QES/pANAwAKAcNPIjmS2Y8kAcsmYgBh7uYtE3gGvhLgCmUm3gkuPv+muXMmo8Zv0BVJ9wIE WTEKmMaJAbMEAAEKAB0WIQT72WJ8QGnJQhU3VynDTyI5ktmPJAUCYe7mLQAKCRDDTyI5ktmPJBjOC/ 0fJ5EJ7XBT2oHcL3oEgjcm1AMtan3NExCq49rRD8olPqSud5SgGVkNwdHauMJeurvHcaXxwvWbG3mP ptgWdmR8kUlv0mEHqLx+qHF986QjHGaKdNG3c/75z7AhQ0H3/E1tEVzr5tVeVSpwYyE8afKu33sLhH JsDxfKuMR0ySBFXe+ChN9L6wRIQ/p3iHeJ/p5QnlYimv2tcNQDyy4CeuGpd/Oj6PNtuSI0zFBhUs5X +ohLC53Vp52GT3sP17rG6JPphvOkAiETffcX1Rh63cfGzxhki4xTnNOxwblKARSvRhIe1LJ56Z+65p AaI4PVpwBSFD0ONQOTPywkQ1XDOmbSidZ4ij+cleQjA2VeNtchnGMh2D2Vz0WErYtBZQf+hLgGtMWE JQjPfRSlgjngAkUwqBblJfmLf7uwXgQB40mY2ks9pURAxyBr+zvny9UArrc+MgPjyB+hDN8d2tREhr 5+8Hz4B336Cf0my4/sOgPlKwFUaEtUY1eFZtPQyaFb/g4= 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-20220124_094913_158114_8ABB2560 X-CRM114-Status: GOOD ( 15.17 ) 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 Restructure the code and add the unwind annotations so that both the frame pointer unwinder as well as the EHABI unwind info based unwinder will be able to follow the call stack through call_with_stack(). Since GCC and Clang use different formats for the stack frame, two methods are implemented: a GCC version that pushes fp, sp, lr and pc for compatibility with the frame pointer unwinder, and a second version that works with Clang, as well as with the EHABI unwinder both in ARM and Thumb2 modes. Signed-off-by: Ard Biesheuvel Acked-by: Linus Walleij Tested-by: Keith Packard Reviewed-by: Nick Desaulniers Tested-by: Marc Zyngier Tested-by: Vladimir Murzin # ARMv7M --- arch/arm/lib/call_with_stack.S | 33 +++++++++++++++----- 1 file changed, 25 insertions(+), 8 deletions(-) diff --git a/arch/arm/lib/call_with_stack.S b/arch/arm/lib/call_with_stack.S index 28b0341ae786..0a268a6c513c 100644 --- a/arch/arm/lib/call_with_stack.S +++ b/arch/arm/lib/call_with_stack.S @@ -8,25 +8,42 @@ #include #include +#include /* * void call_with_stack(void (*fn)(void *), void *arg, void *sp) * * Change the stack to that pointed at by sp, then invoke fn(arg) with * the new stack. + * + * The sequence below follows the APCS frame convention for frame pointer + * unwinding, and implements the unwinder annotations needed by the EABI + * unwinder. */ -ENTRY(call_with_stack) - str sp, [r2, #-4]! - str lr, [r2, #-4]! +ENTRY(call_with_stack) +#if defined(CONFIG_UNWINDER_FRAME_POINTER) && defined(CONFIG_CC_IS_GCC) + mov ip, sp + push {fp, ip, lr, pc} + sub fp, ip, #4 +#else +UNWIND( .fnstart ) +UNWIND( .save {fpreg, lr} ) + push {fpreg, lr} +UNWIND( .setfp fpreg, sp ) + mov fpreg, sp +#endif mov sp, r2 mov r2, r0 mov r0, r1 - badr lr, 1f - ret r2 + bl_r r2 -1: ldr lr, [sp] - ldr sp, [sp, #4] - ret lr +#if defined(CONFIG_UNWINDER_FRAME_POINTER) && defined(CONFIG_CC_IS_GCC) + ldmdb fp, {fp, sp, pc} +#else + mov sp, fpreg + pop {fpreg, pc} +UNWIND( .fnend ) +#endif ENDPROC(call_with_stack) -- 2.30.2 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel