* [PATCH][next] net/smc: Use static_assert() to check struct sizes
@ 2024-08-08 22:07 Gustavo A. R. Silva
2024-08-11 6:12 ` Jan Karcher
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Gustavo A. R. Silva @ 2024-08-08 22:07 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
Commit 9748dbc9f265 ("net/smc: Avoid -Wflex-array-member-not-at-end
warnings") introduced tagged `struct smc_clc_v2_extension_fixed` and
`struct smc_clc_smcd_v2_extension_fixed`. We want to ensure that when
new members need to be added to the flexible structures, they are
always included within these tagged structs.
So, we use `static_assert()` to ensure that the memory layout for
both the flexible structure and the tagged struct is the same after
any changes.
Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
---
net/smc/smc_clc.h | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/net/smc/smc_clc.h b/net/smc/smc_clc.h
index 467effb50cd6..5625fda2960b 100644
--- a/net/smc/smc_clc.h
+++ b/net/smc/smc_clc.h
@@ -145,6 +145,8 @@ struct smc_clc_v2_extension {
);
u8 user_eids[][SMC_MAX_EID_LEN];
};
+static_assert(offsetof(struct smc_clc_v2_extension, user_eids) == sizeof(struct smc_clc_v2_extension_fixed),
+ "struct member likely outside of struct_group_tagged()");
struct smc_clc_msg_proposal_prefix { /* prefix part of clc proposal message*/
__be32 outgoing_subnet; /* subnet mask */
@@ -169,6 +171,8 @@ struct smc_clc_smcd_v2_extension {
);
struct smc_clc_smcd_gid_chid gidchid[];
};
+static_assert(offsetof(struct smc_clc_smcd_v2_extension, gidchid) == sizeof(struct smc_clc_smcd_v2_extension_fixed),
+ "struct member likely outside of struct_group_tagged()");
struct smc_clc_msg_proposal { /* clc proposal message sent by Linux */
struct smc_clc_msg_hdr hdr;
--
2.34.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH][next] net/smc: Use static_assert() to check struct sizes
2024-08-08 22:07 [PATCH][next] net/smc: Use static_assert() to check struct sizes Gustavo A. R. Silva
@ 2024-08-11 6:12 ` Jan Karcher
2024-08-12 6:29 ` Jan Karcher
2024-08-13 2:10 ` patchwork-bot+netdevbpf
2 siblings, 0 replies; 4+ messages in thread
From: Jan Karcher @ 2024-08-11 6:12 UTC (permalink / raw)
To: Gustavo A. R. Silva, Wenjia Zhang, D. Wythe, Tony Lu, Wen Gu,
David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni
Cc: linux-s390, netdev, linux-kernel, linux-hardening
On 09/08/2024 00:07, Gustavo A. R. Silva wrote:
> Commit 9748dbc9f265 ("net/smc: Avoid -Wflex-array-member-not-at-end
> warnings") introduced tagged `struct smc_clc_v2_extension_fixed` and
> `struct smc_clc_smcd_v2_extension_fixed`. We want to ensure that when
> new members need to be added to the flexible structures, they are
> always included within these tagged structs.
>
> So, we use `static_assert()` to ensure that the memory layout for
> both the flexible structure and the tagged struct is the same after
> any changes.
Hi Gustavo,
good catch. By reviewing it, it makes sense to me. Please let me give it
a run with our test-suite before adding a r-b.
Thanks
- J
>
> Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
> ---
> net/smc/smc_clc.h | 4 ++++
> 1 file changed, 4 insertions(+)
>
> diff --git a/net/smc/smc_clc.h b/net/smc/smc_clc.h
> index 467effb50cd6..5625fda2960b 100644
> --- a/net/smc/smc_clc.h
> +++ b/net/smc/smc_clc.h
> @@ -145,6 +145,8 @@ struct smc_clc_v2_extension {
> );
> u8 user_eids[][SMC_MAX_EID_LEN];
> };
> +static_assert(offsetof(struct smc_clc_v2_extension, user_eids) == sizeof(struct smc_clc_v2_extension_fixed),
> + "struct member likely outside of struct_group_tagged()");
>
> struct smc_clc_msg_proposal_prefix { /* prefix part of clc proposal message*/
> __be32 outgoing_subnet; /* subnet mask */
> @@ -169,6 +171,8 @@ struct smc_clc_smcd_v2_extension {
> );
> struct smc_clc_smcd_gid_chid gidchid[];
> };
> +static_assert(offsetof(struct smc_clc_smcd_v2_extension, gidchid) == sizeof(struct smc_clc_smcd_v2_extension_fixed),
> + "struct member likely outside of struct_group_tagged()");
>
> struct smc_clc_msg_proposal { /* clc proposal message sent by Linux */
> struct smc_clc_msg_hdr hdr;
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH][next] net/smc: Use static_assert() to check struct sizes
2024-08-08 22:07 [PATCH][next] net/smc: Use static_assert() to check struct sizes Gustavo A. R. Silva
2024-08-11 6:12 ` Jan Karcher
@ 2024-08-12 6:29 ` Jan Karcher
2024-08-13 2:10 ` patchwork-bot+netdevbpf
2 siblings, 0 replies; 4+ messages in thread
From: Jan Karcher @ 2024-08-12 6:29 UTC (permalink / raw)
To: Gustavo A. R. Silva, Wenjia Zhang, D. Wythe, Tony Lu, Wen Gu,
David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni
Cc: linux-s390, netdev, linux-kernel, linux-hardening
On 09/08/2024 00:07, Gustavo A. R. Silva wrote:
> Commit 9748dbc9f265 ("net/smc: Avoid -Wflex-array-member-not-at-end
> warnings") introduced tagged `struct smc_clc_v2_extension_fixed` and
> `struct smc_clc_smcd_v2_extension_fixed`. We want to ensure that when
> new members need to be added to the flexible structures, they are
> always included within these tagged structs.
>
> So, we use `static_assert()` to ensure that the memory layout for
> both the flexible structure and the tagged struct is the same after
> any changes.
Read up what the macro does. I like it.
Compile tested on s390.
Reviewed-by: Jan Karcher <jaka@linux.ibm.com>
>
> Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
> ---
> net/smc/smc_clc.h | 4 ++++
> 1 file changed, 4 insertions(+)
>
> diff --git a/net/smc/smc_clc.h b/net/smc/smc_clc.h
> index 467effb50cd6..5625fda2960b 100644
> --- a/net/smc/smc_clc.h
> +++ b/net/smc/smc_clc.h
> @@ -145,6 +145,8 @@ struct smc_clc_v2_extension {
> );
> u8 user_eids[][SMC_MAX_EID_LEN];
> };
> +static_assert(offsetof(struct smc_clc_v2_extension, user_eids) == sizeof(struct smc_clc_v2_extension_fixed),
> + "struct member likely outside of struct_group_tagged()");
>
> struct smc_clc_msg_proposal_prefix { /* prefix part of clc proposal message*/
> __be32 outgoing_subnet; /* subnet mask */
> @@ -169,6 +171,8 @@ struct smc_clc_smcd_v2_extension {
> );
> struct smc_clc_smcd_gid_chid gidchid[];
> };
> +static_assert(offsetof(struct smc_clc_smcd_v2_extension, gidchid) == sizeof(struct smc_clc_smcd_v2_extension_fixed),
> + "struct member likely outside of struct_group_tagged()");
>
> struct smc_clc_msg_proposal { /* clc proposal message sent by Linux */
> struct smc_clc_msg_hdr hdr;
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH][next] net/smc: Use static_assert() to check struct sizes
2024-08-08 22:07 [PATCH][next] net/smc: Use static_assert() to check struct sizes Gustavo A. R. Silva
2024-08-11 6:12 ` Jan Karcher
2024-08-12 6:29 ` Jan Karcher
@ 2024-08-13 2:10 ` patchwork-bot+netdevbpf
2 siblings, 0 replies; 4+ messages in thread
From: patchwork-bot+netdevbpf @ 2024-08-13 2: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 Jakub Kicinski <kuba@kernel.org>:
On Thu, 8 Aug 2024 16:07:54 -0600 you wrote:
> Commit 9748dbc9f265 ("net/smc: Avoid -Wflex-array-member-not-at-end
> warnings") introduced tagged `struct smc_clc_v2_extension_fixed` and
> `struct smc_clc_smcd_v2_extension_fixed`. We want to ensure that when
> new members need to be added to the flexible structures, they are
> always included within these tagged structs.
>
> So, we use `static_assert()` to ensure that the memory layout for
> both the flexible structure and the tagged struct is the same after
> any changes.
>
> [...]
Here is the summary with links:
- [next] net/smc: Use static_assert() to check struct sizes
https://git.kernel.org/netdev/net-next/c/0a3e6939d4b3
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] 4+ messages in thread
end of thread, other threads:[~2024-08-13 2:10 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-08-08 22:07 [PATCH][next] net/smc: Use static_assert() to check struct sizes Gustavo A. R. Silva
2024-08-11 6:12 ` Jan Karcher
2024-08-12 6:29 ` Jan Karcher
2024-08-13 2:10 ` patchwork-bot+netdevbpf
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).