From patchwork Tue Sep 12 16:22:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexey Dobriyan X-Patchwork-Id: 138527 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9ecd:0:b0:3f2:4152:657d with SMTP id t13csp789874vqx; Tue, 12 Sep 2023 18:32:08 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE9ilnBilhZvKSFAhAvRVBXgKywctsnyoBxB2pxzo2oxOJ2D6zKwDUXYubVToCnZ/u3BU6m X-Received: by 2002:a17:902:f68e:b0:1b8:8682:62fb with SMTP id l14-20020a170902f68e00b001b8868262fbmr5385210plg.4.1694568728183; Tue, 12 Sep 2023 18:32:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694568728; cv=none; d=google.com; s=arc-20160816; b=kBNaE/K7Oc6ykQ4moBQLnCqZBJvn5UNHRf9mDOEY7+oO9bwni1qfwGvVkTbR3IUEDB lW8FXeZ1A0CArplwidMCge2FVrRvT+hC54CFkTcviHgezsc9qgfau6Xepdkl2SHUKtMF GU4E638YxCmBSNvViACx3x8m6V8+cyHNiSC/6kLY0Ym5OBiW+VRrzE4lwxJJgreZbRXS 9b/WN88oLqMwQVEGo/H1OhP53doE2nsO7pd8jnJVx1hAToaAjLiuHBZzt91SxlgVz0AV 9t5qLmYhCoaP/fSMs6IjfaLDVfgykIFFl6Yy28BENoqYbWMgP59mabSus8U3m8a+IsOi 4niw== 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 2620:137:e000::3:1 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 morse.vger.email (morse.vger.email. [2620:137:e000::3:1]) by mx.google.com with ESMTPS id l18-20020a170903245200b001b87bd2f7b0si4903516pls.402.2023.09.12.18.32.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Sep 2023 18:32:08 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) client-ip=2620:137:e000::3:1; 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 2620:137:e000::3:1 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 morse.vger.email (Postfix) with ESMTP id 23D458031D96; Tue, 12 Sep 2023 09:22:53 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236630AbjILQWe (ORCPT + 37 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-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 (morse.vger.email [0.0.0.0]); Tue, 12 Sep 2023 09:22:53 -0700 (PDT) X-Spam-Status: No, score=-0.6 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.vger.email X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776849749603476291 X-GMAIL-MSGID: 1776884099027643656 __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) From patchwork Tue Sep 12 16:23:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexey Dobriyan X-Patchwork-Id: 138490 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9ecd:0:b0:3f2:4152:657d with SMTP id t13csp751827vqx; Tue, 12 Sep 2023 16:57:30 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHL0uhJyGygQsSzlsGIk53Bm1yhktx1lFUjvHXZpb7XMz7CSGVr8w2rC/yHcH+2s3AkFZmN X-Received: by 2002:a05:6808:ecd:b0:3a7:7988:9916 with SMTP id q13-20020a0568080ecd00b003a779889916mr1262610oiv.59.1694563050424; Tue, 12 Sep 2023 16:57:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694563050; cv=none; d=google.com; s=arc-20160816; b=aM8tiRP+cRPT0rMvwu2mtf6GyLBgdcb/K3z3C/0pbOyipr1i/djVuiot3mpNUmxP/o E45VKuuBAnWIo08udSX1NoCX9ffAsBQYPnSAeM+wGIowDEM1gH/HK9HrVM5ET4mazy1R B3hUdaOHbDWrAu1xfrtU2DWt3WqM3Wiu2Va8x8hAef1gesZt7m597xs+Z79Du6Rqfx1h DMwmhZcNnLPZGRmUbsYAAGzKEdZqs9cg8D2FgqyJElRStEjdud3Fjn2GmHr8HuOJOvA9 BI5P8CZ7F/il2HOYj5v/hpRgohE1DD/Y2NTRqMeT91U1IE+tpOqhuk/zQvU1/ZZHFZpx yvgA== 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=XWvMWZ3PfPL63wEwHZjDGh9ALUEehxR7vNe39ic1Lp4=; fh=eYmNiXs7v9TLdnxMWtThlYaejHNzpjn/oCa3DYX9Gqg=; b=O+GKbLT7m8x5jbk8k2PLsnMIW0twRkNruiNlMQrabgDSL4PC3xqoXtyubo7NQbQuJt vcIya2hTdV8f8sl3rAMJ9c/aLfodfxqg5vNLYKgbgmBR7bNHZtYqR8r+F+17OqqeKzl6 QMxPI0oAILwsPjTQOMHCak4/BUVmcRRTazN0tR1PGYK2cDIYwuOJl7YaliiWvHMKdMCj +iE9m+WAtX4pFqsQuvVYKGs6/nBQGe2s8DSVgBbyfUecrFBm/RamJt4aiwqTwgBSYax3 ZA18ayCpjoXLcqlUnxzYWUg6tjcDDuuyzCzc3dRk8ksHEvqvRD+lVP01NhnMQx1FbLQH MbSQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=mTAJYC2E; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 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 morse.vger.email (morse.vger.email. [2620:137:e000::3:1]) by mx.google.com with ESMTPS id h64-20020a636c43000000b00573fa4cfe4asi8445709pgc.39.2023.09.12.16.57.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Sep 2023 16:57:30 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) client-ip=2620:137:e000::3:1; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=mTAJYC2E; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 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 morse.vger.email (Postfix) with ESMTP id 457E78031AF6; Tue, 12 Sep 2023 09:23:44 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236648AbjILQXa (ORCPT + 37 others); Tue, 12 Sep 2023 12:23:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33132 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231518AbjILQX3 (ORCPT ); Tue, 12 Sep 2023 12:23:29 -0400 Received: from mail-ej1-x630.google.com (mail-ej1-x630.google.com [IPv6:2a00:1450:4864:20::630]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0792310D; Tue, 12 Sep 2023 09:23:25 -0700 (PDT) Received: by mail-ej1-x630.google.com with SMTP id a640c23a62f3a-99c1d03e124so722697366b.2; Tue, 12 Sep 2023 09:23:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1694535803; x=1695140603; 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=XWvMWZ3PfPL63wEwHZjDGh9ALUEehxR7vNe39ic1Lp4=; b=mTAJYC2EkCktF4zTiAVFwbXlMCK8Wqmvh33J2hK1eblyM3eKt9u36SKJxOK42lpXjS XJ6qbkTTpgS/CMKlrjGQE02jy5ClVGKeEnZQACv62r4bPh5y+NB26fWbwAmYpL+exyq+ vDlKyFIzqmj78H1tLoVYo/0jQUBVLMHStJmgnQNAXr2Rr/tCvcSi9+yOmH7cjvYx4N21 LMYGTanzkj08LRe7fP7x4ZN2OCmYEjO7frtMl4CXTNxHBLjpnzx61ulGLvXgDrinSBr4 1BD3Ge/lcIAWVHzlsBJB0k/hzgDM3c5lU/Rk3Dg2R2BEzuqTx6iTbY2KCJJ8YkOIKg8k 6z/w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694535803; x=1695140603; 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=XWvMWZ3PfPL63wEwHZjDGh9ALUEehxR7vNe39ic1Lp4=; b=G+T94wI4sI7cABR8T9V5W/GtRPpITQPQNEZaFsSZ4Ihiv9c0sdW+HNIYUb9z8Cm1eQ U95zn8N5erBKiMBPUcG4poLRHYD1FQOejgp9d4fic/lcoYOgV+YZVH8J13z8aDqUe26d d7w7fq+o1qPeYEwxB2CYORLTT6eJ4OuhRqh1kfewmHbBwqbJ3T9bMm14docak3wKgg3i g0zoGBn8kwyww77jwd2ZZ1QgMSdteAq5eYKCrHhtH7/wY0sOTGAJpu5SVw/Ep1ahvbqI 4tbZik/CBG2oPhq54NDyCqqN2ESctmY3PT1ZYIFDRnPS8dzmgZomkItflu5tvm2XMMUY 58iw== X-Gm-Message-State: AOJu0YzXOS9NT8KXICjFHsbJSHO3EjtWOAGO31PdjnlEhuzppnaHfKOb EHnDIltPwe0MAV8zAC24S/cEmlHy+w== X-Received: by 2002:a17:906:7687:b0:9a5:e441:4cf2 with SMTP id o7-20020a170906768700b009a5e4414cf2mr9904342ejm.58.1694535803184; Tue, 12 Sep 2023 09:23:23 -0700 (PDT) Received: from p183 ([46.53.254.179]) by smtp.gmail.com with ESMTPSA id g21-20020a170906349500b00997e00e78e6sm7119522ejb.112.2023.09.12.09.23.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Sep 2023 09:23:22 -0700 (PDT) Date: Tue, 12 Sep 2023 19:23:21 +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 2/2] uapi: fix header guard in include/uapi/linux/stddef.h Message-ID: References: <930c3ee5-1282-40f4-93e0-8ff894aabf3a@p183> <202309080848.60319AF@keescook> <202309080910.44BB7CEF@keescook> <97242381-f1ec-4a4a-9472-1a464f575657@p183> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <97242381-f1ec-4a4a-9472-1a464f575657@p183> 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 (morse.vger.email [0.0.0.0]); Tue, 12 Sep 2023 09:23:44 -0700 (PDT) X-Spam-Status: No, score=-0.6 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.vger.email X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776878144947273217 X-GMAIL-MSGID: 1776878144947273217 Signed-off-by: Alexey Dobriyan --- include/uapi/linux/stddef.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) --- a/include/uapi/linux/stddef.h +++ b/include/uapi/linux/stddef.h @@ -50,8 +50,9 @@ TYPE NAME[]; \ } #endif -#endif #ifndef __counted_by #define __counted_by(m) #endif + +#endif