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.129.124]) by sourceware.org (Postfix) with ESMTPS id 3FC0C3858C36 for ; Fri, 21 Apr 2023 15:27:12 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 3FC0C3858C36 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=1682090831; 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=Q1f/0XTC1uWXQ4v3xbuApGjgdB8Riz/5OM2K/vWdAGI=; b=ckkV6WsHQ/kt9k60J0ZOkj/hZGVwMk5vjTOqPQun+8phKgirqqDx8g345j/ffC7v/pb+Db gha3npdZtSW66OsugJvXTW8GGNjIKkYxLEX4y5gf+36x5LnHWPVw8XhZ6NSEt+kmYRH1HA oES5MEjL0pIGTvtVpq6QE1qVf/j7bhw= 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-649-uq7HOf6VM7iTOMyD3RyTcg-1; Fri, 21 Apr 2023 11:27:10 -0400 X-MC-Unique: uq7HOf6VM7iTOMyD3RyTcg-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 CD130811E7B; Fri, 21 Apr 2023 15:27:09 +0000 (UTC) Received: from redhat.com (unknown [10.2.16.177]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C05CD1121318; Fri, 21 Apr 2023 15:27:08 +0000 (UTC) Date: Fri, 21 Apr 2023 10:27:07 -0500 From: Eric Blake To: Alejandro Colomar Cc: GNU libc development , austin-group-l@opengroup.org, GCC , Zack Weinberg Subject: Re: [PATCH] sockaddr.3type: Document that sockaddr_storage is the API to be used Message-ID: References: <20230330171310.12330-1-alx@kernel.org> <9b528ba9-e1c6-1c03-8ec7-177c4dc66e19@gmail.com> <7396024c-62d4-a19c-b7bc-e24a9d4bcb31@gmail.com> <6fdadcff-95a2-44fe-9453-d0200822e01e@app.fastmail.com> <7823f94b-ce59-2bef-51aa-fb0f6fad39ec@gmail.com> MIME-Version: 1.0 In-Reply-To: <7823f94b-ce59-2bef-51aa-fb0f6fad39ec@gmail.com> User-Agent: NeoMutt/20230407 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=us-ascii Content-Disposition: inline X-Spam-Status: No, score=-9.8 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,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: On Fri, Apr 21, 2023 at 05:00:14PM +0200, Alejandro Colomar wrote: > > > > The wording I see in > > doesn't seem to cover the case of aliasing a sockaddr_storage as a > > protocol-specific address for setting other members. > > > > Aliasing rules don't allow one to declare an object of type > > sockaddr_storage and then fill the structure as if it were another > > structure, even if alignment and size are correct. We would need > > some wording that says something like: > > > > When a pointer to a sockaddr_storage structure is first aliased as a > > pointer to a protocol-specific address structure, the effective type > > of the object will be set to the protocol-specific structure. I'll add that as a comment to the Austin Group page; it seems like a reasonable statement of intent (POSIX already says that struct sockaddr_storage is sufficiently sized and aligned; all that remains is for the compiler to be aware that we intend to use a more-appropriate effective type once we have the storage allocated). > > > > This is similar to what happens when malloc(3) is assigned to a > > non-character type. That's a big hammer, but it does the job. Maybe > > we would need some looser language? I CCd GCC, in case they have > > concerns about this wording. > > > > Cheers, > > Alex > > > >> > >> I quite like this way of putting it. It subsumes both what I wrote and > >> the related potential headache with deciding whether the sa_family_t > >> field is considered an object or just a range of bytes within a larger > >> object. > >> > >> zw > > > > For the man pages, I've rewritten it to the following: > > > $ git diff > diff --git a/man3type/sockaddr.3type b/man3type/sockaddr.3type > index 2fdf56c59..e610aa0f5 100644 > --- a/man3type/sockaddr.3type > +++ b/man3type/sockaddr.3type > @@ -117,6 +117,14 @@ .SH HISTORY > was invented by POSIX. > See also > .BR accept (2). > +.PP > +These structures were invented before modern ISO C strict-aliasing rules. > +If aliasing rules are applied strictly, > +these structures would be impossible to use Maybe "extremely difficult" instead of "impossible" to use (if I understand this thread correctly, it is possible to memcpy() from one struct into different storage of a different effective type where the memcpy()'s intermediate aliasing through char* avoids the UB). > +without invoking Undefined Behavior (UB). > +POSIX Issue 8 will fix this by requiring that implementations > +make sure that these structures > +can be safely used as they were designed. > .SH NOTES > .I socklen_t > is also defined in > > > I guess this is simple enough that it should work as documentation. It seems fine from my perspective. -- Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3266 Virtualization: qemu.org | libvirt.org