Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp1993276pxb; Sun, 17 Oct 2021 03:06:31 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx1fNa02pG6GL78shS1w3fIMGKbaAFTFq9W/2d3m/jSi9Jxm7O6ph72FCu2eg1kZ/oAJxvN X-Received: by 2002:a17:906:5d6:: with SMTP id t22mr20596740ejt.98.1634465190807; Sun, 17 Oct 2021 03:06:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1634465190; cv=none; d=google.com; s=arc-20160816; b=zsZSYrmLFzhz0NmmvLz4kM6YG6XTbSAnGX3VXP9gg40x9gvJe8zuA+Qc7ok9N8/4TY WtPzx26Zir3An0vourVjEkHK8LotDycNkkN3u+K0ZQ/Sn4WyYrMaKuGgyOdkV9mGRNx7 +pYSK51kjUOfPR5TFX9sktxJND38qjy8vK9Cj6l0/0QRiaex/RqY71kBZWHvjGWl0cIt GY50DFzJCV0VyKeygSZt3Vzzo3FOculyv3Z00R2cRV71o/c5Mdufa2uAsaf1Vdc0e59G ghPkq6+jC8GPMPzK8vkdByCr9sDxa0YyW6D/ulSmF4EMHRQR6trDZCTEWyeBuihL8mzn Rmsg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=uHSnz8D1DIWQcjU5/N5hH4GTJpS+yuQBb1AWvYk624w=; b=h7S6Z3WfgKNiyxuKApCiFVRIAn7zpBOLy5gzAQulUQWiIFzcMy/0uU6YSwaVFMAR21 wL7AoOyNAUb096H1flnW2zJGgj5S9um1W8kgRZ9qO+5wY/zmpFfMn9k8G8+25qrHu/UL OiKWyPaKTBDc1av1Qw5z7Oe5uExgSF6EbNu/ncImziGk1/zFGtGgOfgsvd+mBB5kT6Tf Cz2v4qrTe+RkvhbMYJbrbPwGe5egPpC7CDTldTBDemXBQHX461Ml2SYaQl3X0Zr8N4KN 2kLggKxITIYJ9zZhOpVlHBlV+h1lPySe/AE9Qdwf38lE2dk6cLyC0HvbYys479P9U95a Zc6g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=a7O6f8UV; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h11si14338195edf.416.2021.10.17.03.06.02; Sun, 17 Oct 2021 03:06:30 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=a7O6f8UV; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S241600AbhJOQtb (ORCPT + 99 others); Fri, 15 Oct 2021 12:49:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59804 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241609AbhJOQt2 (ORCPT ); Fri, 15 Oct 2021 12:49:28 -0400 Received: from mail-yb1-xb2b.google.com (mail-yb1-xb2b.google.com [IPv6:2607:f8b0:4864:20::b2b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6DDC3C061570 for ; Fri, 15 Oct 2021 09:47:21 -0700 (PDT) Received: by mail-yb1-xb2b.google.com with SMTP id s64so24129374yba.11 for ; Fri, 15 Oct 2021 09:47:21 -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:content-transfer-encoding; bh=uHSnz8D1DIWQcjU5/N5hH4GTJpS+yuQBb1AWvYk624w=; b=a7O6f8UVoWX1Jh4/B8imWuGC/qXP5rujqE2kd9JOc3F0/CS0vBBNXumKcCh8QMSonM UdiXmmvRljhji/HhIfUWed2GsvE8VLaSl7VhM/6NlyGtqalnTikHvOcRc968gKOlJ5MR NbXvdoNjQgMiQaTg+bJ8kmvQa5S6vyTa6o5e1GQNd3WiG2SHGwVQoVb4Anj8hXIip+/T lEfnDnu85sr7dSfBu7dqu5943MpPHWTiUdczrTTkqmxTWZhk+UDHuO6mLulD1Q9yQS++ qTKU/kY9oq+lwsoIFNq5+QJJGjEzE6IGCBSqv7z37KBfOBs3oMu93sBC6GRpioUW3CTd jJ8w== 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:content-transfer-encoding; bh=uHSnz8D1DIWQcjU5/N5hH4GTJpS+yuQBb1AWvYk624w=; b=6H4J70YhzVPX16GSNCNIfXqA0qHLi0x7JLe16mh88aFMooQliByPo0zEOu87iDcgre 5gVXy/sm/cK1NxnGtXash9lxv3q7x4s+WzM0dMVgNQ43VAHHYkf3y2MgmzOMWBw8uqKP /6B+KE3fNrFTOIL/5DL3dSTjZfWtOhuwzNrMzZ+Zavil6EI/FR3b34qSec3Tq8NxmOiM 49B6Msjsziy0bg5I+rjYYJioEUU95RWWmcrpOtOrgXnN/Mz00o2HNSSU57PmkSAbhdkY g4ChO76UCmB1LwpQCaG1jG27D8EjFzqVPlkUQKPKnLyhfnv3pqNZF7fcCTEUUVNUNKxy IZwA== X-Gm-Message-State: AOAM530gdGbzvmdwjWtCS0K1HJH3a9JUQVR8aF3n6ZglWL78TyPhkPXC FQFK9NkGTTNk84Y0ey1OWcqq2dXv1TnNtHdBiZIa3w== X-Received: by 2002:a25:8b8b:: with SMTP id j11mr15023659ybl.160.1634316437824; Fri, 15 Oct 2021 09:47:17 -0700 (PDT) MIME-Version: 1.0 References: <20211013181658.1020262-1-samitolvanen@google.com> <20211013181658.1020262-4-samitolvanen@google.com> <7377e6b9-7130-4c20-a0c8-16de4620c995@www.fastmail.com> <8735p25llh.ffs@tglx> In-Reply-To: From: Sami Tolvanen Date: Fri, 15 Oct 2021 09:47:06 -0700 Message-ID: Subject: Re: [PATCH v5 03/15] linkage: Add DECLARE_NOT_CALLED_FROM_C To: Andy Lutomirski Cc: Thomas Gleixner , "the arch/x86 maintainers" , Kees Cook , Josh Poimboeuf , "Peter Zijlstra (Intel)" , Nathan Chancellor , Nick Desaulniers , Sedat Dilek , Steven Rostedt , linux-hardening@vger.kernel.org, Linux Kernel Mailing List , llvm@lists.linux.dev Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Oct 15, 2021 at 9:22 AM Andy Lutomirski wrote: > > > > On Fri, Oct 15, 2021, at 8:55 AM, Thomas Gleixner wrote: > > On Thu, Oct 14 2021 at 19:51, Andy Lutomirski wrote: > >> On Wed, Oct 13, 2021, at 11:16 AM, Sami Tolvanen wrote: > >>> > >>> +/* > >>> + * Declares a function not callable from C using an opaque type. Def= ined as > >>> + * an array to allow the address of the symbol to be taken without '= &'. > >>> + */ > >> I=E2=80=99m not convinced that taking the address without using & is a > >> laudable goal. The magical arrays-are-pointers-too behavior of C is a > >> mistake, not a delightful simplification. > > > >>> +#ifndef DECLARE_NOT_CALLED_FROM_C > >>> +#define DECLARE_NOT_CALLED_FROM_C(sym) \ > >>> + extern const u8 sym[] > >>> +#endif > >> > > > >> The relevant property of these symbols isn=E2=80=99t that they=E2=80= =99re not called > >> from C. The relevant thing is that they are just and not objects of a > >> type that the programmer cares to tell the compiler about. (Or that > >> the compiler understands, for that matter. On a system with XO memory > >> or if they=E2=80=99re in a funny section, dereferencing them may fail.= ) > > > > I agree. > > > >> So I think we should use incomplete structs, which can=E2=80=99t be > >> dereferenced and will therefore be less error prone. > > > > While being late to that bike shed painting party, I really have to ask > > the question _why_ can't the compiler provide an annotation for these > > kind of things which: > > > > 1) Make the build fail when invoked directly > > > > 2) Tell CFI that this is _NOT_ something it can understand > > > > -void clear_page_erms(void *page); > > +void __bikeshedme clear_page_erms(void *page); > > > > That still tells me: > > > > 1) This is a function > > > > 2) It has a regular argument which is expected to be in RDI > > > > which even allows to do analyis of e.g. the alternative call which > > invokes that function. > > > > DECLARE_NOT_CALLED_FROM_C(clear_page_erms); > > > > loses these properties and IMO it's a tasteless hack. > > > > > Ah, but clear_page_erms is a different beast entirely as compared to, say= , the syscall entry. It *is* a C function. So I see two ways to handle it: > > 1. Make it completely opaque. Tglx doesn=E2=80=99t like it, and I agree,= but it would *work*. > > 2. Make it a correctly typed function. In clang CFI land, this may or may= not be =E2=80=9Ccanonical=E2=80=9D (or non canonical?). Technically speaking the clear_page_* declarations don't need to be changed for CFI, they do work fine as is, but I included them in the patch as they're not actually called from C code right now. But you're right, we should use a proper function declarations for these. I'll drop the changes to this file in the next version. I wouldn't mind having a consensus on how to deal with exception handlers etc. though. Should I still use opaque types for those? Sami