mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Jan Karcher <jaka@linux.ibm.com>
To: "Gustavo A. R. Silva" <gustavoars@kernel.org>,
	Wenjia Zhang <wenjia@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>
Cc: 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: Use static_assert() to check struct sizes
Date: Mon, 12 Aug 2024 08:29:26 +0200	[thread overview]
Message-ID: <90da4cb0-a422-405d-b5f9-99eba490071f@linux.ibm.com> (raw)
In-Reply-To: <ZrVBuiqFHAORpFxE@cute>



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;

  parent reply	other threads:[~2024-08-12  6:29 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-08-08 22:07 Gustavo A. R. Silva
2024-08-11  6:12 ` Jan Karcher
2024-08-12  6:29 ` Jan Karcher [this message]
2024-08-13  2:10 ` patchwork-bot+netdevbpf

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=90da4cb0-a422-405d-b5f9-99eba490071f@linux.ibm.com \
    --to=jaka@linux.ibm.com \
    --cc=alibuda@linux.alibaba.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=gustavoars@kernel.org \
    --cc=guwen@linux.alibaba.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

all inboxes | Powered by JetHome®