From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pf1-x434.google.com (mail-pf1-x434.google.com [IPv6:2607:f8b0:4864:20::434]) by sourceware.org (Postfix) with ESMTPS id 95D9B3858C5F for ; Thu, 11 May 2023 21:13:08 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 95D9B3858C5F Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=chromium.org Received: by mail-pf1-x434.google.com with SMTP id d2e1a72fcca58-64ab2a37812so268131b3a.1 for ; Thu, 11 May 2023 14:13:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1683839588; x=1686431588; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=0iPvtK8eE4YcejseVQBaIQEVfSENwYG96qP/AvtPv+Y=; b=UBgIMvYRcCeSNbo0PAw8RzF3Hd53WQNccP/U6vfXz2w7A88C13gDLVFIE1h+OPigJn 24afD1MaMaPhvbwilNjeva2PZjatXjEJpCrun1mbLI0hX/ut84DUM6jzvlMuPXndlD4F m0nvbbicXYeuCWVBuqAC6+vmF9SmXUo8C2JUU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683839588; x=1686431588; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=0iPvtK8eE4YcejseVQBaIQEVfSENwYG96qP/AvtPv+Y=; b=kE7p+6cjWq5wNxXc18QgnZYBk9a6oEhaTbajfFCtLAbd7YxbkTmZ9YAQgdabpLRE3/ g2CKa3sSopgw6W/V411UDZsJkgSrMYqOvzDhdATjdILS6Q6v38kMBtFCIiROMbAYOv+E GKB0Noiyt2hPFrUoI41EgSwnPgEwIEIqux/s5DsglEi5K2f3KabbgA6r4q0my3VBQ+b7 Dl/5osjpLfFBMd2CaUQ3JbWSd9IFbeBNOsUgvpynRUfnYCSLVs73OtsVhew7G/PO43q5 M9nacHQKSkjCi4Qz9WQI+9+i6gGsufVKA/vo+93p4Myxz1sYSMJm8w21ykKvZARNsiWq nBoQ== X-Gm-Message-State: AC+VfDzvBoHmcc5MX4+7BLnCp1RUxvxgcQp9NpCVao7W8DuFlBzcuLYt o8PwvKddAbE6GAw9zyIWeif5bw== X-Google-Smtp-Source: ACHHUZ5dO5qa4+mnTcA59fwH9hAengKmF5rUNjLuEBqwS/HtHeokRXUFfw9ThbqW5lmW/PNuPPLviw== X-Received: by 2002:a17:90b:198f:b0:246:5787:6f5d with SMTP id mv15-20020a17090b198f00b0024657876f5dmr31482866pjb.10.1683839587703; Thu, 11 May 2023 14:13:07 -0700 (PDT) Received: from www.outflux.net (198-0-35-241-static.hfc.comcastbusiness.net. [198.0.35.241]) by smtp.gmail.com with ESMTPSA id ei18-20020a17090ae55200b00252a7b73486sm418617pjb.29.2023.05.11.14.13.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 May 2023 14:13:07 -0700 (PDT) Date: Thu, 11 May 2023 14:13:06 -0700 From: Kees Cook To: Joseph Myers Cc: Alejandro Colomar , GCC , Alejandro Colomar , Andrew Clayton , Andrew Clayton , linux-hardening@vger.kernel.org Subject: Re: [wish] Flexible array members in unions Message-ID: <202305111410.CFE0875F@keescook> References: <44940599-7b43-99f6-5b09-4f050d645c7b@gmail.com> <202305111158.C78642624@keescook> <74ee73d2-04e-ea8-9430-93929446e925@codesourcery.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <74ee73d2-04e-ea8-9430-93929446e925@codesourcery.com> X-Spam-Status: No, score=-2.2 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,JMQ_SPF_NEUTRAL,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE autolearn=no 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 Thu, May 11, 2023 at 08:53:52PM +0000, Joseph Myers wrote: > On Thu, 11 May 2023, Kees Cook via Gcc wrote: > > > On Thu, May 11, 2023 at 06:29:10PM +0200, Alejandro Colomar wrote: > > > On 5/11/23 18:07, Alejandro Colomar wrote: > > > [...] > > > > Would you allow flexible array members in unions? Is there any > > > > strong reason to disallow them? > > > > Yes please!! And alone in a struct, too. > > > > AFAICT, there is no mechanical/architectural reason to disallow them > > (especially since they _can_ be constructed with some fancy tricks, > > and they behave as expected.) My understanding is that it's disallowed > > due to an overly strict reading of the very terse language that created > > flexible arrays in C99. > > Standard C has no such thing as a zero-size object or type, which would > lead to problems with a struct or union that only contains a flexible > array member there. Ah-ha, okay. That root cause makes sense now. Why are zero-sized objects missing in Standard C? Or, perhaps, the better question is: what's needed to support the idea of a zero-sized object? -- Kees Cook