From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pl1-x62a.google.com (mail-pl1-x62a.google.com [IPv6:2607:f8b0:4864:20::62a]) by sourceware.org (Postfix) with ESMTPS id 503B63858D1E for ; Thu, 11 May 2023 22:16:45 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 503B63858D1E 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-pl1-x62a.google.com with SMTP id d9443c01a7336-1aaed87d8bdso66135095ad.3 for ; Thu, 11 May 2023 15:16:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1683843404; x=1686435404; 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=mYCkZW2ogs6OMYlPsNws7SbZYW9dz6tYyPZ1gWxGb8k=; b=HkV1/6IE9cIGy1RW+z8Arp7eRsUPZAmopg2U5rg8IL4m0as9cOGnhLviwEqhk9uyp6 L3jkbvNUMZdBL9WuorKQ1KWPD0BAN8cdDO3oAfZd9vcxKrWlTvqtoaeJDwuulQeXEvPO 0izSDa+iwdk5v+qk7go4AYxUGOs9Y2NI5sJjM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683843404; x=1686435404; 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=mYCkZW2ogs6OMYlPsNws7SbZYW9dz6tYyPZ1gWxGb8k=; b=AjkY9pEOFvLbyXkBrVpEyACmSjiTkq1HnzO3L/5bY3V6x6raVHFVkgiBIXQYzCuLpy ctYO8HcbOTD5XrMYuVZCzD67L3SlEv9iof8UhzXwrQqgZPlqWchUygpJiKeUTAktJXWc E5l5JfyWQnJmA7h4HCOPK0XE3Htls6SJ4Qizq6+0mAt8XC8K/HaFzrWpdbE/584K3vBR ELKhlEvLRPKk9b262Ax0JY4C/Ui/+8xPRJUuEDZ3rDBfv+/r4r5166PPuMuQDzLnfj8I o0E2zzv8hUZBoPdJrhn3nLbAH60MrOz2AVXcyILYo7xgf07KCLk/1xFmqZ2UyzlMIlbx VJJQ== X-Gm-Message-State: AC+VfDyIHJV0qFj70XT94yHiZuLGitidnHalCtheNifasDJmxPPg5ilk Ht80JAkdLdKV1p1wUBNO640h9A== X-Google-Smtp-Source: ACHHUZ4JoAef92WR5VbZemTNr+hT6tqc5aZjq7DFDEUq2hse935X6MfDjjp8jOrQMbQVJQhzcASqmg== X-Received: by 2002:a17:902:c952:b0:1ad:ca0e:cf23 with SMTP id i18-20020a170902c95200b001adca0ecf23mr4279369pla.3.1683843404353; Thu, 11 May 2023 15:16:44 -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 z9-20020a170902834900b001aaf2172418sm6406127pln.95.2023.05.11.15.16.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 May 2023 15:16:43 -0700 (PDT) Date: Thu, 11 May 2023 15:16:43 -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: <202305111514.576EB7F@keescook> References: <44940599-7b43-99f6-5b09-4f050d645c7b@gmail.com> <202305111158.C78642624@keescook> <74ee73d2-04e-ea8-9430-93929446e925@codesourcery.com> <202305111410.CFE0875F@keescook> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-2.1 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 09:43:49PM +0000, Joseph Myers wrote: > On Thu, 11 May 2023, Kees Cook via Gcc wrote: > > > 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? > > Zero-sized objects break the principle that different objects have > different addresses, and the principle of being able to subtract pointers > to different elements of an array. There would also be serious C++ > compatibility concerns, since C++ allows a struct with no members but it > has nonzero size, unlike the GNU C extension where a struct with no > members has size zero. Okay, understood. If this is a C-only thing, we can ignore the C++ impact. What depends on the "different objects have different addresses" principle? And why do unions not break this -- they could point to the same locations within the object? And don't flexible arrays already need special handling in this regard? -- Kees Cook