Received: by 2002:a05:7412:31a9:b0:e2:908c:2ebd with SMTP id et41csp2943889rdb; Tue, 12 Sep 2023 18:11:27 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHK0Sq8Pg0n8VVTSAQCXydQa2t5hmjzRvXObusltw9soKgmgdm0QnFVzedieZh7fIK64+3/ X-Received: by 2002:a05:6a20:914f:b0:125:3445:8af0 with SMTP id x15-20020a056a20914f00b0012534458af0mr1676155pzc.7.1694567487378; Tue, 12 Sep 2023 18:11:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694567487; cv=none; d=google.com; s=arc-20160816; b=gs5FqK8aZdcg1XGo89hQnVV+M27oiATTjMOc3B40WlAnAeQ8oYt7Psb8ATUmNW1aCR ZsshPq1IfaeZfiIgQQLhpAfolATJUQRiLwxTwJkF5rDinYtire66nja3DJkk1+GGQgVG XfkNinDevdHDkhmes20EY3CbOTEc1LcEApJJjEiv3ss8gWHrh6gPhKKJflG67kz+rALp 93vb2IaUO+/wsoEMifjF8jQg717LxRUt4EaUaBtIeinHuSQK4xGnj5CZC1tMfYGMsrpg EDDx/KpneuxwaFanNFXReWTt91a/KoQkJBdsS5WLrDXBH9zF6lcROqretHprKU22Hwmu yZNA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=XfZpeOfcmkjD2RwkOI7LjaIvRtoKYYK0xNqzXUjc4kk=; fh=eYmNiXs7v9TLdnxMWtThlYaejHNzpjn/oCa3DYX9Gqg=; b=dGRCI2tdhuwOd/0wVhXK7StG40+u0cbHWx+VuRzlT7VTeS4MEWuTZbiehEmDSYPNb0 DlkxhbHfyKP4AmfCwvQs6bp5WJXxuzOzGdy769skfrEjcXqjBSsMWXhUvk4jdq/KiGvt gmBHyG+o9JxVsEsZFBtG0LE2gOu2HgFuW4DgwfGVaQ20DuxLySHs9FbOMRqd2h3KMZ1Q Qf+JasJiQFcGwX4Rt1RwSO5jLdIMHToOOL5xXeDk6EP4n4TVjB0WS93OfZQ8L0xWlswU AzdISBw54OIUYmgGmKCS0+2vN8RNgJvu9/vm1iWN0Ahc3HP+0mkB9gG6LX6+M7oEgxY3 H0jA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b="abw1/11L"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from howler.vger.email (howler.vger.email. [23.128.96.34]) by mx.google.com with ESMTPS id be3-20020a056a001f0300b0068fca4405aasi4070049pfb.338.2023.09.12.18.11.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Sep 2023 18:11:27 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) client-ip=23.128.96.34; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b="abw1/11L"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id DD8CB84C80CA; Tue, 12 Sep 2023 09:22:42 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236606AbjILQWe (ORCPT + 99 others); Tue, 12 Sep 2023 12:22:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53814 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233717AbjILQWc (ORCPT ); Tue, 12 Sep 2023 12:22:32 -0400 Received: from mail-ej1-x62c.google.com (mail-ej1-x62c.google.com [IPv6:2a00:1450:4864:20::62c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A2C8F10D; Tue, 12 Sep 2023 09:22:28 -0700 (PDT) Received: by mail-ej1-x62c.google.com with SMTP id a640c23a62f3a-99bcf2de59cso742652166b.0; Tue, 12 Sep 2023 09:22:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1694535747; x=1695140547; darn=vger.kernel.org; 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=XfZpeOfcmkjD2RwkOI7LjaIvRtoKYYK0xNqzXUjc4kk=; b=abw1/11LkpA+ahNq+QaCbGTyb+ulw1ZRMK8JIyKxofIhSF5S2nR3zltBMQPwW2Cu1t Ano/Ay2vIt6FrvNP1Uv06Jmi+V7BoJJpD6BBTR7cXYW5nEos1UPMR3RrgJp9jIPKbjag L9scuWC0xflqmCPAmWxXNVpEyOFnjA/7Yi1ahDC6gUYn3NcD6gcJ/daMjiyWK9rwwfL6 0ERnZrcBuhPH+kcfqqUqu1pm4bHfNkxGDXa0oFa8NueBqEXzpfH/8Gdc5Kw3Bjg9M7oB 3dkeXP7PcAfcJU8/2bt+V3GDBimh7uY00pwJdDESr3oAMDLkPtcFnh9SEnOgJ12m0zGQ OsQg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694535747; x=1695140547; 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=XfZpeOfcmkjD2RwkOI7LjaIvRtoKYYK0xNqzXUjc4kk=; b=ieIbETahCHZfsaNRK/dzYv0N2LngNu57OlXLvwjuhQ1mZOJSk+QDWyWyYQaw0GcUML HhIQ2VNXEFyU/WSzIzxV3boBq1m5IlchKEqzzu+SdLMLOPQGCDbpKM0bib29TJAHyag3 1xaIWMj/UNSdRUhmKt4998pEu1vKHPpN1ZDoWJ6wQKjPLeVxgfA0gBQHAKObb9CMcZev ZfB+OT3PHXIpz+1bmcAAGxBv1sbZeJOuzyJAOnD0Kivy8WorFQQQ+2WISbHUtA1J3ZUu RvVCRG8XycGzzf7a8jSXRiRkvPfr5iQLUHPzGMziXY0OD/goCCi5XssbQoHvZ6Z8vBmN fBFw== X-Gm-Message-State: AOJu0Yy1qB0i7xtiqFfWPANjXGzyLBFhvsHfPWwtCNl5Q3UICFdhs80K ztC8MFWOq2RsjIS/37psg+dsKUj1ww== X-Received: by 2002:a17:907:7791:b0:9a9:e41c:bcb6 with SMTP id ky17-20020a170907779100b009a9e41cbcb6mr11465182ejc.28.1694535746774; Tue, 12 Sep 2023 09:22:26 -0700 (PDT) Received: from p183 ([46.53.254.179]) by smtp.gmail.com with ESMTPSA id d11-20020a1709064c4b00b00993004239a4sm6998179ejw.215.2023.09.12.09.22.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Sep 2023 09:22:26 -0700 (PDT) Date: Tue, 12 Sep 2023 19:22:24 +0300 From: Alexey Dobriyan To: akpm@linux-foundation.org, keescook@chromium.org Cc: linux-kernel@vger.kernel.org, linux-api@vger.kernel.org, linux-hardening@vger.kernel.org, David.Laight@aculab.com Subject: [PATCH v3 1/2] uapi: fix __DECLARE_FLEX_ARRAY for C++ Message-ID: <97242381-f1ec-4a4a-9472-1a464f575657@p183> References: <930c3ee5-1282-40f4-93e0-8ff894aabf3a@p183> <202309080848.60319AF@keescook> <202309080910.44BB7CEF@keescook> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (howler.vger.email [0.0.0.0]); Tue, 12 Sep 2023 09:22:43 -0700 (PDT) __DECLARE_FLEX_ARRAY(T, member) macro expands to struct { struct {} __empty_member; T member[]; }; which is subtly wrong in C++ because sizeof(struct{}) is 1 not 0, changing UAPI structures layouts. This can be fixed by expanding to T member[]; Now g++ doesn't like "T member[]" either, throwing errors on the following code: struct S { union { T1 member1[]; T2 member2[]; }; }; or struct S { T member[]; }; Use "T member[0];" which seems to work and does the right thing wrt structure layout. Signed-off-by: Alexey Dobriyan Fixes: 3080ea5553cc ("stddef: Introduce DECLARE_FLEX_ARRAY() helper") --- include/uapi/linux/stddef.h | 6 ++++++ 1 file changed, 6 insertions(+) --- a/include/uapi/linux/stddef.h +++ b/include/uapi/linux/stddef.h @@ -29,6 +29,11 @@ struct TAG { MEMBERS } ATTRS NAME; \ } +#ifdef __cplusplus +/* sizeof(struct{}) is 1 in C++, not 0, can't use C version of the macro. */ +#define __DECLARE_FLEX_ARRAY(T, member) \ + T member[0] +#else /** * __DECLARE_FLEX_ARRAY() - Declare a flexible array usable in a union * @@ -45,6 +50,7 @@ TYPE NAME[]; \ } #endif +#endif #ifndef __counted_by #define __counted_by(m)