Linux Hardening
 help / color / mirror / Atom feed
From: Alexander Lobakin <aleksander.lobakin@intel.com>
To: Gal Pressman <gal@nvidia.com>
Cc: <netdev@vger.kernel.org>, "David S. Miller" <davem@davemloft.net>,
	"Eric Dumazet" <edumazet@google.com>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
	Andrew Lunn <andrew+netdev@lunn.ch>,
	Tariq Toukan <tariqt@nvidia.com>,
	Louis Peens <louis.peens@corigine.com>,
	Simon Horman <horms@kernel.org>, David Ahern <dsahern@kernel.org>,
	Pravin B Shelar <pshelar@ovn.org>,
	Yotam Gigi <yotam.gi@gmail.com>,
	Jamal Hadi Salim <jhs@mojatatu.com>,
	Cong Wang <xiyou.wangcong@gmail.com>,
	Jiri Pirko <jiri@resnulli.us>, Kees Cook <kees@kernel.org>,
	"Gustavo A. R. Silva" <gustavoars@kernel.org>,
	<dev@openvswitch.org>, <linux-hardening@vger.kernel.org>,
	Ilya Maximets <i.maximets@ovn.org>,
	"Cosmin Ratiu" <cratiu@nvidia.com>
Subject: Re: [PATCH net-next v2] net: Add options as a flexible array to struct ip_tunnel_info
Date: Wed, 12 Feb 2025 17:29:40 +0100	[thread overview]
Message-ID: <f9adb864-8ed5-4368-a880-b2aac8aac885@intel.com> (raw)
In-Reply-To: <20250212140953.107533-1-gal@nvidia.com>

From: Gal Pressman <gal@nvidia.com>
Date: Wed, 12 Feb 2025 16:09:53 +0200

> Remove the hidden assumption that options are allocated at the end of
> the struct, and teach the compiler about them using a flexible array.

[...]

> diff --git a/include/net/dst_metadata.h b/include/net/dst_metadata.h
> index 84c15402931c..4160731dcb6e 100644
> --- a/include/net/dst_metadata.h
> +++ b/include/net/dst_metadata.h
> @@ -163,11 +163,8 @@ static inline struct metadata_dst *tun_dst_unclone(struct sk_buff *skb)
>  	if (!new_md)
>  		return ERR_PTR(-ENOMEM);
>  
> -	unsafe_memcpy(&new_md->u.tun_info, &md_dst->u.tun_info,
> -		      sizeof(struct ip_tunnel_info) + md_size,
> -		      /* metadata_dst_alloc() reserves room (md_size bytes) for
> -		       * options right after the ip_tunnel_info struct.
> -		       */);
> +	memcpy(&new_md->u.tun_info, &md_dst->u.tun_info,
> +	       sizeof(struct ip_tunnel_info) + md_size);
>  #ifdef CONFIG_DST_CACHE
>  	/* Unclone the dst cache if there is one */
>  	if (new_md->u.tun_info.dst_cache.cache) {
> diff --git a/include/net/ip_tunnels.h b/include/net/ip_tunnels.h
> index 1aa31bdb2b31..517f78070be0 100644
> --- a/include/net/ip_tunnels.h
> +++ b/include/net/ip_tunnels.h
> @@ -93,12 +93,6 @@ struct ip_tunnel_encap {
>  	GENMASK((sizeof_field(struct ip_tunnel_info,		\
>  			      options_len) * BITS_PER_BYTE) - 1, 0)
>  
> -#define ip_tunnel_info_opts(info)				\
> -	_Generic(info,						\
> -		 const struct ip_tunnel_info * : ((const void *)((info) + 1)),\
> -		 struct ip_tunnel_info * : ((void *)((info) + 1))\
> -	)

You could leave this macro inplace and just change `(info) + 1` to
`(info)->options` avoiding changes in lots of files and adding casts
everywhere.

> -
>  struct ip_tunnel_info {
>  	struct ip_tunnel_key	key;
>  	struct ip_tunnel_encap	encap;
> @@ -107,6 +101,7 @@ struct ip_tunnel_info {
>  #endif
>  	u8			options_len;
>  	u8			mode;
> +	u8			options[] __aligned(sizeof(void *)) __counted_by(options_len);

Since 96 % 16 == 0, I'd check if __aligned_largest would change the
bytecode anyhow... Sometimes it does.

Thanks,
Olek

  reply	other threads:[~2025-02-12 16:34 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-02-12 14:09 [PATCH net-next v2] net: Add options as a flexible array to struct ip_tunnel_info Gal Pressman
2025-02-12 16:29 ` Alexander Lobakin [this message]
2025-02-12 18:13   ` Gal Pressman
2025-02-13  1:55     ` Jakub Kicinski

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=f9adb864-8ed5-4368-a880-b2aac8aac885@intel.com \
    --to=aleksander.lobakin@intel.com \
    --cc=andrew+netdev@lunn.ch \
    --cc=cratiu@nvidia.com \
    --cc=davem@davemloft.net \
    --cc=dev@openvswitch.org \
    --cc=dsahern@kernel.org \
    --cc=edumazet@google.com \
    --cc=gal@nvidia.com \
    --cc=gustavoars@kernel.org \
    --cc=horms@kernel.org \
    --cc=i.maximets@ovn.org \
    --cc=jhs@mojatatu.com \
    --cc=jiri@resnulli.us \
    --cc=kees@kernel.org \
    --cc=kuba@kernel.org \
    --cc=linux-hardening@vger.kernel.org \
    --cc=louis.peens@corigine.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=pshelar@ovn.org \
    --cc=tariqt@nvidia.com \
    --cc=xiyou.wangcong@gmail.com \
    --cc=yotam.gi@gmail.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