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 X-Spam-Level: X-Spam-Status: No, score=-8.2 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4782FC433E0 for ; Wed, 17 Jun 2020 09:07:22 +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 024832070A for ; Wed, 17 Jun 2020 09:07:22 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="RKL6qL8p" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 024832070A Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=arm.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+infradead-linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=BgHwMcyv3H6ADmIzReC7nYthKazNp6AABWNGCPIPsDk=; b=RKL6qL8p5k6dan QwIYUpH7JT862Jxk8OR8ZFA4pofsUwlUPAKcQLuPYvEiBBDyjUvSILF93g4Jl2RkDMef04nA3czuP 4FfgntKMM2v1Jx3Ilhp/VDkXstpH0BUw4M2uiAMPq3QU5jpEF/m7YHrw5eL8lqNlEq4FbWNTjMoNX lNYvZiRgPkffq/qYtXCojaPi5V/WBbVtbuaoHcprM0j8sU+tpG7VZQnWXLJbQpdwGqClj5N0Rewug Zq+/LIeMlwYuvgKfi4O6tG7RV4A2XbL3QlqguYTnEeCxDk5LTs3Nwcpm6TZsZdAi09DS9dX56lbrM O4anNykILDDler8zzp3Q==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jlU2S-0005Pk-Ux; Wed, 17 Jun 2020 09:07:20 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jlU1Y-0004cI-Iq for linux-arm-kernel@lists.infradead.org; Wed, 17 Jun 2020 09:06:26 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 0602B31B; Wed, 17 Jun 2020 02:06:22 -0700 (PDT) Received: from arm.com (usa-sjc-imap-foss1.foss.arm.com [10.121.207.14]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id C49173F6CF; Wed, 17 Jun 2020 02:06:20 -0700 (PDT) Date: Wed, 17 Jun 2020 10:06:18 +0100 From: Dave Martin To: Will Deacon Subject: Re: [PATCH] arm64: bti: Require clang >= 10.0.1 for in-kernel BTI support Message-ID: <20200617090616.GO25945@arm.com> References: <20200616183630.2445-1-will@kernel.org> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20200616183630.2445-1-will@kernel.org> User-Agent: Mutt/1.5.23 (2014-03-12) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200617_020624_734370_45F3B938 X-CRM114-Status: GOOD ( 19.28 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Tom Stellard , Nick Desaulniers , clang-built-linux@googlegroups.com, Mark Brown , Nathan Chancellor , kernel-team@android.com, linux-arm-kernel@lists.infradead.org, Daniel Kiss Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+infradead-linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Tue, Jun 16, 2020 at 07:36:30PM +0100, Will Deacon wrote: > Unfortunately, most versions of clang that support BTI are capable of > miscompiling the kernel when converting a switch statement into a jump > table. As an example, attempting to spawn a KVM guest results in a panic: > > [ 56.253312] Kernel panic - not syncing: bad mode > [ 56.253834] CPU: 0 PID: 279 Comm: lkvm Not tainted 5.8.0-rc1 #2 > [ 56.254225] Hardware name: QEMU QEMU Virtual Machine, BIOS 0.0.0 02/06/2015 > [ 56.254712] Call trace: > [ 56.254952] dump_backtrace+0x0/0x1d4 > [ 56.255305] show_stack+0x1c/0x28 > [ 56.255647] dump_stack+0xc4/0x128 > [ 56.255905] panic+0x16c/0x35c > [ 56.256146] bad_el0_sync+0x0/0x58 > [ 56.256403] el1_sync_handler+0xb4/0xe0 > [ 56.256674] el1_sync+0x7c/0x100 > [ 56.256928] kvm_vm_ioctl_check_extension_generic+0x74/0x98 > [ 56.257286] __arm64_sys_ioctl+0x94/0xcc > [ 56.257569] el0_svc_common+0x9c/0x150 > [ 56.257836] do_el0_svc+0x84/0x90 > [ 56.258083] el0_sync_handler+0xf8/0x298 > [ 56.258361] el0_sync+0x158/0x180 > > This is because the switch in kvm_vm_ioctl_check_extension_generic() > is executed as an indirect branch to tail-call through a jump table: > > ffff800010032dc8: 3869694c ldrb w12, [x10, x9] > ffff800010032dcc: 8b0c096b add x11, x11, x12, lsl #2 > ffff800010032dd0: d61f0160 br x11 > > However, where the target case uses the stack, the landing pad is elided > due to the presence of a paciasp instruction: > > ffff800010032e14: d503233f paciasp > ffff800010032e18: a9bf7bfd stp x29, x30, [sp, #-16]! > ffff800010032e1c: 910003fd mov x29, sp > ffff800010032e20: aa0803e0 mov x0, x8 > ffff800010032e24: 940017c0 bl ffff800010038d24 > ffff800010032e28: 93407c00 sxtw x0, w0 > ffff800010032e2c: a8c17bfd ldp x29, x30, [sp], #16 > ffff800010032e30: d50323bf autiasp > ffff800010032e34: d65f03c0 ret > > Unfortunately, this results in a fatal exception because paciasp is > compatible only with branch-and-link (call) instructions and not simple > indirect branches. > > A fix is being merged into Clang 10.0.1 so that a 'bti j' instruction is > emitted as an explicit landing pad in this situation. Make in-kernel > BTI depend on that compiler version when building with clang. > > Cc: Nick Desaulniers > Cc: Mark Brown > Cc: Nathan Chancellor > Cc: Tom Stellard > Cc: Daniel Kiss > Link: https://lore.kernel.org/r/20200615105524.GA2694@willie-the-truck > Signed-off-by: Will Deacon > --- > arch/arm64/Kconfig | 2 ++ > 1 file changed, 2 insertions(+) > > diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig > index 31380da53689..4ae2419c14a8 100644 > --- a/arch/arm64/Kconfig > +++ b/arch/arm64/Kconfig > @@ -1630,6 +1630,8 @@ config ARM64_BTI_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://reviews.llvm.org/rGb8ae3fdfa579dbf366b1bb1cbfdbf8c51db7fa55 > + depends on !CC_IS_CLANG || CLANG_VERSION >= 100001 > depends on !(CC_IS_CLANG && GCOV_KERNEL) > depends on (!FUNCTION_GRAPH_TRACER || DYNAMIC_FTRACE_WITH_REGS) > help FWIW: Acked-by: Dave Martin I've not tried to reproduce this myself, but the problem description and proposed solution seem perfectly plausible, given how BTI works. Cheers ---Dave _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel