* [PATCH v4][next] net/smc: Avoid -Wflex-array-member-not-at-end warnings
@ 2024-03-28 21:52 Gustavo A. R. Silva
2024-04-01 3:34 ` Wen Gu
2024-04-03 10:10 ` patchwork-bot+netdevbpf
0 siblings, 2 replies; 3+ messages in thread
From: Gustavo A. R. Silva @ 2024-03-28 21:52 UTC (permalink / raw)
To: Wenjia Zhang, Jan Karcher, D. Wythe, Tony Lu, Wen Gu,
David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni
Cc: linux-s390, netdev, linux-kernel, Gustavo A. R. Silva, linux-hardening
-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_fixed, fixed,
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_fixed pclc_v2_ext;
...
struct smc_clc_smcd_v2_extension_fixed 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;
| ^~~~~~~~~~~~~~~~
Reviewed-by: Kees Cook <keescook@chromium.org>
Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
---
Changes v4:
- Fix code comments (due to copy/paste error, aghhh).
Changes in v3:
- Adjust code to 80 columns. (Wen Gu)
- Add a couple of code comments.
- Link: https://lore.kernel.org/linux-hardening/ZgXlIADfiXSyRz8d@neat/
Changes in v2:
- Name the tagged struct *_fixed instead of *_hdr.
- Add Kees' RB tag.
- Link: https://lore.kernel.org/linux-hardening/ZfCXBykRw5XqBvf0@neat/
v1:
- Link: https://lore.kernel.org/linux-hardening/ZeIhOT44ON5rjPiP@neat/
net/smc/smc_clc.c | 6 ++++--
net/smc/smc_clc.h | 26 ++++++++++++++++----------
2 files changed, 20 insertions(+), 12 deletions(-)
diff --git a/net/smc/smc_clc.c b/net/smc/smc_clc.c
index e55026c7529c..33fa787c28eb 100644
--- a/net/smc/smc_clc.c
+++ b/net/smc/smc_clc.c
@@ -853,8 +853,10 @@ int smc_clc_send_proposal(struct smc_sock *smc, struct smc_init_info *ini)
pclc_smcd = &pclc->pclc_smcd;
pclc_prfx = &pclc->pclc_prfx;
ipv6_prfx = pclc->pclc_prfx_ipv6;
- v2_ext = &pclc->pclc_v2_ext;
- smcd_v2_ext = &pclc->pclc_smcd_v2_ext;
+ v2_ext = container_of(&pclc->pclc_v2_ext,
+ struct smc_clc_v2_extension, fixed);
+ smcd_v2_ext = container_of(&pclc->pclc_smcd_v2_ext,
+ struct smc_clc_smcd_v2_extension, fixed);
gidchids = pclc->pclc_gidchids;
trl = &pclc->pclc_trl;
diff --git a/net/smc/smc_clc.h b/net/smc/smc_clc.h
index 7cc7070b9772..467effb50cd6 100644
--- a/net/smc/smc_clc.h
+++ b/net/smc/smc_clc.h
@@ -134,12 +134,15 @@ struct smc_clc_smcd_gid_chid {
*/
struct smc_clc_v2_extension {
- struct smc_clnt_opts_area_hdr hdr;
- u8 roce[16]; /* RoCEv2 GID */
- u8 max_conns;
- u8 max_links;
- __be16 feature_mask;
- u8 reserved[12];
+ /* New members must be added within the struct_group() macro below. */
+ struct_group_tagged(smc_clc_v2_extension_fixed, fixed,
+ struct smc_clnt_opts_area_hdr hdr;
+ u8 roce[16]; /* RoCEv2 GID */
+ u8 max_conns;
+ u8 max_links;
+ __be16 feature_mask;
+ u8 reserved[12];
+ );
u8 user_eids[][SMC_MAX_EID_LEN];
};
@@ -159,8 +162,11 @@ struct smc_clc_msg_smcd { /* SMC-D GID information */
};
struct smc_clc_smcd_v2_extension {
- u8 system_eid[SMC_MAX_EID_LEN];
- u8 reserved[16];
+ /* New members must be added within the struct_group() macro below. */
+ struct_group_tagged(smc_clc_smcd_v2_extension_fixed, fixed,
+ u8 system_eid[SMC_MAX_EID_LEN];
+ u8 reserved[16];
+ );
struct smc_clc_smcd_gid_chid gidchid[];
};
@@ -183,9 +189,9 @@ struct smc_clc_msg_proposal_area {
struct smc_clc_msg_smcd pclc_smcd;
struct smc_clc_msg_proposal_prefix pclc_prfx;
struct smc_clc_ipv6_prefix pclc_prfx_ipv6[SMC_CLC_MAX_V6_PREFIX];
- struct smc_clc_v2_extension pclc_v2_ext;
+ struct smc_clc_v2_extension_fixed pclc_v2_ext;
u8 user_eids[SMC_CLC_MAX_UEID][SMC_MAX_EID_LEN];
- struct smc_clc_smcd_v2_extension pclc_smcd_v2_ext;
+ struct smc_clc_smcd_v2_extension_fixed pclc_smcd_v2_ext;
struct smc_clc_smcd_gid_chid
pclc_gidchids[SMCD_CLC_MAX_V2_GID_ENTRIES];
struct smc_clc_msg_trail pclc_trl;
--
2.34.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH v4][next] net/smc: Avoid -Wflex-array-member-not-at-end warnings
2024-03-28 21:52 [PATCH v4][next] net/smc: Avoid -Wflex-array-member-not-at-end warnings Gustavo A. R. Silva
@ 2024-04-01 3:34 ` Wen Gu
2024-04-03 10:10 ` patchwork-bot+netdevbpf
1 sibling, 0 replies; 3+ messages in thread
From: Wen Gu @ 2024-04-01 3:34 UTC (permalink / raw)
To: Gustavo A. R. Silva, Wenjia Zhang, Jan Karcher, D. Wythe,
Tony Lu, David S. Miller, Eric Dumazet, Jakub Kicinski,
Paolo Abeni
Cc: linux-s390, netdev, linux-kernel, linux-hardening
On 2024/3/29 05:52, 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_fixed, fixed,
> 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_fixed pclc_v2_ext;
> ...
> struct smc_clc_smcd_v2_extension_fixed 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;
> | ^~~~~~~~~~~~~~~~
>
> Reviewed-by: Kees Cook <keescook@chromium.org>
> Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
Thank you, Gustavo.
Reviewed-by: Wen Gu <guwen@linux.alibaba.com>
> ---
> Changes v4:
> - Fix code comments (due to copy/paste error, aghhh).
>
> Changes in v3:
> - Adjust code to 80 columns. (Wen Gu)
> - Add a couple of code comments.
> - Link: https://lore.kernel.org/linux-hardening/ZgXlIADfiXSyRz8d@neat/
>
> Changes in v2:
> - Name the tagged struct *_fixed instead of *_hdr.
> - Add Kees' RB tag.
> - Link: https://lore.kernel.org/linux-hardening/ZfCXBykRw5XqBvf0@neat/
>
> v1:
> - Link: https://lore.kernel.org/linux-hardening/ZeIhOT44ON5rjPiP@neat/
>
> net/smc/smc_clc.c | 6 ++++--
> net/smc/smc_clc.h | 26 ++++++++++++++++----------
> 2 files changed, 20 insertions(+), 12 deletions(-)
>
> diff --git a/net/smc/smc_clc.c b/net/smc/smc_clc.c
> index e55026c7529c..33fa787c28eb 100644
> --- a/net/smc/smc_clc.c
> +++ b/net/smc/smc_clc.c
> @@ -853,8 +853,10 @@ int smc_clc_send_proposal(struct smc_sock *smc, struct smc_init_info *ini)
> pclc_smcd = &pclc->pclc_smcd;
> pclc_prfx = &pclc->pclc_prfx;
> ipv6_prfx = pclc->pclc_prfx_ipv6;
> - v2_ext = &pclc->pclc_v2_ext;
> - smcd_v2_ext = &pclc->pclc_smcd_v2_ext;
> + v2_ext = container_of(&pclc->pclc_v2_ext,
> + struct smc_clc_v2_extension, fixed);
> + smcd_v2_ext = container_of(&pclc->pclc_smcd_v2_ext,
> + struct smc_clc_smcd_v2_extension, fixed);
> gidchids = pclc->pclc_gidchids;
> trl = &pclc->pclc_trl;
>
> diff --git a/net/smc/smc_clc.h b/net/smc/smc_clc.h
> index 7cc7070b9772..467effb50cd6 100644
> --- a/net/smc/smc_clc.h
> +++ b/net/smc/smc_clc.h
> @@ -134,12 +134,15 @@ struct smc_clc_smcd_gid_chid {
> */
>
> struct smc_clc_v2_extension {
> - struct smc_clnt_opts_area_hdr hdr;
> - u8 roce[16]; /* RoCEv2 GID */
> - u8 max_conns;
> - u8 max_links;
> - __be16 feature_mask;
> - u8 reserved[12];
> + /* New members must be added within the struct_group() macro below. */
> + struct_group_tagged(smc_clc_v2_extension_fixed, fixed,
> + struct smc_clnt_opts_area_hdr hdr;
> + u8 roce[16]; /* RoCEv2 GID */
> + u8 max_conns;
> + u8 max_links;
> + __be16 feature_mask;
> + u8 reserved[12];
> + );
> u8 user_eids[][SMC_MAX_EID_LEN];
> };
>
> @@ -159,8 +162,11 @@ struct smc_clc_msg_smcd { /* SMC-D GID information */
> };
>
> struct smc_clc_smcd_v2_extension {
> - u8 system_eid[SMC_MAX_EID_LEN];
> - u8 reserved[16];
> + /* New members must be added within the struct_group() macro below. */
> + struct_group_tagged(smc_clc_smcd_v2_extension_fixed, fixed,
> + u8 system_eid[SMC_MAX_EID_LEN];
> + u8 reserved[16];
> + );
> struct smc_clc_smcd_gid_chid gidchid[];
> };
>
> @@ -183,9 +189,9 @@ struct smc_clc_msg_proposal_area {
> struct smc_clc_msg_smcd pclc_smcd;
> struct smc_clc_msg_proposal_prefix pclc_prfx;
> struct smc_clc_ipv6_prefix pclc_prfx_ipv6[SMC_CLC_MAX_V6_PREFIX];
> - struct smc_clc_v2_extension pclc_v2_ext;
> + struct smc_clc_v2_extension_fixed pclc_v2_ext;
> u8 user_eids[SMC_CLC_MAX_UEID][SMC_MAX_EID_LEN];
> - struct smc_clc_smcd_v2_extension pclc_smcd_v2_ext;
> + struct smc_clc_smcd_v2_extension_fixed pclc_smcd_v2_ext;
> struct smc_clc_smcd_gid_chid
> pclc_gidchids[SMCD_CLC_MAX_V2_GID_ENTRIES];
> struct smc_clc_msg_trail pclc_trl;
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v4][next] net/smc: Avoid -Wflex-array-member-not-at-end warnings
2024-03-28 21:52 [PATCH v4][next] net/smc: Avoid -Wflex-array-member-not-at-end warnings Gustavo A. R. Silva
2024-04-01 3:34 ` Wen Gu
@ 2024-04-03 10:10 ` patchwork-bot+netdevbpf
1 sibling, 0 replies; 3+ messages in thread
From: patchwork-bot+netdevbpf @ 2024-04-03 10:10 UTC (permalink / raw)
To: Gustavo A. R. Silva
Cc: wenjia, jaka, alibuda, tonylu, guwen, davem, edumazet, kuba,
pabeni, linux-s390, netdev, linux-kernel, linux-hardening
Hello:
This patch was applied to netdev/net-next.git (main)
by David S. Miller <davem@davemloft.net>:
On Thu, 28 Mar 2024 15:52:49 -0600 you 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;
> ...
> };
>
> [...]
Here is the summary with links:
- [v4,next] net/smc: Avoid -Wflex-array-member-not-at-end warnings
https://git.kernel.org/netdev/net-next/c/9748dbc9f265
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2024-04-03 10:10 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-03-28 21:52 [PATCH v4][next] net/smc: Avoid -Wflex-array-member-not-at-end warnings Gustavo A. R. Silva
2024-04-01 3:34 ` Wen Gu
2024-04-03 10:10 ` patchwork-bot+netdevbpf
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.