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 C49C5C433F5 for ; Fri, 8 Oct 2021 07:44:09 +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 92BDC61100 for ; Fri, 8 Oct 2021 07:44:09 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 92BDC61100 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=XsUI3dlc/WDdR5tYvSiz8Hq1CkTm18ghjbLVH4Wi/kg=; b=jTbHJ+EOzPEEnt B4SjkfU/bwWSiZ+s8rTfkIVtwernsHA2FmGCdvYLK+4x/HQo0Jqod3FmfrDV8XObsTQfGCP4hRdRV z8blo7bLzEx1ykIIrJm41f09q62qbjpDxSwg0dvQ7PEhGjhYbKGuaZbKYLLUZ6Colnq0G8SuvLxfo W6gJEjJ1Fr1n71UCzKnyt0qTxLw9vrWdrgp2mht7ifnqEi4inIL0shDUPHlZHUXmxIYwhZ8Xj2AaC eHbWfi/2t6K8LGsj2eQzGOqj9uAg32gYiZOIPCHPMZlkix0Q1ufkrzmJ+a2b+S7sI9E6sJjB+45ZI kz9kiCcAKd//1upwCeDw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mYkWW-001tRL-04; Fri, 08 Oct 2021 07:42:32 +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 1mYkVt-001tMB-8B for linux-arm-kernel@lists.infradead.org; Fri, 08 Oct 2021 07:41:54 +0000 Received: by mail.kernel.org (Postfix) with ESMTPSA id 0865A60F9D; Fri, 8 Oct 2021 07:41:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1633678913; bh=pK7Q+LJsYl3m1bUTf9D/M7S42paR2Tx9HE/+G3d8N9Q=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=smFLDlYrcIXLnGz0MTAAvxnYaOewrASEuOybHmj/GCaN+PSSLXW0EZc04HvH8deu5 lpS9u7UQ8iUYhnoEUsEgjVp5yZoWw/Qqlfmyoil4cb7QFBjMFbsQtk+nmtuFp29gso eCsTRNzI6uDIeCJp4qpX/LctWiC5DFEq14ffUzStKuqAdl0T7KeA7nJXv0Do5tCpFo S8d6re/HvjD9X8J1rL2eFW01Vvp/sZlTL3THsrGhMZplbCRZW6IeF6eTx+NiTdQUIG 9mz+QqSn0n4FOCPCtydispIUMD0i5V/otO/qSDt3JDGK6FM7Ai1jfEyHJiSx+lKwzq V/8uJ6hQ2ZHlA== From: Ard Biesheuvel To: linux-arm-kernel@lists.infradead.org, linux@armlinux.org.uk Cc: Ard Biesheuvel , Nicolas Pitre , Arnd Bergmann , Kees Cook , Keith Packard , Linus Walleij Subject: [PATCH 4/5] ARM: unwind: disregard unwind info before stack frame is set up Date: Fri, 8 Oct 2021 09:41:26 +0200 Message-Id: <20211008074127.435364-5-ardb@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20211008074127.435364-1-ardb@kernel.org> References: <20211008074127.435364-1-ardb@kernel.org> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2281; h=from:subject; bh=pK7Q+LJsYl3m1bUTf9D/M7S42paR2Tx9HE/+G3d8N9Q=; b=owEB7QES/pANAwAKAcNPIjmS2Y8kAcsmYgBhX/YhYBI5ZQc0y/659UIV/dBjw49ejcIekRVubgac sg5Dg7SJAbMEAAEKAB0WIQT72WJ8QGnJQhU3VynDTyI5ktmPJAUCYV/2IQAKCRDDTyI5ktmPJJEGDA CPtPJ+iEAy7T7H4kcgi78KRQ8YOqjIWui1ZGg5RRs2+rfMcGoQGDGg2G78sSBPvcWa+Yu5W95s/620 WEJLoVEjfYMnV0pjjvbAViiuDCYQYnldX35C5L8rHfuAHSiIwRo1i/D6HR+GmEojr5Wl49wmNrN+8R vETWGaVqqcW7k/HlfjGAJzkrIiBGWxyjTee1rKJ2B3g2a2I0b/Rq+lrjep1ZfPtrfTfsvD7UTLbEsd QWZZOQJxOqmsikrOhMMA1ZkTNgTMBra7vZYJ3Uvx7ZQjdmIC5Eg5w2BJAJDlXRxTDlymO+8Q6v3a/s 1u7cxevKJRz0g0yye/GapLeiX2+JtG7WXvc+gj1lCw0cUHtZkWNTfYBtFnQkGFUegcije4ZpVD0Dti 24wLYklhnmClhdZANeotGYs2XOFSMCJ6PsVuee5Dmyzx7wbkMz0GOxMHoHosHKLMz7lxvuoqZHu/jf P+uskl3jdmHhjOjPRW6BL8ZbExFa94Z8pVBaNc8sZNfxs= 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-20211008_004153_341978_8E966EED X-CRM114-Status: GOOD ( 17.46 ) 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 --- arch/arm/kernel/unwind.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/arch/arm/kernel/unwind.c b/arch/arm/kernel/unwind.c index b7a6141c342f..de0d26dc73fd 100644 --- a/arch/arm/kernel/unwind.c +++ b/arch/arm/kernel/unwind.c @@ -411,7 +411,19 @@ 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. + */ + 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