Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp82841pxb; Mon, 8 Nov 2021 10:06:53 -0800 (PST) X-Google-Smtp-Source: ABdhPJx++k858fcXfkzrk/2uVZVHuVPOSuTBiYMYHkMe4X6tLkkKSSL6w2cp8PIq8Vr8MCbs5ViV X-Received: by 2002:a05:6602:1645:: with SMTP id y5mr701801iow.35.1636394813077; Mon, 08 Nov 2021 10:06:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1636394813; cv=none; d=google.com; s=arc-20160816; b=k7Wr6x0xdNsY72Uk9ZPiwBe21+X9XpSsCwt18khdFT55smQR1FWjeNF6S2FJqgXol1 vVSpqxVO9uRrRMiNmoz7d9aSzRB7xy9esjSWGR0d8DICUyoQAgaKTAtGcAiRNmiFJqIs 4szqXMUzj5UiCe9P4nTdw8H0Ru9stA3WVJaCuUougdpBb8ovQf9uWpDGBk3qveR788Eu dlOzR7wdjqVIOJMXA1p2V4O5HuTjQXtE9dp0qd6UTQuFUiD/icHLOUApOfe9kK8s7wLb I1dagHSQYZLVf0Fdh+QMlQ3i0TbynLyItaqlhAz6gQndGIr+YAl63gBwRINjE+wYy61E gx5A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=iGvLUtwPbdRsAfeVJOcAVPj61fXiSzd4nOb67Hfr9sw=; b=YGE522WGFzHLBMOWfV5JMf6vNJGX3RhPLVme2FD++OkzspNOKvOoWRwTf5ZbtNr/P/ M8vThadT/x3j4/nY96srYLJM3ofPGPo/Ahd/8C7GKgSBRBACn1No+AwGOwQy4TNslWda cOW1blLbgXYiIgrB6R0JGAUNz/psI8eWYe1XXw0gMNMkuHjHrhR2oXliC9zLwEV0r9YA Y20EP6IMwHaP9nJX+Sd/9ne7zg/Eb7pGsCAhdQCigY1YSgEHEoBg3enPoeRV+f2cbPQL xBjw3B4WxDiL5SHheNjTbR32ohok5CwAmlZHuwUXfyvICGWsYWOU6ntBj2D+2wsFWvRn ZN9g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=F+BJuQ+I; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id t14si18140738jag.43.2021.11.08.10.06.34; Mon, 08 Nov 2021 10:06:53 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=F+BJuQ+I; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239304AbhKHLz3 (ORCPT + 99 others); Mon, 8 Nov 2021 06:55:29 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33302 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231401AbhKHLz2 (ORCPT ); Mon, 8 Nov 2021 06:55:28 -0500 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A77C3C061570 for ; Mon, 8 Nov 2021 03:52:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=iGvLUtwPbdRsAfeVJOcAVPj61fXiSzd4nOb67Hfr9sw=; b=F+BJuQ+IrbziNIXT9xJu5L+UqB lraLF91ieb3EqV159cAYbdxPh16m+cadbOWiwl9jcekGoedIewYhnqSHhhBMR7qmFo6cNLMrEiTOH neMlc6vd2JUNmiVxh1iTSzLBHXGzM61RRdXD67CWRqKR3FZe0cFI6bFgVawRKX0mfGI9E1PFMJh2A FQkh+4azXrnUjFKS64DvsnAhK1VH8e2rMEzUhJ9/d7EDudfuZ9U0/a0FfeOZOhFvyNDTwD4qDu9GW guMvF6BRN4pe336JdFGkbJ6qabesfBb0AfOrYp4Ps9LBBs95b486GrznQjoZzSdl8F7ZQQyOJdQgk QpUumMpQ==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=noisy.programming.kicks-ass.net) by casper.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1mk3CR-0009SK-Fj; Mon, 08 Nov 2021 11:52:32 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id 8764830030B; Mon, 8 Nov 2021 12:52:31 +0100 (CET) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 5EFD4202A0132; Mon, 8 Nov 2021 12:52:31 +0100 (CET) Date: Mon, 8 Nov 2021 12:52:31 +0100 From: Peter Zijlstra To: Ard Biesheuvel Cc: Linux ARM , Linux Kernel Mailing List , Mark Rutland , Quentin Perret , Catalin Marinas , James Morse , Will Deacon , Frederic Weisbecker , Kees Cook , Sami Tolvanen , Andy Lutomirski , Josh Poimboeuf , Steven Rostedt Subject: Re: [PATCH v6 2/2] arm64: implement support for static call trampolines Message-ID: References: <20211105145917.2828911-1-ardb@kernel.org> <20211105145917.2828911-3-ardb@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Nov 08, 2021 at 12:29:04PM +0100, Ard Biesheuvel wrote: > On Mon, 8 Nov 2021 at 11:23, Peter Zijlstra wrote: > > > +static void *strip_cfi_jt(void *addr) > > > +{ > > > + if (IS_ENABLED(CONFIG_CFI_CLANG)) { > > > + void *p = addr; > > > + u32 insn; > > > + > > > + /* > > > + * Taking the address of a function produces the address of the > > > + * jump table entry when Clang CFI is enabled. Such entries are > > > + * ordinary jump instructions, preceded by a BTI C instruction > > > + * if BTI is enabled for the kernel. > > > + */ > > > + if (IS_ENABLED(CONFIG_ARM64_BTI_KERNEL)) > > > + p += 4; > > > > Perhaps: > > if (aarch64_insn_is_bti(le32_to_cpup(p))) > > That instruction does not exist yet, and it begs the question which > type of BTI instruction we want to detect. Yeah, I actually checked, but I figured the intent was clear enough. I figured all of them? > > p += 4; > > > > Perhapser still, add: > > else > > WARN_ON(IS_ENABLED(CONFIG_ARM64_BTI_KERNEL)); > > > > There's already a WARN() below that will trigger and return the > original address if the entry did not have the expected layout, which > means a direct branch at offset 0x0 or 0x4 depending on whether BTI is > on. > > So I could add a WARN() here as well, but I'd prefer to keep the one > at the bottom, which makes the one here slightly redundant. Sure, that works. The slightly more paranoid me would tell you that the code as is might match something you didn't want it to. Eg. without the extra WARN, you could accidentally match a B instruction without BTI on a BTI kernel build. Or your initial version could even match: RET; B ponies; on a BTI kernel. My point being that since we're not exactly sure what a future compiler will generate for us here, we'd best be maximally paranoid about what we're willing to accept. > > > + > > > + insn = le32_to_cpup(p); > > > + if (aarch64_insn_is_b(insn)) > > > + return p + aarch64_get_branch_offset(insn); > > > + > > > + WARN_ON(1); > > > + } > > > + return addr; > > > +} > > > > Also, can this please have a comment decrying the lack of built-in for > > this? > > Sure. Which ties in with that. Once it's a built-in, we can be sure the compiler knows what it needs to do to undo it's own magic.