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 8BB623856627 for ; Tue, 30 May 2023 08:09:50 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 8BB623856627 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=1685434190; 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: in-reply-to:in-reply-to:references:references; bh=KQXe2+AToxx8BNjykRYHgW+6ZApYN0QJ3+pRFdWCjQE=; b=a1cVn3LcfBiv0U4Bv5tsEnnDKAWrlCDTfS52EGCxU2rkZTcuo60oMND6ENJoWXIRFVJ6PN NjFkRtlfy3b35sm0x+pTkc5zqEb4bEKqzv/AokMsu442jNeq45HhFLoJDODcMux25S0KBq PxPdJfhlasWnP2dfnToyWp1xFNKq6OU= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-128-pNeuRvqROvOk_4bHertkQg-1; Tue, 30 May 2023 04:09:48 -0400 X-MC-Unique: pNeuRvqROvOk_4bHertkQg-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 5BE958032E4; Tue, 30 May 2023 08:09:48 +0000 (UTC) Received: from oldenburg.str.redhat.com (unknown [10.2.16.38]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 751BD112132C; Tue, 30 May 2023 08:09:47 +0000 (UTC) From: Florian Weimer To: Sergey Bugaev via Libc-alpha Cc: Sergey Bugaev , Siddhesh Poyarekar Subject: Re: [PATCH v2 0/3] fcntl fortification References: <20230528172013.73111-1-bugaevc@gmail.com> Date: Tue, 30 May 2023 10:09:45 +0200 In-Reply-To: <20230528172013.73111-1-bugaevc@gmail.com> (Sergey Bugaev via Libc-alpha's message of "Sun, 28 May 2023 20:20:10 +0300") Message-ID: <87wn0qw88m.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 X-Spam-Status: No, score=-4.6 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 via Libc-alpha: > 2. There is a __fcntl_types_compatible () macro which is a thin wrapper > over __builtin_types_compatible_p () in plain C, and uses an > std::is_same_v-like check (using partial template specialization) in > C++. Importantly, it uses __typeof () even in C++ (not decltype ()), > because we don't want the extra references appended to our type. For > 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. > 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. > 6. __fcntl_warn () is basically the same as __fcntl_alias (), except > it's defined with __warnattr. So you get a warning (not a hard error) > on type mismatch. This is in line with how pointer type mismatch is > handled elsewhere in C / GCC. You can of course escalate this to an > error with -Werror if you want to. Forgeting an argument when it's > required is still a hard error (__errordecl). 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. > I have only really tested with (modern) GCC. I briefly checked with > Clang, but the fortification doesn't seem to get enabled at all; perhaps > it's failing some other check. Which Clang version? Siddhesh, maybe you could look at this? Thanks, Florian