From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 269A92C99 for ; Tue, 2 Nov 2021 21:48:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; 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=Y4e5G7N0rSCI/bB/4KF9vQwtKks3I0Qizmban8wLh88=; b=deg62C+MyuBRwQgACHwdkh+TpH rLxXHgp2kCN5sxwJAwtlpaMXRzaIEXFSfax93Azl8g+nUE4eW4As40ibGij99hMe3M+VHiZxLfWoZ jQwZB/FHQPaDO1mTBz6jKM435wHVvQrUauh9YmdsLjQOVVhs1j1z39SyLEU1yJbO6dwmi+5UaHl9N kkYd+La1bPtsk3Pb9/xEJ+Ud5JLYk+yTmNGSJaxwnNCFwGnVGvla6t74ZbQkukKoQYvfyRmvutpYW uZSXv5PaA5Xl0FabbBzC3gA0tGodLB8BPLaHvcy8vufb+wnozGDTg9xTrdvIgLqIZcyusXKDRbIGZ XUK5AWIw==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=worktop.programming.kicks-ass.net) by desiato.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1mi1dj-00DpCo-PG; Tue, 02 Nov 2021 21:48:20 +0000 Received: by worktop.programming.kicks-ass.net (Postfix, from userid 1000) id 68039984CD2; Tue, 2 Nov 2021 22:48:19 +0100 (CET) Date: Tue, 2 Nov 2021 22:48:19 +0100 From: Peter Zijlstra To: Ard Biesheuvel Cc: Sami Tolvanen , Mark Rutland , X86 ML , Kees Cook , Josh Poimboeuf , Nathan Chancellor , Nick Desaulniers , Sedat Dilek , Steven Rostedt , linux-hardening@vger.kernel.org, Linux Kernel Mailing List , llvm@lists.linux.dev, joao@overdrivepizza.com Subject: Re: [PATCH] static_call,x86: Robustify trampoline patching Message-ID: <20211102214819.GZ174703@worktop.programming.kicks-ass.net> References: <20211101090155.GW174703@worktop.programming.kicks-ass.net> Precedence: bulk X-Mailing-List: llvm@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: On Tue, Nov 02, 2021 at 07:18:53PM +0100, Ard Biesheuvel wrote: > > The range check isn't fundamental to CFI, having a check is the > > important thing AFAIU. > > Agreed. If the call site has a direct branch, it doesn't need the range check. That, from the earlier email: | And have the actual indirect callsite look like: | | # r11 - &foo | ALTERNATIVE_2 "cs call __x86_indirect_thunk_r11", | "cs call __x86_indirect_cfi_deadbeef", X86_FEATURE_CFI | "cs call __x86_indirect_ibt_deadbeef", X86_FEATURE_IBT So the callsite has a direct call to the hash-specific and cfi-type specific thunk, which then does an (indirect) tail-call. The CFI one does the hash check in the thunk and jumps to the function proper, the IBT one on does it in the landing-pad. The !CFI one ignore it all and simply does an indirect call (retpoline aided or otherwise) to the function proper -- in which case we can free all the thunks.