From patchwork Fri Sep 2 00:15:50 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: D Scott Phillips X-Patchwork-Id: 12963446 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 57C8FECAAD3 for ; Fri, 2 Sep 2022 00:17:14 +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=GdTux401crthCyUcw8iUWI8J00HF2NzhYZxS7QwnrWw=; b=g2XJ9LfkRA4Ywq OrToBgAUFKTLm436baCDYlq+BMDlkpVhtSIXBWD8H0gLFRjiI8Q649h/ddeCFNQBxw8QOTOdcf1b9 a0f2RhOqpQBpwRD+4nVHLZ05BwkMSFi6OhHDXFhMgoEEkX9yy0f/6JAigI5Unq8fUtflhOd/F7Uwf xq9Sq9h+6MwEdgI4uZPXoW++Yipj6+vadfD184sKz/a30oalCXu0YdjqSo+YkhyotCVmbPR5v82DV oj6RJSp09+z4ICdb8f58bVZhVK9HnobAdzN9m3Gj3zo4TtoQr0fduR8VIzpuCOjMwbu6nN3rWNWK4 sDlPx0GXBSg1xGazJebw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oTuM0-00G5MU-9U; Fri, 02 Sep 2022 00:16:12 +0000 Received: from mail-dm3nam02on2094.outbound.protection.outlook.com ([40.107.95.94] helo=NAM02-DM3-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1oTuLp-00G5Jk-UR for linux-arm-kernel@lists.infradead.org; Fri, 02 Sep 2022 00:16:03 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=dqsRAqnj2EreU4JU3jUqqgqIkLGTst1t2/2DMk8yQ5TGwBr4hOdgtVmlISUYZJ5Qe+D4MMnhEe1JNEaKqRRQG/52wKe38IbhCmyLXf9WTN3vdhmd+fYNqES0RoNiyBZeBAfmqFor3AlFZPYLdeEF2yoqlplez6/4VRGkiM8u2hLltsPwZQaIoOhjv1mz/mdY25iHgMzz/G9S//wQvDiWGYq7GEYG77QNrd2HjiQswSsmL0pJE4IsTGtosYKyk71ZX249MSzXEF4+V/2q0thzgEpnKpmbF1X8bmwTEd8rf3B4txgbHpYDWJdcYlybv5x/T5jEvLTcICvf3LBhkff0VA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=jnHytk3GmOv4k28e9cF9qzL/6mZa/FAWtg9Hy/E0J/Y=; b=P+o+5U46DaMM4DTiVEYrWEvvBGLjHpLjO6MgpXpiB2uiYPF2W+9K6NTZmI98dqYbTWOCOK9O8V7kC3+5k57Kv5NIzC99jDi/+Y4YXeA+39ng36Adz+d8OJxgDI82ban3rT/vqmfI56jgZWoWmTR2h7b34C0LMQfFrrjDNajpSYUnuG115vVy7A9ii/LqmdZ7uwG9hgPNTabTKItXXKZqyJBHTfD4fSAB9a8TMeZxOLUsaltMkR8+gkFAUxgD9yot3ydVmXmrCUaKRIOy6z7VTf/vdOjxIsD+CR9GGYWNrG3Rc2Ei30ZBcr/XgY30p/fKpq03MbydsmqXK4LryUkgkg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=os.amperecomputing.com; dmarc=pass action=none header.from=os.amperecomputing.com; dkim=pass header.d=os.amperecomputing.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=os.amperecomputing.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=jnHytk3GmOv4k28e9cF9qzL/6mZa/FAWtg9Hy/E0J/Y=; b=f3tZkMVCxuNl09GgaFXkkoZK2G7TAxb77HH4Rt+neB9pUtUe6r8EUyk8oZpdHLlLUZLWL93lVMkuKN55AoaTq451YrwsMW9zhdcHf2TNjjRcw5eTJSkXAKWzHw2yJleXH0l89FljM5g9HPcwAFkYhsOICeItl/j6jKR+Tz6bJ1U= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=os.amperecomputing.com; Received: from MWHPR0101MB2893.prod.exchangelabs.com (2603:10b6:301:33::25) by DS7PR01MB7830.prod.exchangelabs.com (2603:10b6:8:7d::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5566.21; Fri, 2 Sep 2022 00:15:59 +0000 Received: from MWHPR0101MB2893.prod.exchangelabs.com ([fe80::a82f:4278:a97f:2c29]) by MWHPR0101MB2893.prod.exchangelabs.com ([fe80::a82f:4278:a97f:2c29%4]) with mapi id 15.20.5566.016; Fri, 2 Sep 2022 00:15:59 +0000 From: D Scott Phillips To: Mark Brown , linux-arm-kernel@lists.infradead.org Cc: Catalin Marinas , Will Deacon , patches@amperecomputing.com Subject: [PATCH v3 1/2] arm64: Handle kernel BTI exceptions Date: Thu, 1 Sep 2022 17:15:50 -0700 Message-Id: <20220902001551.2349544-2-scott@os.amperecomputing.com> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220902001551.2349544-1-scott@os.amperecomputing.com> References: <20220902001551.2349544-1-scott@os.amperecomputing.com> X-ClientProxiedBy: CH2PR02CA0011.namprd02.prod.outlook.com (2603:10b6:610:4e::21) To MWHPR0101MB2893.prod.exchangelabs.com (2603:10b6:301:33::25) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 4b18b197-9ca8-4132-735f-08da8c784ff0 X-MS-TrafficTypeDiagnostic: DS7PR01MB7830:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: wfSwXVQER4sDuIlR7EdKhKgW4akiCUizmPIGUum/scaxwXmLS64up7RFy+gJzIAwKMBMh+5fS1JpqFKKObCDy3MPEA6m4PoOe/dQ4NxiCbdzTpToWEDu6LOZvYUOnFW05sKq5YGREED1mWpenPEtrBQXXkkVcMp50KSecIwVsHCIXV9LxcP8nkF3LUev1BnWQVgVD1s6ngCxPj3mxW40HUvBx9goGjXbCaxRFuhwPi3V0U3F638Q7ch+M5t/VXlcyYi/xhHeMezKAn+LrWrpRsmVQyw7IDtONhqZ027fenWw9+7AwV9X6/oCjfznS6YPZsvTZuv5cZjJ/ZOablVtHebxw++c5RhESVsC4mbhZukmAp7uJW6c7ewlElZ7WXZ7XpRjRwalyY/ipachizJIcQWtzGY2qLIaEzQP3oawGRow5EC4ZneL0WFZaiqdp8E5zCIf50ouE0hqda2y6iWkqBaBKDusEwhPOg833WqAlgt+BEYXoXotFTgDnlhzRKsyZn0LjjWqHsdzBj/M/nKeMV0UbkdHSPEO1fnJx2u3SO9O2TaY7AOwRXZa0AC5oM+KhUcKkoEqn18sVQ0ECp+BUQvo5KoPNT8mKUWsRFshKwNRwt1aeGJ2wU57OEnmv9hLSHZIqTxgtwCzQYryrPYIGyVXOIDgp12Jo6vm87vDa8XBuNF3CK7ic/q7srz8tKiPdAD0G5PmH7bguoKYHTnxMEF/fyMKQ7HPfNHsvjm/ClaRIJwlFIeo7+onfpPIilzC4Tonz9MjlnZL6KGgeXuixg== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:MWHPR0101MB2893.prod.exchangelabs.com;PTR:;CAT:NONE;SFS:(13230016)(4636009)(39850400004)(346002)(136003)(366004)(376002)(396003)(8936002)(66556008)(66476007)(8676002)(5660300002)(2906002)(4326008)(66946007)(316002)(54906003)(2616005)(52116002)(478600001)(6512007)(6506007)(41300700001)(107886003)(6666004)(26005)(38350700002)(186003)(6486002)(1076003)(86362001)(83380400001)(38100700002);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: VK7izMgpsMc/vGKc9e0W8MlNwnUWv7ckjXfsbs1VtMsVeY73wpUTL7yQdp2/7xe/OkH3xRX6EYMpHsZ267Hx5INKieH1fQuag33N1X2WDN1Q1nMbAjMYPf2E03OLrXYpgH5G99TovtT/RQXpVA2VOQA2OM9qlgCMhKx1uAAUtGxcaB0lB12EExVUB3A/cuhxabx3c8rQ33Xf3+6IALRHf31Wbx6AFUCkeR+nIvPt8MmEvxb4T3OGTilQiG59SoqrRGKY3w57uAv7Zocm4MjBhNVA4oFrQYSKmR8FeiH4H8Uy8tf2yTk8tq6aOsZBAIJKv+TFQwOdjtweKT0wv435JiMSOmZRfotLLbAGuiaMx7AbNyVkmfn94DH/CFlTviDdQtCAxJ0A/MLKhuHhB8rhsNxgjZb0lik+adtWzwOyFSbFk7buq6S31Wg5ptGFcXcPKqWlgY3tdd6glVvXN8625F7hEn9hJ4TjNP+zLhCjx/DoGAmMuETtG3ZlsfWXh2GwACfO5f+U/a6kaA5umQvZHbH0YCq819WHg09WXabEgby9Bxf38a9dMSziH36hiK0aArOUOBgj6yohIaoLnQjO2FLP8kYwc9PvXf5zGilBfLkZ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0 X-MS-Exchange-CrossTenant-AuthSource: MWHPR0101MB2893.prod.exchangelabs.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Sep 2022 00:15:59.3812 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3bc2b170-fd94-476d-b0ce-4229bdc904a7 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: cdm+T63lvoSdq6Vdc7jUI0XW++fsLEvhJzFu2unIBq3AWOa+V8a8BBSDo4RvvgqrKm8jPY729estuWNW8d4GDAQt60Q2UmBuHt3ZjpcOE+igAevHZxHG6kW0YwvDSyP6 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS7PR01MB7830 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220901_171602_000990_42D42326 X-CRM114-Status: GOOD ( 11.52 ) 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: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Send BTI exceptions to the do_bti handler, killing the current task with SIGSEGV instead of panicking. This is to allow a later patch to apply a compiler bug workaround. Signed-off-by: D Scott Phillips Reviewed-by: Mark Brown --- arch/arm64/kernel/entry-common.c | 12 ++++++++++++ arch/arm64/kernel/traps.c | 8 ++++++-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/arch/arm64/kernel/entry-common.c b/arch/arm64/kernel/entry-common.c index c75ca36b4a49..dad27e854d8c 100644 --- a/arch/arm64/kernel/entry-common.c +++ b/arch/arm64/kernel/entry-common.c @@ -388,6 +388,15 @@ static void noinstr el1_undef(struct pt_regs *regs) exit_to_kernel_mode(regs); } +static void noinstr el1_bti(struct pt_regs *regs) +{ + enter_from_kernel_mode(regs); + local_daif_inherit(regs); + do_bti(regs); + local_daif_mask(); + exit_to_kernel_mode(regs); +} + static void noinstr el1_dbg(struct pt_regs *regs, unsigned long esr) { unsigned long far = read_sysreg(far_el1); @@ -427,6 +436,9 @@ asmlinkage void noinstr el1h_64_sync_handler(struct pt_regs *regs) case ESR_ELx_EC_UNKNOWN: el1_undef(regs); break; + case ESR_ELx_EC_BTI: + el1_bti(regs); + break; case ESR_ELx_EC_BREAKPT_CUR: case ESR_ELx_EC_SOFTSTP_CUR: case ESR_ELx_EC_WATCHPT_CUR: diff --git a/arch/arm64/kernel/traps.c b/arch/arm64/kernel/traps.c index b7fed33981f7..56e1782fcf54 100644 --- a/arch/arm64/kernel/traps.c +++ b/arch/arm64/kernel/traps.c @@ -501,8 +501,12 @@ NOKPROBE_SYMBOL(do_undefinstr); void do_bti(struct pt_regs *regs) { - BUG_ON(!user_mode(regs)); - force_signal_inject(SIGILL, ILL_ILLOPC, regs->pc, 0); + if (user_mode(regs)) { + force_signal_inject(SIGILL, ILL_ILLOPC, regs->pc, 0); + return; + } + + die("Oops - BTI", regs, 0); } NOKPROBE_SYMBOL(do_bti); From patchwork Fri Sep 2 00:15:51 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: D Scott Phillips X-Patchwork-Id: 12963447 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 BAED0ECAAD2 for ; Fri, 2 Sep 2022 00:17:32 +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=Sjlu6VrnFKi9mYmIYYPzgE5hOEOcf1igvRvotXPwcWY=; b=FW8KZuAO2dVvSP j9oArN9gH8ERBfFkjoPckk44e46qRiWhtIglKugF9SFuFZTbglrP7E7Axxtp8LV9VAO2Hv4zAvRNo Fd3a31yEzkaVse90i/4fih0aCrOHdlUnB2NX8nkg3z17xa+cCX+n6Ig9wC+YJ8Eya+60etfAScuTL fxKuCHrvz85u4ae9OaaZweXkXjNjblszuwzNwaXtdc8aJLBew2Ia5T0QSeMRk5g4Psah12SyexrZe WgGhQ6m+RVyZ9Q0TUwcVjo5qdfHgs2hA7KpS/xgXWA9gmGUb3UH1k52ZKRmXzgm+Sgo2mjwxAd4LG thjm2HFCClYJcSoNm+qQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oTuM9-00G5Nw-17; Fri, 02 Sep 2022 00:16:21 +0000 Received: from mail-dm3nam02on2094.outbound.protection.outlook.com ([40.107.95.94] helo=NAM02-DM3-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1oTuLt-00G5LK-3w for linux-arm-kernel@lists.infradead.org; Fri, 02 Sep 2022 00:16:06 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=fNmQqgpRJmy5cd0Mf5RSHzHQOJxIf+S7NniTMPM64AeXO9NTzIIq5qK1H4BayhimMh9RR3BtcsRZJvq1H8pBVI2T2JQ9hKBBzk+C3XE83FFj2xr+bHvMPjmi4n2PmENXNz/0HOv00k7OiJ0LzpjQbN4atEZbMH2nRavJqvfCL/QmIWtk+6S0lNgZD9JFvszOtCM8FggTkPK1apNPIhuZF/4Xo381yikNQbSmqyteGarUFexDBnafeaIQ2HjK6UZOYcuD3LE8EwHZlm8TgkT96s8E+msAMCzeeFk7M6Vr+5flp5CKZ8hkys0g6SU8sSrB6AqxpbcHP3kZC5osaS59kw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=C6EESysCcmiFVCatty5Ox/HOZznDbb0D4tPOMcCe6Ak=; b=K1m4wDk10bLHFdOBCBntntkEGR0vdd4vfsHGO0aYii24CKSMOEk6IPOL+XPurqeoqYm9dVcK8/awO+hlq/av5zLcyhaEGqDE0lhFvaTJNuVV5b4zT3wh55vIt9Ua0xPKiN+R1I5ozCiJNpNQJtzLIgR1MALKWdg87Ak4kWm/hvYDPT3lU+G2OyeY4AJK1FuVO+nMuP7ub9gcQz/eOki4OvvQSgVOZGv+/wJkqabaQCZAZ9qcHgFQoHgEyKkU0CVLXhoOO0xxl9j+GG1hOEx2vIMDypCzuGxUK6UTNzTV4/ZiJfA5Ldywcqh+0axL+O6KTa9T0SLNqAu748kuxSvHEw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=os.amperecomputing.com; dmarc=pass action=none header.from=os.amperecomputing.com; dkim=pass header.d=os.amperecomputing.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=os.amperecomputing.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=C6EESysCcmiFVCatty5Ox/HOZznDbb0D4tPOMcCe6Ak=; b=JKVyKJ2I5thJ4MgRnATfezEC73h1qCCnphoDq2EKk08+Jev0U2wpD1deXfyXx2kR1+9bZD0Y2qVydd526/j7GZAvHgV2XAhSa1V8ZwKtig5ROl5+J2GFHLYF33Eyuay2PJ6uAXO4FDChDZnCeBZZNBWW4yrEc2fm0VfOGhEUp68= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=os.amperecomputing.com; Received: from MWHPR0101MB2893.prod.exchangelabs.com (2603:10b6:301:33::25) by DS7PR01MB7830.prod.exchangelabs.com (2603:10b6:8:7d::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5566.21; Fri, 2 Sep 2022 00:16:02 +0000 Received: from MWHPR0101MB2893.prod.exchangelabs.com ([fe80::a82f:4278:a97f:2c29]) by MWHPR0101MB2893.prod.exchangelabs.com ([fe80::a82f:4278:a97f:2c29%4]) with mapi id 15.20.5566.016; Fri, 2 Sep 2022 00:16:02 +0000 From: D Scott Phillips To: Mark Brown , linux-arm-kernel@lists.infradead.org Cc: Catalin Marinas , Will Deacon , patches@amperecomputing.com Subject: [PATCH v3 2/2] arm64: Work around missing `bti c` in modules Date: Thu, 1 Sep 2022 17:15:51 -0700 Message-Id: <20220902001551.2349544-3-scott@os.amperecomputing.com> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220902001551.2349544-1-scott@os.amperecomputing.com> References: <20220902001551.2349544-1-scott@os.amperecomputing.com> X-ClientProxiedBy: CH2PR18CA0041.namprd18.prod.outlook.com (2603:10b6:610:55::21) To MWHPR0101MB2893.prod.exchangelabs.com (2603:10b6:301:33::25) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: d9f3e4ed-9c08-4a69-1dea-08da8c785188 X-MS-TrafficTypeDiagnostic: DS7PR01MB7830:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Q4A/cYGiMWHb7Rr1DA/n4NqVWv8KJcYWMEbNDL1b6/8ouE1sr+H3vhTUhnDqWtHO32qy5vn+0ax67JAElFgZZymg7JNZc+2A1sa4fYb4ashBw4hZv7xVa5hRnd6T+6IOB5Av6VcQnJM2EWsufAv8XM+nkmYe2Afl1gOtPBE91fMvo4xx9ivVYloujcAA38cH7tRdvySSUohuTKSI6YEXT75Mm8LuAOcjfgcAG9dDywfOT6pL2nhRQKGCqbnvmQT0E5ftsnEiyB7gE8qXAe0b/4UK9cJwEsyrLvnIoF4YSmb5ylVQ88tOUtOGFR/B8dRrfCO4SOdObueag8xju/s6Ng1IYtOByyrSZ65ZiEZNoU0cBZnh9fAhJIr7Ys8z3bzkKe0tKuDg6l0z3qE8WNdyT/PgEF4mZPG8ip9+4soNfW/JT2tuuB7WW7u/8lPWk0BMYKNM9P5mh//RtY9OtLy4LZJ3KGu4zo8OQOyynyE6PDIAQ3V12DPKr9lmGHfpk/QQ0sgUQSK9+b+C/S62t1geLvou+DJiVzBMonITDnusnQaeOVHsEfQaHdxK5zXK9azEBUiVTlHo4r4T6m5XXB4wYn3Mug5X0ZIuEK2AYFW4H0le3AE5CXndxJQ/jZEZQhKTffEQWsZrlV/+rjfZOvhzKIeL+vK5dAQupZ/DpFRP3YKMgGcnVRyUGpbtCLItI2QAjsfojf2UPcArdpODVtwXBt+EkasTC+2jhzNHviJAYygipVHXBSFK27tcuifCGwGnI+4rarcqoASTx5uPsN28qPYthbnU1BIi5RVLc+2ZzS+PfejW2d+pdkY6NDwRwVe3 X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:MWHPR0101MB2893.prod.exchangelabs.com;PTR:;CAT:NONE;SFS:(13230016)(4636009)(39850400004)(346002)(136003)(366004)(376002)(396003)(8936002)(66556008)(66476007)(8676002)(5660300002)(2906002)(4326008)(66946007)(316002)(54906003)(2616005)(52116002)(478600001)(6512007)(6506007)(41300700001)(107886003)(6666004)(966005)(26005)(38350700002)(186003)(6486002)(1076003)(86362001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zw8Y3giDYnPmm8alevDezyD8c2X2ePgoZQvJW9OZ5DA1YSbJobVo76NONe9fbuoVLP6y6TJsZfCK14RTKAMwvGRcaWIA+cchITIXzvrmlbr1QPcLRTLH5UyTlBiEFI4lYHuF8Bh2sE+IYmw4RAAUON4SB4gAY16//5bZNCXCRJmIK6gFjIm8e9FAwQOLsRrvK/f2eOvBkjCg/TFQDTERXIwwBcJOtVcCglzdnzQ6slpn9Uky1rbz77nZzI9ETXdJ9RQHptLuSQij6QmI1/g6sP7KgrpvV03+0jRnCJA92ldFRYT7ByNFcR526iPgWxyN2YtLp/hp5iDUB0FU7+GXx2uR6GadtlVf3eJRgq9UAfWdHoFIno7MftrDfM1zVxGpZ9qm9KT2E0rsKhxixImQBoSQ/9UbBO5cBk2w5vqJByOX75IUKbgZg+UTULEyZ/oaAx4/LlGRHYMyxO8L5OECZ3RUE4spQkQVFVqIwNfAHhGGHMWqiWfOCBnhoMe6Q2PfY8PQlpN29D5TZPyPbYDzMNel+YdI4x8bnqDJjcYiSbpWnrqCBlRs2Mvyqt9xLWm0G7yjqMeyxVUMFi+097lZ2hf1YPFdjZgZp60TUpOHaaFKmHqFv4PHMH8dkQ== X-OriginatorOrg: os.amperecomputing.com X-MS-Exchange-CrossTenant-Network-Message-Id: d9f3e4ed-9c08-4a69-1dea-08da8c785188 X-MS-Exchange-CrossTenant-AuthSource: MWHPR0101MB2893.prod.exchangelabs.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Sep 2022 00:16:02.1622 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3bc2b170-fd94-476d-b0ce-4229bdc904a7 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: PQs0jEZEGzXiaa7OkUO2xfJ8x6J/SBrM++C10E9+SESK2dhA26rFiSNvMdtE1W6uUIZOE6qWoo7sg48/YPH7Fs3oCFGxOe2aPr/tU/4dRC2BPrXmOQCrgnqynLNpdGi/ X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS7PR01MB7830 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220901_171605_182318_1E86269C X-CRM114-Status: GOOD ( 13.81 ) 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: , 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 all callers reach the function through a direct branch[1]. In the case of cross-section calls (like __init to non __init), a thunk may be inserted which uses an indirect branch. If that happens, the first instruction in the callee function will result in a Branch Target Exception due to the missing `bti c`. Handle Branch Target Exceptions which happen in the kernel due to module calls from __init to non-__init by clearing PSTATE.BTYPE and resuming. [1]: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106671 Signed-off-by: D Scott Phillips Reviewed-by: Mark Brown --- arch/arm64/Kconfig | 3 +++ arch/arm64/kernel/traps.c | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig index 9fb9fff08c94..8038842fa6b9 100644 --- a/arch/arm64/Kconfig +++ b/arch/arm64/Kconfig @@ -1896,6 +1896,9 @@ config ARM64_BTI_KERNEL is enabled and the system supports BTI all kernel code including modular code must have BTI enabled. +config CC_HAS_CROSS_SECTION_BTI_MISSING + def_bool CC_IS_GCC # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106671 + config CC_HAS_BRANCH_PROT_PAC_RET_BTI # GCC 9 or later, clang 8 or later def_bool $(cc-option,-mbranch-protection=pac-ret+leaf+bti) diff --git a/arch/arm64/kernel/traps.c b/arch/arm64/kernel/traps.c index 56e1782fcf54..315a305a4f1d 100644 --- a/arch/arm64/kernel/traps.c +++ b/arch/arm64/kernel/traps.c @@ -501,11 +501,46 @@ NOKPROBE_SYMBOL(do_undefinstr); void do_bti(struct pt_regs *regs) { + struct module *mod; + if (user_mode(regs)) { force_signal_inject(SIGILL, ILL_ILLOPC, regs->pc, 0); return; } + /* + * GCC does not insert a `bti c` instruction at the beginning + * of a function when all callers reach the function through a + * direct branch. In the case of cross-section calls (like + * __init to non __init), a thunk may be inserted which uses + * an indirect branch. If that happens, the first instruction + * in the callee function will result in a Branch Target + * Exception due to the missing `bti c`. + * + * https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106671 + * + * If that's the case here, clear PSTATE.BTYPE and resume. + */ + if (IS_ENABLED(CONFIG_CC_HAS_CROSS_SECTION_BTI_MISSING)) { + preempt_disable(); + mod = __module_text_address(regs->pc); + + if (mod && try_module_get(mod)) { + bool from_init; + + from_init = within_module_init(regs->regs[30], mod); + module_put(mod); + + if (from_init) { + preempt_enable(); + regs->pstate &= ~PSR_BTYPE_MASK; + return; + } + } + + preempt_enable(); + } + die("Oops - BTI", regs, 0); } NOKPROBE_SYMBOL(do_bti);