Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp902005iob; Wed, 4 May 2022 10:15:38 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxo+pdTO6hm6ri7EfIHvSNahRNcHTsuIKO0qiAhdZeOrI1ezMCW20/nzewBe7TlIqf6CVOB X-Received: by 2002:a17:907:3d91:b0:6df:a01c:f7cd with SMTP id he17-20020a1709073d9100b006dfa01cf7cdmr21122249ejc.255.1651684538016; Wed, 04 May 2022 10:15:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651684538; cv=none; d=google.com; s=arc-20160816; b=nQQlhPLomIdHUK/pgv3Es9TU+S6Sfa20phxxO5YBkOHj8oKE3QHx/jNWjkcZdHOEoX caDwTezjXpM0GheaJcBkDJA1Lp01GUg3y0GDCME0j9rgVqXAKuemwVFG3Iu4tXLcop/d BkDOiQZDIDmKdlkSAPcnaSafYqxabOtQtXXk1ktZhSUQcEeGMnbZO8avToTWaf6ZO7ZV RipRR9bgiVorSp2OyiQC1R19g7XNcAW0L6sX1uPw3haQf+43SIDEv5ph5ZJwCNNBtrzS BIUgyclRCQfnO5F4nZt0srz8/Sp6CL+N+Td5n0iNbuWKoCiMiklhx2FsdzqfKeVyguLm y3uA== 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=cTSIQdlg91RSK+na/NVKBd/Ax/ZBULg9Q/4Gx74hmBE=; b=suNVgc732oBhghyTaKOleF9Jvt8ALB5+tQ+FeFH0Wucv/u0IzUobJcSBFeoxD/Wux2 cLJLxKGGdX8976Ce0msj95gnZznIxngKUXFvaM+QQUwpcuC+TmsRZjNyAG2ceIhKS/hd 0LRCG4yoo5QW3SNU+9nX9yXHzDyTmH3CMdrAhHj+BLMjG7SuuJGmKV2q5lZIEYehIxlJ fsnXYj/frZQu5OyxEbLSzBoTUMdbN09knVlHlIUwPZWsRkqKasHHLGm2D0A4P5rl7jTr 4GuFhvyA07wYVEA28iahJHGTTwtsb8vFbM0YjNF70QI3U9mHjp2LVL7GmLuIJh+u/shz /GsQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=desiato.20200630 header.b=DJ4sRfVF; 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 fi17-20020a170906da1100b006f46a64f640si5591330ejb.863.2022.05.04.10.15.13; Wed, 04 May 2022 10:15:37 -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=desiato.20200630 header.b=DJ4sRfVF; 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 S1345530AbiEDHjq (ORCPT + 99 others); Wed, 4 May 2022 03:39:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58982 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346037AbiEDHjQ (ORCPT ); Wed, 4 May 2022 03:39:16 -0400 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 D05DB27157; Wed, 4 May 2022 00:34:37 -0700 (PDT) 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=cTSIQdlg91RSK+na/NVKBd/Ax/ZBULg9Q/4Gx74hmBE=; b=DJ4sRfVFdZHqiUR1scXw9foZfl L7yKxBEJhUhm/nN8KNGznPTfuCfQS10cTZGTZncnxpQcvHtmIibXuZIf4BWhkVTwUsXutzODCujTX 9ol5m6lfkrhF1XEjyiZyaKvorG5EUGu2bSqA/FcWM5LcriPRGK2tDMPLFNt4Lz0WYO0NKcTysvqe1 ju+XiMI9AoOmYgIRswBct3J0G8rSnfT/S/lYzMGoHVAa5UY/87fStP27Br/E5nPYN5Sh2OitDpTAx CPy06b7r2hzVIO98a1HVNwlRWcw0xPwXqpEILLaa17u5ZiJGLI0PMYOMFXL3CPPGYkmCdK5kE6dIL wBOgZgjg==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=noisy.programming.kicks-ass.net) by desiato.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1nm9Wd-00B171-EK; Wed, 04 May 2022 07:34:19 +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 (4096 bits)) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id 7BD913004B5; Wed, 4 May 2022 09:34:18 +0200 (CEST) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 3EF7E2029A1DC; Wed, 4 May 2022 09:34:18 +0200 (CEST) Date: Wed, 4 May 2022 09:34:18 +0200 From: Peter Zijlstra To: Peter Collingbourne Cc: Sami Tolvanen , Kees Cook , Mark Rutland , Josh Poimboeuf , Will Deacon , Catalin Marinas , Nathan Chancellor , Nick Desaulniers , Joao Moreira , Sedat Dilek , Steven Rostedt , LKML , X86 ML , linux-hardening@vger.kernel.org, linux-arm-kernel , llvm@lists.linux.dev Subject: Re: [RFC PATCH 00/21] KCFI support Message-ID: References: <20220429203644.2868448-1-samitolvanen@google.com> <202204291545.47C6A97EA2@keescook> 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 Tue, May 03, 2022 at 03:35:34PM -0700, Peter Collingbourne wrote: > On Mon, May 2, 2022 at 1:02 PM Peter Zijlstra wrote: > > > > On Mon, May 02, 2022 at 08:22:57AM -0700, Sami Tolvanen wrote: > > > > > > Anyway, I think I hate that __builtin, I'd *much* rather see a variable > > > > attribute or qualifier for this, such that one can mark a function > > > > pointer as not doing CFI. > > > > > > > > I simply doesn't make sense to have a builtin that operates on an > > > > expression. The whole thing is about indirect calls, IOW function > > > > pointers. > > > > > > I also thought an attribute would be more convenient, but the compiler > > > folks prefer a built-in: > > > > > > https://reviews.llvm.org/D122673 > > > > That seems to mostly worry about C++ things (overload sets, template > > specialization, name mangling) we kernel folks don't seem to much care > > about. > > > > I'll stick with saying type system makes more sense to me though. > > I'd say it's not only the C++ issues but more the "action at a > distance" that's implied by having this be part of the type system. > With this being in the function type it's hard to tell whether any > particular call will have CFI disabled, without needing to go and look > at how the function pointer is defined. Look at how we use volatile: *(volatile int *)(&foo) we don't use volatile on actual variable definitions (much), but instead cast it in at the usage site. Same can be done with this if so desired. > On the other hand, if we > explicitly mark up the calls with CFI disabled, the code becomes > easier to audit (think Rust "unsafe" blocks). I don't know any Rust. To me Rust still looks like line noise. > Does it seem any better to you to have this be marked up via the > function expression, rather than the call? The idea is that this would > always compile to a check-free function call, no matter what "func" > is: > > __builtin_kcfi_call_unchecked(func)(args) > > We already have this, to some degree, with KCFI as implemented: CFI > checks are disabled if the function expression refers to a declared > function. The builtin would allow overriding the decision to also > disable CFI checks for function expressions that use the builtin. It > also wouldn't preclude a type based system later on (the builtin would > become effectively a cast to the "unchecked" type). That's still a bit naf; you've effectively made that builtin a type-cast.