Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp915335iob; Wed, 4 May 2022 10:32:57 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxn7AbDFZ1kSvSixzkwFCRK0WGuKRgnIdqUuvTxDIVkNQYxcrv/mBbffvW6xr6gEvnyG8pP X-Received: by 2002:a17:902:ed82:b0:158:fef8:b501 with SMTP id e2-20020a170902ed8200b00158fef8b501mr22087849plj.47.1651685576966; Wed, 04 May 2022 10:32:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651685576; cv=none; d=google.com; s=arc-20160816; b=FFeKA3fsjRQOlAkn2lPLmU2FyB6Fav7IdSj2Bjjf8SnTA50Kkd5mFUDVZaAx+t8V2I o3hvmJZzZ+jj9hKhKk2mpQt4Qn1lxG3pthfmU1jzZ3iahuY60G4cdWRuZPLFweAzfXsv gxOI9ATQYZpGnad56xLDTf6F3cV7CLhJej0SOpxBlRkqBeFZi6yg2+M6WeNtyJkNd8VO f8Mgikj/qBgTRHyv9sgq/GOXPjVYeyp5inIJSnZfqi81Vg0vawxQP79WgC48BLsB3+Fw f5iDWZySBLd20wk+cTabtxzMVkIZX9mSLnMVAVvU0zbbcN1YBWEz9liS/20q23i+401y qwpA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=8uN3rj4E61pEiXuH0S044PiehAa3W3BMN3Lqc1kk7Uw=; b=Xj3X0fMyp9UOFwZAaC1JLA9KC6FZ4AGTSs6WAaaHfZqEfuXWhPzmDVPw6LEVnWXgv1 ZUocLVULB4BoZbpVs9/p1uW9IsbccvCJrJ3If1N9enUy2SsYpIxVEovHgyfoZgx5+OGg cqT3DqgXT3yy7CAobyB8CCiWZH7CVnRhBQC3OB9d6RGiai7dp/OyysS4UrDncZgtsVQm Tu47W2mOkGLCNtl8D+f+iQ1AfNbPsyqUpfmzmk2JYFkKEvmf+APSlSQrZEJAfp60ApqF T8lnpCOG3bG1OlC+F+hhYH4zPSE4p4mu8yKzlWhp2VDu6eV35jXlkdnyx1zZhK3sskUh DV5w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=Ue8FeaYY; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id k1-20020a056a00168100b004fa3a8dffc4si19350230pfc.123.2022.05.04.10.32.39; Wed, 04 May 2022 10:32:56 -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=@google.com header.s=20210112 header.b=Ue8FeaYY; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243690AbiECWjY (ORCPT + 99 others); Tue, 3 May 2022 18:39:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58130 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230073AbiECWjV (ORCPT ); Tue, 3 May 2022 18:39:21 -0400 Received: from mail-vs1-xe2b.google.com (mail-vs1-xe2b.google.com [IPv6:2607:f8b0:4864:20::e2b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A76EC427DB for ; Tue, 3 May 2022 15:35:46 -0700 (PDT) Received: by mail-vs1-xe2b.google.com with SMTP id c62so17844885vsc.10 for ; Tue, 03 May 2022 15:35:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=8uN3rj4E61pEiXuH0S044PiehAa3W3BMN3Lqc1kk7Uw=; b=Ue8FeaYYp63Oq+H4NMZb+pBRhFnk/iofdWy5gXeIg5QTwAVaQhcPh7NJMycsbGfWZE Fc+5btEiGJmM5fEXhaxOFjxGU7fzkiSoqnkUqFrl1ZRRzs4ig52ohWMhFGSgHhm+VyaG TWPDOh3RfjJbT1pjROk+5GJXdEClUvyooIraMli+y9nHLH03LpgjlCrH+hdF8m40WCQE E5GOMstVRJssp5a6VJFS+WxZDfGT+cOVRpciMnyrojahl/hfM9ETPdwkTCKcre9KwcNY l73O7V2zpphu3uEFz9tC/hRsuke1nKrMRDzlaIhhkSYfm4lNq2qk0/FjvFICEl6nNSsW YGgg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=8uN3rj4E61pEiXuH0S044PiehAa3W3BMN3Lqc1kk7Uw=; b=3Jj9rV5i4CYm5M02p6Fr0MwrVwLpXunEQsN2mOMODcFN/+61CAo68Tp40Gu9b18kQ3 5Cu5RN/8AwcCP6BGPeS0JSyZkHMoWzqOI4n/jGTKRr2b+yd1Cy2pqZ9E2n4saNF1kNwb JGFeri+4ugIvzhrwB9mAMuH4iYH/4dHGJAWhd/rjoZbmTP2tiJjPP77e7pTVeKjFdzrr tGEsHmT1PR/f+plR3/gPLWSmjjfde+IyeRcKWl4Zm2CVN5Jkzq/HSAvk1n2tp60jhP+s qpO/bwe0SlL+kRwhMw8rvwLYl2zmI24cO3dEBnsSu5vYpzOpwpGsLupypC3BF17vRU1q oo2w== X-Gm-Message-State: AOAM5305haY2PYDDjeUmXohaouoeHbS+FayvKqJkYDITEoI0yLGuzXHn ZcJoQDqj1kVwTvNxukTLTUdwn0hoLAUQ2+MEbWc9pQ== X-Received: by 2002:a67:c408:0:b0:32d:1319:2e38 with SMTP id c8-20020a67c408000000b0032d13192e38mr6059296vsk.72.1651617345595; Tue, 03 May 2022 15:35:45 -0700 (PDT) MIME-Version: 1.0 References: <20220429203644.2868448-1-samitolvanen@google.com> <202204291545.47C6A97EA2@keescook> In-Reply-To: From: Peter Collingbourne Date: Tue, 3 May 2022 15:35:34 -0700 Message-ID: Subject: Re: [RFC PATCH 00/21] KCFI support To: Peter Zijlstra 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 Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-17.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL 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 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. On the other hand, if we explicitly mark up the calls with CFI disabled, the code becomes easier to audit (think Rust "unsafe" blocks). 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). Peter