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 22A7CC77B73 for ; Sat, 6 May 2023 16:14:50 +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: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:In-Reply-To:References: List-Owner; bh=X+FRC0q8cq2fx8tnAHMWCzt5vXn7XVN2d9DV0+NSoxE=; b=zGIA9VFM4Wpc60 t7HPQD0E6lkItTlfWiI3sLY3rLCSpWMBFrnlMOj6GZTrHdpDCUoQMF3PbK2NiXAysiSG1YceXQDuu cU50n8Ntj6ZuLjT1NhH1NbJmMsUJBImej7p4yXTP4vc+pXtUHL50jF9wzI/4Z8e/k5qK+B46N39J7 qQhpZs/7k09+kcDj9FqZADXhEQdC5DHzAQ8Bx35mQB1uIovjSpQ14N8VvAE+cS2nQ9VNYgeSzQqq3 7TZh1orD9zQVh3K5oZ4MLZacEW43/dJbNyTgAD9wje3rrWv65wA/DIVs9ulgJzFZAyb23jpizdYDK XyZh0iILxM211aXJNrfw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1pvKXe-00DznV-21; Sat, 06 May 2023 16:13:50 +0000 Received: from dfw.source.kernel.org ([139.178.84.217]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1pvKXb-00Dzmx-2M for linux-arm-kernel@lists.infradead.org; Sat, 06 May 2023 16:13:49 +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 3D39C60F92; Sat, 6 May 2023 16:13:46 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6AAD2C433EF; Sat, 6 May 2023 16:13:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1683389625; bh=q8kdHot23GwN12+wrWOXkleEqI70GhcU5JlcsEAzr4U=; h=From:To:Cc:Subject:Date:From; b=uipvo6bAQmuHgkmNTq3bSOhCUTb46HWzmZy3Lny/tf8vMwLJhjBjjnoxe2e0ohEiR UL+RtltCLCcQk5xG5IFY0I4CXsXKWf05AH/0rMktbS1WaD+6vvqmMxsqgG7hTzlOWp uKA317LEr6kWsuX9r2lXqufnO3V9JXOpZelRe3O26sLLmVBEKSp5YcswCDi/R96Rr3 vGrDY/wAU7XOcoVmU9fQ9YNYxC/6qQLvFowGIDAlZgMnr2cBozZ1xM7HKp+ueduFgE oZciQ7JHnReKSTwIci2BQhw2oytFYjVJ752jN465uDJ51zQINGih6lxmeIV/10jpvC TDnSMUOa55OAw== From: Ard Biesheuvel To: linux@armlinux.org.uk Cc: linux-arm-kernel@lists.infradead.org, linus.walleij@linaro.org, Ard Biesheuvel , syzbot+d4b00edc2d0c910d4bf4@syzkaller.appspotmail.com Subject: [PATCH] ARM: vfp: avoid unbalanced stack on 'success' return path Date: Sat, 6 May 2023 18:13:25 +0200 Message-Id: <20230506161325.223362-1-ardb@kernel.org> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=3297; i=ardb@kernel.org; h=from:subject; bh=q8kdHot23GwN12+wrWOXkleEqI70GhcU5JlcsEAzr4U=; b=owGbwMvMwCFmkMcZplerG8N4Wi2JISWsZomr8Gfe64WPXtrPLvoSFnraXe4Nx6Pzs/7OzKu0P 52RXPOoo5SFQYyDQVZMkUVg9t93O09PlKp1niULM4eVCWQIAxenAEzk1WeGf4Zee085i5+bLaJg vO5Lrgbv55z1t+5kpwS4FE8+0hGRVc7IcGhNyp3aitOKR3OCn7QnB7O72Ly+bprF5vuBKYtp8S4 OJgA= 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-20230506_091347_872336_9521AF01 X-CRM114-Status: GOOD ( 20.10 ) 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 Commit c76c6c4ecbec0deb5 ("ARM: 9294/2: vfp: Fix broken softirq handling with instrumentation enabled") updated the VFP exception entry logic to go via a C function, so that we get the compiler's version of local_bh_disable(), which may be instrumented, and isn't generally callable from assembler. However, this assumes that passing an alternative 'success' return address works in C as it does in asm, and this is only the case if the C calls in question are tail calls, as otherwise, the stack will need some unwinding as well. I have already sent patches to the list that replace most of the asm logic with C code, and so it is preferable to have a minimal fix that addresses the issue and can be backported along with the commit that it fixes to v6.3 from v6.4. Hopefully, we can land the C conversion for v6.5. So instead of passing the 'success' return address as a function argument, pass the stack address from where to pop it so that both LR and SP have the expected value. Fixes: c76c6c4ecbec0deb5 ("ARM: 9294/2: vfp: Fix broken softirq handling with ...") Reported-by: syzbot+d4b00edc2d0c910d4bf4@syzkaller.appspotmail.com Signed-off-by: Ard Biesheuvel --- This is one of those cases where you scratch your head and ask yourself how it ever worked in the first place. I've tested this stuff under KVM but also on BeagleBone and the original Raspberry Pi, but apparently, none of the configs I've tested had the frame pointer unwinder enabled, and this is what appears to result in vfp_support_entry() not being tail-called from vfp_entry() but from a proper stack frame, and this blows up the first time you call it. Oh well. arch/arm/vfp/entry.S | 7 +++++-- arch/arm/vfp/vfphw.S | 6 ++++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/arch/arm/vfp/entry.S b/arch/arm/vfp/entry.S index 7483ef8bccda394c..62206ef250371cd3 100644 --- a/arch/arm/vfp/entry.S +++ b/arch/arm/vfp/entry.S @@ -23,6 +23,9 @@ @ ENTRY(do_vfp) mov r1, r10 - mov r3, r9 - b vfp_entry + str lr, [sp, #-8]! + add r3, sp, #4 + str r9, [r3] + bl vfp_entry + ldr pc, [sp], #8 ENDPROC(do_vfp) diff --git a/arch/arm/vfp/vfphw.S b/arch/arm/vfp/vfphw.S index 4d8478264d82b3d2..a4610d0f321527cc 100644 --- a/arch/arm/vfp/vfphw.S +++ b/arch/arm/vfp/vfphw.S @@ -172,13 +172,14 @@ vfp_hw_state_valid: @ out before setting an FPEXC that @ stops us reading stuff VFPFMXR FPEXC, r1 @ Restore FPEXC last + mov sp, r3 @ we think we have handled things + pop {lr} sub r2, r2, #4 @ Retry current instruction - if Thumb str r2, [sp, #S_PC] @ mode it's two 16-bit instructions, @ else it's one 32-bit instruction, so @ always subtract 4 from the following @ instruction address. - mov lr, r3 @ we think we have handled things local_bh_enable_and_ret: adr r0, . mov r1, #SOFTIRQ_DISABLE_OFFSET @@ -209,8 +210,9 @@ skip: process_exception: DBGSTR "bounce" + mov sp, r3 @ setup for a return to the user code. + pop {lr} mov r2, sp @ nothing stacked - regdump is at TOS - mov lr, r3 @ setup for a return to the user code. @ Now call the C code to package up the bounce to the support code @ r0 holds the trigger instruction -- 2.39.2 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel