From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 2CFEC3858C00 for ; Tue, 30 May 2023 11:08:33 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 2CFEC3858C00 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1685444912; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=9Z0o2MBJRUiCNFKh1KoEDdMZnksPnSJqiXIFmnVm+sQ=; b=KpVHQKc9udSkkxlgyf6Q3gBnHKI8IM84KmN1VMlDMstU0Z0FFM071gXu84LJ9iYXcjixN7 yQcgZKktwBhXqJwUDv0lzLBrORlsGmKTCFQO1pqCZd24ePZsxMZvC1cPSE6Uzjo0XA2nP1 Yvm590q2zq34Y5Hap6W+6QqfEQoW634= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-628-ljqdq6lJP7mvNSnaLm0LLw-1; Tue, 30 May 2023 07:08:31 -0400 X-MC-Unique: ljqdq6lJP7mvNSnaLm0LLw-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 486E33802139; Tue, 30 May 2023 11:08:31 +0000 (UTC) Received: from oldenburg.str.redhat.com (unknown [10.2.16.38]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 6B06F112132C; Tue, 30 May 2023 11:08:30 +0000 (UTC) From: Florian Weimer To: Sergey Bugaev Cc: Siddhesh Poyarekar , libc-alpha@sourceware.org Subject: Re: [PATCH v2 0/3] fcntl fortification References: <20230528172013.73111-1-bugaevc@gmail.com> <87wn0qw88m.fsf@oldenburg.str.redhat.com> Date: Tue, 30 May 2023 13:08:28 +0200 In-Reply-To: (Sergey Bugaev's message of "Tue, 30 May 2023 13:46:23 +0300") Message-ID: <878rd6uleb.fsf@oldenburg.str.redhat.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.2 (gnu/linux) MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-4.9 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_NONE,TXREP,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 server2.sourceware.org List-Id: * Sergey Bugaev: > On Tue, May 30, 2023 at 11:09=E2=80=AFAM Florian Weimer wrote: >> > 2. There is a __fcntl_types_compatible () macro which is a thin wrappe= r >> > over __builtin_types_compatible_p () in plain C, and uses an >> > std::is_same_v-like check (using partial template specialization) i= n >> > C++. Importantly, it uses __typeof () even in C++ (not decltype ())= , >> > because we don't want the extra references appended to our type. Fo= r >> > example, we want 'int', not 'const int &' or 'int &&'. >> >> I think you should avoid using __typeof, otherwise we need to add >> another GCC check. If you need to use decltype, you'll have to add a >> __cplusplus version check. > > I don't think I understand your point about the GCC check, could you > please expand? Ahh, maybe that check is implied by doing this for fortification only? >> > 5. Here's the fcntl () macro in all of its horrible glory: >> > >> > #define fcntl(fd, cmd, ...) >> > (__VA_OPT__ (0 ?) __fcntl_2_inline (fd, cmd) >> >> I think we should avoid the new __fcntl_2 symbol because it an >> unnecessary optimization. > > And again I don't think I understand your point :| > Could you please expand here as well? What's the (unnecessary) > optimization here? > > __fcntl_2 is required to do runtime checking of whether the runtime > value of CMD indeed does not require a third argument. Oh, I'm not sure if the run-time check is really that useful. There's no vfcntl function, so I expect that we will have accurate type information at the callsite in most cases, and the compile-time check works. >> It would very nice if we could generate the appropriate warning for C >> (-Wincompatible-pointer-types). This is what I tried to do, but it >> might actually be impossible. >> >> Should we generate errors for C++? It requires compatible pointer >> types, after all. > > So the way I think about this, what this is doing is not making fcntl > into a proper type-safe overloaded function, but adding some > safeguards on top of the existing vararg definition that catch some > mistakes. > > The diagnostics emitted are different, and this is fine. Another > instance of this: you get the "error: call to '__fcntl_missing_arg' > declared with attribute error" and not the error you would otherwise > get from GCC upon forgetting a required function argument ("error: too > few arguments to function 'foo'"). > > I would prefer to keep type mismatch a warning in C++ too (because > this is best-effort additional safeguards, not a real type system), > but this would be easy to change if you want me to. Hmm. I certainly don't see this as a blocker, what you are proposing is way better than what we have today. Thanks, Florian