From: Kees Cook <keescook@chromium.org>
To: "Gustavo A. R. Silva" <gustavoars@kernel.org>
Cc: Wenjia Zhang <wenjia@linux.ibm.com>,
Jan Karcher <jaka@linux.ibm.com>,
"D. Wythe" <alibuda@linux.alibaba.com>,
Tony Lu <tonylu@linux.alibaba.com>,
Wen Gu <guwen@linux.alibaba.com>,
"David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
linux-s390@vger.kernel.org, netdev@vger.kernel.org,
linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org
Subject: Re: [PATCH][next] net/smc: Avoid -Wflex-array-member-not-at-end warnings
Date: Fri, 1 Mar 2024 16:09:29 -0800 [thread overview]
Message-ID: <202403011607.8E903049@keescook> (raw)
In-Reply-To: <ZeIhOT44ON5rjPiP@neat>
On Fri, Mar 01, 2024 at 12:40:57PM -0600, Gustavo A. R. Silva wrote:
> -Wflex-array-member-not-at-end is coming in GCC-14, and we are getting
> ready to enable it globally.
>
> There are currently a couple of objects in `struct smc_clc_msg_proposal_area`
> that contain a couple of flexible structures:
>
> struct smc_clc_msg_proposal_area {
> ...
> struct smc_clc_v2_extension pclc_v2_ext;
> ...
> struct smc_clc_smcd_v2_extension pclc_smcd_v2_ext;
> ...
> };
>
> So, in order to avoid ending up with a couple of flexible-array members
> in the middle of a struct, we use the `struct_group_tagged()` helper to
> separate the flexible array from the rest of the members in the flexible
> structure:
>
> struct smc_clc_smcd_v2_extension {
> struct_group_tagged(smc_clc_smcd_v2_extension_hdr, hdr,
> u8 system_eid[SMC_MAX_EID_LEN];
> u8 reserved[16];
> );
> struct smc_clc_smcd_gid_chid gidchid[];
> };
>
> With the change described above, we now declare objects of the type of
> the tagged struct without embedding flexible arrays in the middle of
> another struct:
>
> struct smc_clc_msg_proposal_area {
> ...
> struct smc_clc_v2_extension_hdr pclc_v2_ext;
> ...
> struct smc_clc_smcd_v2_extension_hdr pclc_smcd_v2_ext;
> ...
> };
>
> We also use `container_of()` when we need to retrieve a pointer to the
> flexible structures.
>
> So, with these changes, fix the following warnings:
>
> In file included from net/smc/af_smc.c:42:
> net/smc/smc_clc.h:186:49: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end]
> 186 | struct smc_clc_v2_extension pclc_v2_ext;
> | ^~~~~~~~~~~
> net/smc/smc_clc.h:188:49: warning: structure containing a flexible array member is not at the end of another structure [-Wflex-array-member-not-at-end]
> 188 | struct smc_clc_smcd_v2_extension pclc_smcd_v2_ext;
> | ^~~~~~~~~~~~~~~~
>
> Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
I think this is a nice way to deal with these flex-array cases. Using
the struct_group() and container_of() means there is very little
collateral impact. Since this is isolated to a single file, I wonder if
it's easy to check that there are no binary differences too? I wouldn't
expect any -- container_of() is all constant expressions, so the
assignment offsets should all be the same, etc.
Reviewed-by: Kees Cook <keescook@chromium.org>
-Kees
--
Kees Cook
next prev parent reply other threads:[~2024-03-02 0:09 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-03-01 18:40 [PATCH][next] net/smc: Avoid -Wflex-array-member-not-at-end warnings Gustavo A. R. Silva
2024-03-02 0:09 ` Kees Cook [this message]
2024-03-04 9:00 ` Wen Gu
2024-03-07 8:17 ` Jan Karcher
2024-03-07 23:46 ` Gustavo A. R. Silva
2024-03-11 10:59 ` Wen Gu
2024-03-12 7:54 ` Jan Karcher
2024-03-12 9:53 ` Wen Gu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=202403011607.8E903049@keescook \
--to=keescook@chromium.org \
--cc=alibuda@linux.alibaba.com \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=gustavoars@kernel.org \
--cc=guwen@linux.alibaba.com \
--cc=jaka@linux.ibm.com \
--cc=kuba@kernel.org \
--cc=linux-hardening@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-s390@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=tonylu@linux.alibaba.com \
--cc=wenjia@linux.ibm.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).