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 A0B02C38145 for ; Fri, 2 Sep 2022 12:57:31 +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=MxuDAuY72gZ1HXNiWUu2r97TRIrreXve1hGPFv1koyw=; b=HEZ5DsgP5K1Bob 3hhTyPpGmKA2kKAdXzKUDfA2ToT8oZZLAxr9hn/dVD1+7jsC35in6qBCxAhNjYYh1jDGo7+uqR89r YvTRQw3JxTZit1a0YDVG431jhdN5ME5ShIr6cpzVj5SIHrukqBVhjp2FXKdDDZKcOMcxqqzlrPI+8 23TiRShFGcMOmiEFmtdcP8UXmH2yVYvwWSbAG6dp46fb4UPgzEImtDkRxbvvPnvYbyjcc/JDTMvY/ yHfLhjMwj6Q5ITB2vLvaMGwTF3lm4rS0yj1/rmPFk64JJp0zKBrzEhGgXBgj1ikhVFTwHIHHnMUm2 f18ke4n1OChLf0vJ4XTQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oU6DV-004r5U-39; Fri, 02 Sep 2022 12:56:13 +0000 Received: from ams.source.kernel.org ([2604:1380:4601:e00::1]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1oU657-004itF-F3 for linux-arm-kernel@lists.infradead.org; Fri, 02 Sep 2022 12:47:35 +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 E8ED8B82A99; Fri, 2 Sep 2022 12:47:31 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6F39FC433C1; Fri, 2 Sep 2022 12:47:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1662122849; bh=BIMODrIWKJlPWX83zSnu+rUQejHNClp6CP+NteWG8nc=; h=From:To:Cc:Subject:Date:From; b=cP0FiT8B/O+tcnMBlRsphwT0PIV54TEYhJTvsBVg9Os9EopgmhjEYHVr0DjeqNqWL GEJc5kBAMFeZlYDQhaR06X9P8Z56ff6D+/Cei5W+keFxgN7O4GtjTXqL/arb4sB04w Q5yePFqagUWQ5UMpkllje9p0jGIp4lVuZLIKnHAJCF0x+W4smzzjG7b82dO7oLnDP7 Fdv+zIfp3AAjHwHy8ziobtAuvLmqXNJNZ8M/SwvmLXs2Amcb+3hnW1QQ8TbAZpVYBU m9EhW/40/uXLbEVO/UvctQVRiT8cgi4fgxo5ojSZ1XsU/vBpsGjn93lnMwO/TeE1iq CgDQAO7EANjSg== From: Mark Brown To: D Scott Phillips , Catalin Marinas , Will Deacon Cc: linux-arm-kernel@lists.infradead.org, Mark Rutland , Mark Brown Subject: [PATCH] arm64/bti: Disable in kernel BTI when cross section thunks are broken Date: Fri, 2 Sep 2022 13:47:24 +0100 Message-Id: <20220902124724.19334-1-broonie@kernel.org> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2203; i=broonie@kernel.org; h=from:subject; bh=BIMODrIWKJlPWX83zSnu+rUQejHNClp6CP+NteWG8nc=; b=owEBbQGS/pANAwAKASTWi3JdVIfQAcsmYgBjEftcw5wMJfpxnmttHNFPDqIM4fTwl/ubIDVdBE9U ibTn2U6JATMEAAEKAB0WIQSt5miqZ1cYtZ/in+ok1otyXVSH0AUCYxH7XAAKCRAk1otyXVSH0EJcCA CBvdfLajifgVwOCPihE3ayk36qwAM/uLzDc7Gu9NyanQLuBkjRsmPybK7E50PwCDT6DVDZ4UJci6ZC yBqrvVXt94hk8VfHiS30tEDnm/6+dBLsB9NaQY8dIadJFasZtPBzoBrUsCiD7AKtMeTW8WAVUugtzS gAkTx7f57Q187kt137iaEWm/nleg7ZGvzvvMuzMuC074BJoSqfBiuu1S0YMaZPUc+jrWUgNAnimLhm qRGLG9hpl6nMSV7qY+b03IsKPP0CDdVT6F33uuCS2tdIsXLmR/2oG6xw8cabJpVB5l/V6fVI0/AmCO q4kxQJZGKL6u1jRaUnbzNuRm+7T5jW X-Developer-Key: i=broonie@kernel.org; a=openpgp; fpr=3F2568AAC26998F9E813A1C5C3F436CA30F5D8EB X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220902_054733_838862_374DF72F X-CRM114-Status: GOOD ( 17.61 ) 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 GCC does not insert a `bti c` instruction at the beginning of a function when it believes that all callers reach the function through a direct branch[1]. Unfortunately the logic it uses to determine this is not sufficiently robust, for example not taking account of functions being placed in different sections which may be loaded separately, so we may still see thunks being generated to these functions. If that happens, the first instruction in the callee function will result in a Branch Target Exception due to the missing landing pad. While this has currently only been observed in the case of modules having their main code loaded sufficiently far from their init section to require thunks it could potentially happen for other cases so the safest thing is to disable BTI for the kernel when building with an affected toolchain. [1]: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106671 Reported-by: D Scott Phillips [Bits of the commit message are lifted from his report & workaround] Signed-off-by: Mark Brown --- I'm sending this as an alternative to Scott's workaround in: https://lore.kernel.org/r/20220902001551.2349544-1-scott@os.amperecomputing.com in case people aren't comfortable with that, given the GCC bug it seems likely that it is possible to generate some other case where there might be issues. arch/arm64/Kconfig | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig index 9fb9fff08c94..863b807681ce 100644 --- a/arch/arm64/Kconfig +++ b/arch/arm64/Kconfig @@ -1885,8 +1885,8 @@ config ARM64_BTI_KERNEL depends on ARM64_BTI depends on ARM64_PTR_AUTH_KERNEL depends on CC_HAS_BRANCH_PROT_PAC_RET_BTI - # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94697 - depends on !CC_IS_GCC || GCC_VERSION >= 100100 + # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106671 + depends on !CC_IS_GCC # https://github.com/llvm/llvm-project/commit/a88c722e687e6780dcd6a58718350dc76fcc4cc9 depends on !CC_IS_CLANG || CLANG_VERSION >= 120000 depends on (!FUNCTION_GRAPH_TRACER || DYNAMIC_FTRACE_WITH_REGS) -- 2.30.2 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel