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 A44BAC433F5 for ; Mon, 15 Nov 2021 11:20:50 +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 72E9963214 for ; Mon, 15 Nov 2021 11:20:50 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 72E9963214 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=8PxJMuzVDh2Db7k+kZ1Yg3ulTHqExrf8MPqljA8uqG8=; b=IguvOnRWZIBohP 1cBvKlPj8zd/iTOAX54iU0cf8lLBAjH42uHXMLL8cnVmBQnNPsqD0lDrKdXhHGsZ3ANZD2wCXp5Ds Xr9fruW9hShPL3mb+nIOs6NMTtVgPn24BMMMi3SToUzcRUvc2GMatGBGqkLg8foUU6BoVX4adpF8k sLTkNSvHzCxGDKF60bTx5v4uASrQypZ96uysbdNwGW5USRQgUojbBFOqfWMX/RdxC1ohbsUvSITYn bjHwlX7ppOHE3Q+0O+6Ybo+INPJhOaqE2ACL0RMOG2EGicNF52dKOFwdQZpMWL1BtrZPWrgskR6Qc RjyPA3HSMfg8XK/sfnFg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mma13-00FKGe-PA; Mon, 15 Nov 2021 11:19:13 +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 1mma0S-00FK9z-Fx for linux-arm-kernel@lists.infradead.org; Mon, 15 Nov 2021 11:18:37 +0000 Received: by mail.kernel.org (Postfix) with ESMTPSA id 3877D63214; Mon, 15 Nov 2021 11:18:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1636975116; bh=G8bl/jS0UF4ofWVfxX1cIJJ06WAI6ETjTnMacIEZcB4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fugLKw3E+BEjvoHLeQP544j6pJhfyaczvwtBBXwj4dowlgseiu4bm8Zu5+JgQLuFs HNMZQdZ/3JSJ0ZhFWMfFwRMDPhEF/1/9Hfg4okt0/X2XSI93yCcEhP4nbVGw4vCMQ9 yHLfEUvxYsQ98SW9YHEPCknqcIlBzZWkIHsucx4Pyo6w90RUJ6lcbd03JHNTChO1c+ c7TU+9QKrBuEzJXGhgi5ASmMT/c/ihBdRRF8VtVksMSdrqQ0L7jhWAr5sTmzYK8lBa emWJ8V+Ranl8a0F6GtuS/b96EXCmUsuHgbRfNkbcVfUcQ347ioGTiAaaPVcWJc1F8Z HIdD4sLWWj5Pw== From: Ard Biesheuvel To: linux-arm-kernel@lists.infradead.org Cc: Ard Biesheuvel , Russell King , Nicolas Pitre , Arnd Bergmann , Kees Cook , Keith Packard , Linus Walleij , Nick Desaulniers Subject: [PATCH v3 4/7] ARM: unwind: disregard unwind info before stack frame is set up Date: Mon, 15 Nov 2021 12:18:13 +0100 Message-Id: <20211115111816.3911213-5-ardb@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20211115111816.3911213-1-ardb@kernel.org> References: <20211115111816.3911213-1-ardb@kernel.org> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2389; h=from:subject; bh=G8bl/jS0UF4ofWVfxX1cIJJ06WAI6ETjTnMacIEZcB4=; b=owEB7QES/pANAwAKAcNPIjmS2Y8kAcsmYgBhkkHxuEi30aIbAnRchjXXGvZ89mMKIIQd149EMa+6 bmr6GyKJAbMEAAEKAB0WIQT72WJ8QGnJQhU3VynDTyI5ktmPJAUCYZJB8QAKCRDDTyI5ktmPJPuADA CZJ/1f7pj+biUmNSflyaIBEDdka6P2a92bJaXaFdleCAfeZGMPg8qFC95kpdOLoV614xJIdJm/6w53 qpf/cLQPooF7JhZziOU4TdrYnYbYDXHv4J4a/XrVMxD0/IxuKxY9BOq4138X8yC7HaSAjGbjXbOlxB cMtKkQe+luuKr2GSSpr63BlqdQgreJrnnD0bURQ91lMKwqf33FLEhMDarcThKRvLjvt2iVj4/+13gT EtL3b0OenITxDdhvBm6iD413J1qBx3rQhLt62jbiwysK/mhCBIFWUvpr/fPjt7rAXVEy9AH/66ho2J 4zF7HjThekU3fbYVcGqCJpdQN4m0bCqj3TLJjFPAsCgo4eJI30rSvvMK0DDAfo/rGLKP30SP3ff+ee wE8YtqQ53xIrcZ5RlghsGH6k3DYH9zzAyuP+NQlXxegoH/GuQK59R1qZBORpVHMrEqI09EdxKOstZE p1MTpfxCKtmS5nNzkFLE36uqVjX7WDAVxfgb4qNbM9uSs= 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-20211115_031836_589547_E4692ED0 X-CRM114-Status: GOOD ( 18.83 ) 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 When unwinding the stack from a stack overflow, we are likely to start from a stack push instruction, given that this is the most common way to grow the stack for compiler emitted code. This push instruction rarely appears anywhere else than at offset 0x0 of the function, and if it doesn't, the compiler tends to split up the unwind annotations, given that the stack frame layout is apparently not the same throughout the function. This means that, in the general case, if the frame's PC points at the first instruction covered by a certain unwind entry, there is no way the stack frame that the unwind entry describes could have been created yet, and so we are still on the stack frame of the caller in that case. So treat this as a special case, and return with the new PC taken from the frame's LR, without applying the unwind transformations to the virtual register set. This permits us to unwind the call stack on stack overflow when the overflow was caused by a stack push on function entry. Signed-off-by: Ard Biesheuvel Tested-by: Keith Packard --- arch/arm/kernel/unwind.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/arch/arm/kernel/unwind.c b/arch/arm/kernel/unwind.c index b7a6141c342f..e8d729975f12 100644 --- a/arch/arm/kernel/unwind.c +++ b/arch/arm/kernel/unwind.c @@ -411,7 +411,21 @@ int unwind_frame(struct stackframe *frame) if (idx->insn == 1) /* can't unwind */ return -URC_FAILURE; - else if ((idx->insn & 0x80000000) == 0) + else if (frame->pc == prel31_to_addr(&idx->addr_offset)) { + /* + * Unwinding is tricky when we're halfway through the prologue, + * since the stack frame that the unwinder expects may not be + * fully set up yet. However, one thing we do know for sure is + * that if we are unwinding from the very first instruction of + * a function, we are still effectively in the stack frame of + * the caller, and the unwind info has no relevance yet. + */ + if (frame->pc == frame->lr) + return -URC_FAILURE; + frame->sp_low = frame->sp; + frame->pc = frame->lr; + return URC_OK; + } else if ((idx->insn & 0x80000000) == 0) /* prel31 to the unwind table */ ctrl.insn = (unsigned long *)prel31_to_addr(&idx->insn); else if ((idx->insn & 0xff000000) == 0x80000000) -- 2.30.2 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel