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 B2FEBC433F5 for ; Mon, 24 Jan 2022 18:02:44 +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=BN50aYhAwj2Qoy7zRk/SBntzhCV2ceFIXm+a+gox4Is=; b=mSVI+nvUoI6sXv jr0SC6C6qJXMB9BxHf3LqwDoh48n6uWwwRI6AtsutqXGb6Q39wGApDniFPCw9zQnGUpxmeTYPjNSO 8RsadG4bfaLmlqH1Eh7TI5PDPBilbk0peR7X11QNyu6mJW8nfxyb5sw7JJjEk3ysuJN24UUsxpkIp ub7ebSN0GXaoJzOoUzHbx8R/nej1kwMBOIB8pde+CavSSXJpChHLTwR7De3xc2jpjCFcmW6QIgLfD qAbhZftisH3AE9pkCwt8BW7xVW1nhYw7EDfwzwFH0ov+tWB8WA/wdiQxYqhVO7f4eG/fJNyXfKdas N2JAryplSx01cfXtP4qg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nC3eJ-004KwN-BI; Mon, 24 Jan 2022 18:01:04 +0000 Received: from dfw.source.kernel.org ([2604:1380:4641:c500::1]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nC3Sf-004FVr-E1 for linux-arm-kernel@lists.infradead.org; Mon, 24 Jan 2022 17:49:06 +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 dfw.source.kernel.org (Postfix) with ESMTPS id D9CAC60FDB; Mon, 24 Jan 2022 17:49:00 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 74896C340E8; Mon, 24 Jan 2022 17:48:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1643046540; bh=6iePrDdRo1FEptrMGTjRPP3aneHB8xt6RRoMqC1C9mk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ptoBXMtaZHLKhMA8ZOjT6ZDeM19zKEUsr02jw/eJdg/L6NrUF/GECFqOqpjKzN9uW GAv+VlVbUg5dUfFtKZul2fhplW6TDm6PVaOkfvT6F2rrUsGC3VGFj4nNgAB4GGN+l3 J1bdhq99fKavOh7QqNtI6SokiQ7HDMkw3m6shenBu7s0ziOeTBlsGbsfku4bvdrD5A ckMdMSQt9Wre0c2DqvUtsy9YstuWph+GT/fB1gGSVu+Pe/QB0ouKGz68DYvMz1cPN9 mDHcs9h+pZC30MNKxzPoMLaSLPei0gyF6uBTWIhkHAh3kk/E1Cf94S55E69Uz4ukPn zCBwEIhQBK0AA== 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 20/32] ARM: unwind: dump exception stack from calling frame Date: Mon, 24 Jan 2022 18:47:32 +0100 Message-Id: <20220124174744.1054712-21-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=3477; h=from:subject; bh=6iePrDdRo1FEptrMGTjRPP3aneHB8xt6RRoMqC1C9mk=; b=owEB7QES/pANAwAKAcNPIjmS2Y8kAcsmYgBh7uYoADUPn+SPniy3ES0sTnZF4IDI3RJ7qNFKOy8J dWMFOICJAbMEAAEKAB0WIQT72WJ8QGnJQhU3VynDTyI5ktmPJAUCYe7mKAAKCRDDTyI5ktmPJEt6C/ 0Wu/eTXGd3U041kAWfvVdVR0n0DZfO2wJBB3zXW5/Wjkdjc11GQgSPEOv1pTzpr7d4yYi/74uVhzig tPpzUaRyemIsm7N/NFf41k0CQTzVcQ/oD8olnoRR5dubfuOvBLjyhxl5uoMjCG9TN6T66mgw+8eGdB WD/nHSX4zLHvCSQG95WWDNox34kbqVNQFxFNeuLqzlEUa3uCqhKm6jbRiyJpL64RSGDqd9gIeT2jtv w11qH8Gkjzkp16HeTx1QPZtvX6f4Fk3Ej6U26jUoHCzqHqMJT49LICyZOs4VuaX5CJ3jghr9vduQuH oDD4UNBqspFOyp+oHjzdsiXClX2GnAFLgHFu+wLD/qsPIct8TzfWQIQOHXWJi9hvaNidJZixLVm9nJ SyYbqQi5GOAGMbVpLMkUEEOLz3ZW/9gt3FTvoF60MP40fUP07gYpZA/lhB3lqP3KluojwDlaHIV2IH GEp+moQvWn9omVbO2Trs5kh/aTp4QwNCc51erun/qMmWA= 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_094901_596473_D3DD2602 X-CRM114-Status: GOOD ( 21.19 ) 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 The existing code that dumps the contents of the pt_regs structure passed to __entry routines does so while unwinding the callee frame, and dereferences the stack pointer as a struct pt_regs*. This will no longer work when we enable support for IRQ or overflow stacks, because the struct pt_regs may live on the task stack, while we are executing from another stack. The unwinder has access to this information, but only while unwinding the calling frame. So let's combine the exception stack dumping code with the handling of the calling frame as well. By printing it before dumping the caller/callee addresses, the output order is preserved. Signed-off-by: Ard Biesheuvel Reviewed-by: Arnd Bergmann Acked-by: Linus Walleij Tested-by: Keith Packard Tested-by: Marc Zyngier Tested-by: Vladimir Murzin # ARMv7M --- arch/arm/include/asm/stacktrace.h | 10 ++++++++++ arch/arm/kernel/traps.c | 3 ++- arch/arm/kernel/unwind.c | 8 +++++++- 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/arch/arm/include/asm/stacktrace.h b/arch/arm/include/asm/stacktrace.h index 33ee1aa4b8c0..d87d60532b86 100644 --- a/arch/arm/include/asm/stacktrace.h +++ b/arch/arm/include/asm/stacktrace.h @@ -18,6 +18,16 @@ struct stackframe { struct llist_node *kr_cur; struct task_struct *tsk; #endif +#ifdef CONFIG_ARM_UNWIND + /* + * This field is used to track the stack pointer value when calling + * __entry routines. This is needed when IRQ stacks and overflow stacks + * are used, because in that case, the struct pt_regs passed to these + * __entry routines may be at the top of the task stack, while we are + * executing from another stack. + */ + unsigned long sp_low; +#endif }; static __always_inline diff --git a/arch/arm/kernel/traps.c b/arch/arm/kernel/traps.c index 710306eac71f..c51b87f6fc3e 100644 --- a/arch/arm/kernel/traps.c +++ b/arch/arm/kernel/traps.c @@ -76,7 +76,8 @@ void dump_backtrace_entry(unsigned long where, unsigned long from, printk("%s %ps from %pS\n", loglvl, (void *)where, (void *)from); #endif - if (in_entry_text(from) && end <= ALIGN(frame, THREAD_SIZE)) + if (!IS_ENABLED(CONFIG_UNWINDER_ARM) && + in_entry_text(from) && end <= ALIGN(frame, THREAD_SIZE)) dump_mem(loglvl, "Exception stack", frame + 4, end); } diff --git a/arch/arm/kernel/unwind.c b/arch/arm/kernel/unwind.c index 9cb9af3fc433..b7a6141c342f 100644 --- a/arch/arm/kernel/unwind.c +++ b/arch/arm/kernel/unwind.c @@ -29,6 +29,7 @@ #include #include +#include #include #include #include @@ -459,6 +460,7 @@ int unwind_frame(struct stackframe *frame) frame->sp = ctrl.vrs[SP]; frame->lr = ctrl.vrs[LR]; frame->pc = ctrl.vrs[PC]; + frame->sp_low = ctrl.sp_low; return URC_OK; } @@ -502,7 +504,11 @@ void unwind_backtrace(struct pt_regs *regs, struct task_struct *tsk, urc = unwind_frame(&frame); if (urc < 0) break; - dump_backtrace_entry(where, frame.pc, frame.sp - 4, loglvl); + if (in_entry_text(where)) + dump_mem(loglvl, "Exception stack", frame.sp_low, + frame.sp_low + sizeof(struct pt_regs)); + + dump_backtrace_entry(where, frame.pc, 0, loglvl); } } -- 2.30.2 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel