[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <8bf89095-4e5d-4111-8ae3-607e0beedd1e@linux.ibm.com>
Date: Sun, 11 Aug 2024 08:12:30 +0200
From: Jan Karcher <jaka@...ux.ibm.com>
To: "Gustavo A. R. Silva" <gustavoars@...nel.org>,
Wenjia Zhang <wenjia@...ux.ibm.com>,
"D. Wythe" <alibuda@...ux.alibaba.com>,
Tony Lu <tonylu@...ux.alibaba.com>, Wen Gu <guwen@...ux.alibaba.com>,
"David S. Miller" <davem@...emloft.net>,
Eric Dumazet <edumazet@...gle.com>, Jakub Kicinski <kuba@...nel.org>,
Paolo Abeni <pabeni@...hat.com>
Cc: linux-s390@...r.kernel.org, netdev@...r.kernel.org,
linux-kernel@...r.kernel.org, linux-hardening@...r.kernel.org
Subject: Re: [PATCH][next] net/smc: Use static_assert() to check struct sizes
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@...nel.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;
Powered by blists - more mailing lists