Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp3336051iob; Mon, 16 May 2022 19:51:11 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxqG3MtbqTGlXmKQaLlXZ6YpdD/De9nMA3JuIVtEDustZX2pxbXNvdpPMgavIP5N0/d1INh X-Received: by 2002:a17:902:a705:b0:156:9cc5:1d6f with SMTP id w5-20020a170902a70500b001569cc51d6fmr20111550plq.66.1652755871263; Mon, 16 May 2022 19:51:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652755871; cv=none; d=google.com; s=arc-20160816; b=LCCBeHrTHL/GYjjzM8Hlpt/VMF6yYHvVxCWShWvp0OPpOfvswarJVZFaCxbJCKEXkL N8irdK4pHcqcWHrLK3GCsLSATdAJWf8z+RNyzc+IiI7sV2QXDFEcFW8X9IvwkvSlSrsY vaOknp/1nOfGOrp0hy6sFkowMPSoECwGlooa/wIMBrrID6FfBfa7zzL8vPULshfaij6W a9MqG/rmZQdjpsvLego45Tm7nxp4EE9gZ357TQ3ikx0g+SFQOcwM1sa++aGCi7JBlj4c pqOZV54rpxwFY4+QqGlRRGhk9Tq13NAiYrioXx5zGNiL7UQkM0iugJZChunZHPivaSKj 5dZQ== 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=+8+afjaY3BKlHOSP79HK/qVp1CiDmSymT4MdofQ8IZ4=; b=SP0WhkQOx+CM7hKJFTIR4c5Ur2Wru+l0iFVdbr0njgEf+dYyYxB75zGStYTl7nfRVA WaYhWIjq0dfB6iCQhFaPqNlcYBDJJksz1ihximL0vwWbgF3qm/9oVSxJn6Nr2eH7ixdF FfnDgwnzCgAVLRim3/MnHcxsseeGAHNBeFMMfjyDFXhh4fJYegJIAGvTDJZ9MI3AWU5N yyZaHybcqpVtQ+QdtxEZbppnHLcePZXG5cm6KMlxyyJNwYAJgasrmiyobo37UsXkGgyj wUtqRPxpdS8NWAaOJXGdtePocasEXMsH5LE7W/a5oPfUYABRijRrKirkPESM5FqrL5/k sTsw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=q5xCbm4U; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j2-20020a17090276c200b0015874d582f1si13492360plt.326.2022.05.16.19.50.59; Mon, 16 May 2022 19:51:11 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=q5xCbm4U; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344862AbiEPSbh (ORCPT + 99 others); Mon, 16 May 2022 14:31:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55654 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344954AbiEPSbZ (ORCPT ); Mon, 16 May 2022 14:31:25 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9502632EFB; Mon, 16 May 2022 11:31:07 -0700 (PDT) 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=+8+afjaY3BKlHOSP79HK/qVp1CiDmSymT4MdofQ8IZ4=; b=q5xCbm4UH9jAMw10q00U9nl9fj KFfw+45+4Ggx4ZuRGbGIeBDWL5TE5EcKIheQZ2HOcD65sqSiIJSKWVcm/alk5iPqH8nIHyuoX2Q1D 0aBYvGEmDA++xrFn7XpzW5GE/RMldzEZTDzod7CKCiofXw9cSy/uvAsduoZy9pzdYtPF2KMZpn4S5 Bke46GD3RlhLsRiOYndBdsYizCEF9XKawVbKWaZqVWT7Wy0StoGuSLfn2434+wBNK4FK+a7PqP+pc Pi3ws4dWkxHA7vo9Gcziiim2MLThS/eXzQRC3Ex4YQg630x8f9zgXJU6jLDJNHGDTXF/3T52t/ZUg CoLNqxyQ==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=worktop.programming.kicks-ass.net) by casper.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1nqfUX-00A7XG-Vy; Mon, 16 May 2022 18:30:50 +0000 Received: by worktop.programming.kicks-ass.net (Postfix, from userid 1000) id 4BC17980DCC; Mon, 16 May 2022 20:30:47 +0200 (CEST) Date: Mon, 16 May 2022 20:30:47 +0200 From: Peter Zijlstra To: Sami Tolvanen Cc: linux-kernel@vger.kernel.org, Kees Cook , Josh Poimboeuf , x86@kernel.org, Catalin Marinas , Will Deacon , Mark Rutland , Nathan Chancellor , Nick Desaulniers , Joao Moreira , Sedat Dilek , Steven Rostedt , linux-hardening@vger.kernel.org, linux-arm-kernel@lists.infradead.org, llvm@lists.linux.dev Subject: Re: [RFC PATCH v2 20/21] x86: Add support for CONFIG_CFI_CLANG Message-ID: <20220516183047.GM76023@worktop.programming.kicks-ass.net> References: <20220513202159.1550547-1-samitolvanen@google.com> <20220513202159.1550547-21-samitolvanen@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham 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 Mon, May 16, 2022 at 10:15:00AM -0700, Sami Tolvanen wrote: > On Mon, May 16, 2022 at 2:54 AM Peter Zijlstra wrote: > > > > On Fri, May 13, 2022 at 01:21:58PM -0700, Sami Tolvanen wrote: > > > With CONFIG_CFI_CLANG, the compiler injects a type preamble > > > immediately before each function and a check to validate the target > > > function type before indirect calls: > > > > > > ; type preamble > > > __cfi_function: > > > int3 > > > int3 > > > mov , %eax > > > int3 > > > int3 > > > function: > > > ... > > > > When I enable CFI_CLANG and X86_KERNEL_IBT I get: > > > > 0000000000000c80 <__cfi_io_schedule_timeout>: > > c80: cc int3 > > c81: cc int3 > > c82: b8 b5 b1 39 b3 mov $0xb339b1b5,%eax > > c87: cc int3 > > c88: cc int3 > > > > 0000000000000c89 : > > c89: f3 0f 1e fa endbr64 > > > > > > That seems unfortunate. Would it be possible to get an additional > > compiler option to suppress the endbr for all symbols that get a __cfi_ > > preaamble? > > What's the concern with the endbr? Dropping it would currently break > the CFI+IBT combination on newer hardware, no? Well, yes, but also that combination isn't very interesting. See, https://lore.kernel.org/all/20220420004241.2093-1-joao@overdrivepizza.com/T/#m5d67fb010d488b2f8eee33f1eb39d12f769e4ad2 and the patch I did down-thread: https://lkml.kernel.org/r/YoJKhHluN4n0kZDm@hirez.programming.kicks-ass.net If we have IBT, then FineIBT is a much better option than kCFI+IBT. Removing that superfluous endbr also shrinks the whole thing by 4 bytes. So I'm fine with the compiler generating working code for that combination; but please get me an option to supress it in order to save those pointless bytes. All this CFI stuff is enough bloat as it is. > > > ; indirect call check > > > cmpl , -6(%r11) > > > je .Ltmp1 > > > ud2 > > > .Ltmp1: > > > call __x86_indirect_thunk_r11 > > > > The first one I try and find looks like: > > > > 26: 41 81 7b fa a6 96 9e 38 cmpl $0x389e96a6,-0x6(%r11) > > 2e: 74 02 je 32 <__traceiter_sched_kthread_stop+0x29> > > 30: 0f 0b ud2 > > 32: 4c 89 f6 mov %r14,%rsi > > 35: e8 00 00 00 00 call 3a <__traceiter_sched_kthread_stop+0x31> 36: R_X86_64_PLT32 __x86_indirect_thunk_r11-0x4 > > > > This must not be. If I'm to rewrite that lot to: > > > > movl $\hash, %r10d > > sub $9, %r11 > > call *%r11 > > .nop 4 > > > > Then there must not be spurious instruction in between the ud2 and the > > indirect call/retpoline thing. > > With the current compiler patch, LLVM sets up function arguments after > the CFI check. if it's a problem, we can look into changing that. Yes, please fix that. Again see that same patch for why this is a problem. Objtool can trivially find retpoline calls, but finding this kCFI gadget is going to be hard work. If you ensure they're unconditionally stuck together, then the problem goes away find one, finds the other.