Received: by 2002:a05:6a10:7420:0:0:0:0 with SMTP id hk32csp576939pxb; Tue, 15 Feb 2022 22:38:34 -0800 (PST) X-Google-Smtp-Source: ABdhPJwNd9HqMkWypmBKy3VB00wh+Yee4GuW2cDpbu8IZLCzFlgMSOOAB7pL2I3r9stL7A2cuU9g X-Received: by 2002:a17:902:680d:b0:14d:c5df:54dc with SMTP id h13-20020a170902680d00b0014dc5df54dcmr1573173plk.0.1644993514222; Tue, 15 Feb 2022 22:38:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644993514; cv=none; d=google.com; s=arc-20160816; b=kqvruKSidRhGj5/fMC+5V2CeZMbayPlA40SMoWzb5ftOI6qrhUnmkZCJcCadECY5GZ 1/2ttLSd73RHgXPbwrep54bNemNBcyvPnmVCKNR6KmYct8S0D3FohT36DDy8PvLhYdtW 6dk42awsiNx6YjUa+TnfII0iFFQUr9YquRVnKSv+myVs3QJniQC9aR1HtxTpe31bnMjh YS/m8UitWTYG9s8XUvWukEEie+zFC6b2cfOoNaUvV7LI+S6wFYkVbaRMNYxSfEfL3AV4 +Y6bzVTcqtrG3ZhUGUiKXFoSWj6NJraFQsW8p9hYC2KJhF3PxExfu//+6xZEDJ+eCvLd SK6g== 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=STnj2ybwZv05qCjMTqaXWuXN0Sm5uRuBvdpB6J67Jg0=; b=WvViuYn4Og9cQ4BglKYWmq2/aro0BnaL1Q9Az/XvB8o5pm9g4Ze8rjQ2RwOIAPrFDT oVb/bszO1Ic7kwnUaEH+eaiDCy0RfPdHOACqbJwY5yOn6cwp6woB+ugcDHeLzvnLts2Y boX6Rd86MYFa3THbgUERghKnns9BDMbPYeVwQ29r3/9L7vET1ylgNpYiTIPLMQAjW+tX wZfJH9Ft/VsSJFineS7gFIbt17Hyj3GBNY1kdRE0OH4smkSNgDK4i/inLov4c3w92+pm BzSLMdyg6ILpZX79PIl1DJAJL3Rj5OUljSBQSgFnz6ND3wmEqrZ+Z5qFGyPKLh/dgCin CBfA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=desiato.20200630 header.b=o++5p4Uy; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id d184si4849933pgc.533.2022.02.15.22.38.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Feb 2022 22:38:34 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=desiato.20200630 header.b=o++5p4Uy; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 58F01192562; Tue, 15 Feb 2022 22:28:57 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243095AbiBOUyX (ORCPT + 99 others); Tue, 15 Feb 2022 15:54:23 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:49030 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235916AbiBOUyW (ORCPT ); Tue, 15 Feb 2022 15:54:22 -0500 Received: from desiato.infradead.org (desiato.infradead.org [IPv6:2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0972F27159 for ; Tue, 15 Feb 2022 12:54:12 -0800 (PST) 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=STnj2ybwZv05qCjMTqaXWuXN0Sm5uRuBvdpB6J67Jg0=; b=o++5p4UyKYULUAc9XC40okIKxv p9pPp+HvcJo46VATvElhowtSi+6FB7H2feZPLxDPHk1AkWihA23qMIj4IsNq9zaUTEt8913L+IM4l nFS/JGmwP1+I/zScTHdItmu7EIiDyHDpqRr6bai9qTIniHz5b5AwLu0ksN/owOGXTe0RmDtnyT0M2 Yz8euY75y/El0mSE0isb+8qiguE50bRr92wSRlFUqUhkagz9flQTo2aqXRZL2ewrEVZDtu5W8PtkN Js0Lx/dWZE7xNmwOzqAv9YOGDgjwsF3VvSnuH5L4Lc9ZHw7M404pCUPyJrlpMbDOcwqRkCZ9F/ee0 seBCiFgA==; 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 1nK4pb-00ABAC-Jx; Tue, 15 Feb 2022 20:53:52 +0000 Received: by worktop.programming.kicks-ass.net (Postfix, from userid 1000) id EC34B987956; Tue, 15 Feb 2022 21:53:49 +0100 (CET) Date: Tue, 15 Feb 2022 21:53:49 +0100 From: Peter Zijlstra To: Sami Tolvanen Cc: Joao Moreira , Kees Cook , X86 ML , hjl.tools@gmail.com, Josh Poimboeuf , andrew.cooper3@citrix.com, LKML , Nick Desaulniers , llvm@lists.linux.dev Subject: Re: [RFC][PATCH 6/6] objtool: Add IBT validation / fixups Message-ID: <20220215205349.GC23216@worktop.programming.kicks-ass.net> References: <20211122170805.338489412@infradead.org> <6ebb0ab131c522f20c094294d49091fc@overdrivepizza.com> <202202081541.900F9E1B@keescook> <202202082003.FA77867@keescook> <9ea50c51ee8db366430c9dc697a83923@overdrivepizza.com> <20220211133803.GV23216@worktop.programming.kicks-ass.net> <20220214222550.GB23216@worktop.programming.kicks-ass.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Feb 15, 2022 at 08:56:03AM -0800, Sami Tolvanen wrote: > On Mon, Feb 14, 2022 at 2:25 PM Peter Zijlstra wrote: > > On Mon, Feb 14, 2022 at 01:38:18PM -0800, Sami Tolvanen wrote: > > > I'm fine with adding a trap mode that's used by default, but having > > > more helpful diagnostics when something fails is useful even in > > > production systems in my experience. This change results in a vmlinux > > > that's another 0.92% smaller. > > > > You can easily have the exception generate a nice warning, you can even > > have it continue. You really don't need a call for that. > > Sure, but wouldn't that require us to generate something like > __bug_table, so we know where the CFI specific traps are? Yes, but since you're going to emit a retpoline, and objtool already generates a list of retpoline sites, we can abuse that. If the instruction after the trap is a retpoline site, we a CFI fail. > > > In this case the function has two indirect calls and Clang seems to > > > prefer to emit just one ud2. > > > > That will not allow you to recover from the exception. UD2 is not an > > unconditional fail. It should have an out-going edge in this case too. > > Yes, CFI failures are not recoverable in that code. In fact, LLVM > assumes that the llvm.trap intrinsic (i.e. ud2) never returns, but I > suppose we could just use an int3 instead. I assume that's sufficient > to stop speculation? It is. int3 is also smaller by one byte, but the exception is already fairly complicated, but I can see if we can make it work. > > Also, you really should add a CS prefix to the retpoline thunk call if > > you insist on using r11 (or any of the higher regs). > > I actually didn't touch the retpoline thunk call, that's exactly the > code Clang normally generates. Yeah, and it needs help, also see: https://lore.kernel.org/lkml/20211119165630.276205624@infradead.org/ Specifically, clang needs to: - CS prefix stuff the retpoline thunk call/jmp; - stop doing conditional indirect tail-calls.