diff mbox series

[net-next,v3,1/2] ip_tunnel: Use ip_tunnel_info() helper instead of 'info + 1'

Message ID 20250217202503.265318-2-gal@nvidia.com (mailing list archive)
State Superseded
Delegated to: Netdev Maintainers
Headers show
Series Flexible array for ip tunnel options | expand

Checks

Context Check Description
netdev/series_format success Posting correctly formatted
netdev/tree_selection success Clearly marked for net-next
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 1 this patch: 1
netdev/build_tools success Errors and warnings before: 26 (+1) this patch: 26 (+1)
netdev/cc_maintainers success CCed 9 of 9 maintainers
netdev/build_clang success Errors and warnings before: 53 this patch: 53
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 185 this patch: 185
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 34 lines checked
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0
netdev/contest success net-next-2025-02-18--00-00 (tests: 891)

Commit Message

Gal Pressman Feb. 17, 2025, 8:25 p.m. UTC
Tunnel options should not be accessed directly, use the ip_tunnel_info()
accessor instead.

Signed-off-by: Gal Pressman <gal@nvidia.com>
---
 include/net/ip_tunnels.h   | 2 +-
 net/sched/act_tunnel_key.c | 8 +++++---
 2 files changed, 6 insertions(+), 4 deletions(-)

Comments

Jakub Kicinski Feb. 19, 2025, 2:45 a.m. UTC | #1
On Mon, 17 Feb 2025 22:25:02 +0200 Gal Pressman wrote:
> diff --git a/net/sched/act_tunnel_key.c b/net/sched/act_tunnel_key.c
> index af7c99845948..6d97be6bc7fa 100644
> --- a/net/sched/act_tunnel_key.c
> +++ b/net/sched/act_tunnel_key.c
> @@ -572,7 +572,7 @@ static int tunnel_key_geneve_opts_dump(struct sk_buff *skb,
>  				       const struct ip_tunnel_info *info)
>  {
>  	int len = info->options_len;
> -	u8 *src = (u8 *)(info + 1);
> +	u8 *src = (u8 *)ip_tunnel_info_opts(info);
>  	struct nlattr *start;
>  
>  	start = nla_nest_start_noflag(skb, TCA_TUNNEL_KEY_ENC_OPTS_GENEVE);
> @@ -603,7 +603,8 @@ static int tunnel_key_geneve_opts_dump(struct sk_buff *skb,
>  static int tunnel_key_vxlan_opts_dump(struct sk_buff *skb,
>  				      const struct ip_tunnel_info *info)
>  {
> -	struct vxlan_metadata *md = (struct vxlan_metadata *)(info + 1);
> +	struct vxlan_metadata *md =
> +		(struct vxlan_metadata *)ip_tunnel_info_opts(info);
>  	struct nlattr *start;
>  
>  	start = nla_nest_start_noflag(skb, TCA_TUNNEL_KEY_ENC_OPTS_VXLAN);
> @@ -622,7 +623,8 @@ static int tunnel_key_vxlan_opts_dump(struct sk_buff *skb,
>  static int tunnel_key_erspan_opts_dump(struct sk_buff *skb,
>  				       const struct ip_tunnel_info *info)
>  {
> -	struct erspan_metadata *md = (struct erspan_metadata *)(info + 1);
> +	struct erspan_metadata *md =
> +		(struct erspan_metadata *)ip_tunnel_info_opts(info);
>  	struct nlattr *start;

We shouldn't cast the const away any more. 
Squash this in, please:

diff --git a/net/sched/act_tunnel_key.c b/net/sched/act_tunnel_key.c
index 6d97be6bc7fa..ae5dea7c48a8 100644
--- a/net/sched/act_tunnel_key.c
+++ b/net/sched/act_tunnel_key.c
@@ -569,20 +569,20 @@ static void tunnel_key_release(struct tc_action *a)
 }
 
 static int tunnel_key_geneve_opts_dump(struct sk_buff *skb,
                                       const struct ip_tunnel_info *info)
 {
+       const u8 *src = ip_tunnel_info_opts(info);
        int len = info->options_len;
-       u8 *src = (u8 *)ip_tunnel_info_opts(info);
        struct nlattr *start;
 
        start = nla_nest_start_noflag(skb, TCA_TUNNEL_KEY_ENC_OPTS_GENEVE);
        if (!start)
                return -EMSGSIZE;
 
        while (len > 0) {
-               struct geneve_opt *opt = (struct geneve_opt *)src;
+               const struct geneve_opt *opt = (const struct geneve_opt *)src;
 
                if (nla_put_be16(skb, TCA_TUNNEL_KEY_ENC_OPT_GENEVE_CLASS,
                                 opt->opt_class) ||
                    nla_put_u8(skb, TCA_TUNNEL_KEY_ENC_OPT_GENEVE_TYPE,
                               opt->type) ||
@@ -601,12 +601,11 @@ static int tunnel_key_geneve_opts_dump(struct sk_buff *skb,
 }
 
 static int tunnel_key_vxlan_opts_dump(struct sk_buff *skb,
                                      const struct ip_tunnel_info *info)
 {
-       struct vxlan_metadata *md =
-               (struct vxlan_metadata *)ip_tunnel_info_opts(info);
+       const struct vxlan_metadata *md = ip_tunnel_info_opts(info);
        struct nlattr *start;
 
        start = nla_nest_start_noflag(skb, TCA_TUNNEL_KEY_ENC_OPTS_VXLAN);
        if (!start)
                return -EMSGSIZE;
@@ -621,12 +620,11 @@ static int tunnel_key_vxlan_opts_dump(struct sk_buff *skb,
 }
 
 static int tunnel_key_erspan_opts_dump(struct sk_buff *skb,
                                       const struct ip_tunnel_info *info)
 {
-       struct erspan_metadata *md =
-               (struct erspan_metadata *)ip_tunnel_info_opts(info);
+       const struct erspan_metadata *md = ip_tunnel_info_opts(info);
        struct nlattr *start;
 
        start = nla_nest_start_noflag(skb, TCA_TUNNEL_KEY_ENC_OPTS_ERSPAN);
        if (!start)
                return -EMSGSIZE;
diff mbox series

Patch

diff --git a/include/net/ip_tunnels.h b/include/net/ip_tunnels.h
index 1aa31bdb2b31..7b54cea5de27 100644
--- a/include/net/ip_tunnels.h
+++ b/include/net/ip_tunnels.h
@@ -650,7 +650,7 @@  static inline void iptunnel_xmit_stats(struct net_device *dev, int pkt_len)
 static inline void ip_tunnel_info_opts_get(void *to,
 					   const struct ip_tunnel_info *info)
 {
-	memcpy(to, info + 1, info->options_len);
+	memcpy(to, ip_tunnel_info_opts(info), info->options_len);
 }
 
 static inline void ip_tunnel_info_opts_set(struct ip_tunnel_info *info,
diff --git a/net/sched/act_tunnel_key.c b/net/sched/act_tunnel_key.c
index af7c99845948..6d97be6bc7fa 100644
--- a/net/sched/act_tunnel_key.c
+++ b/net/sched/act_tunnel_key.c
@@ -572,7 +572,7 @@  static int tunnel_key_geneve_opts_dump(struct sk_buff *skb,
 				       const struct ip_tunnel_info *info)
 {
 	int len = info->options_len;
-	u8 *src = (u8 *)(info + 1);
+	u8 *src = (u8 *)ip_tunnel_info_opts(info);
 	struct nlattr *start;
 
 	start = nla_nest_start_noflag(skb, TCA_TUNNEL_KEY_ENC_OPTS_GENEVE);
@@ -603,7 +603,8 @@  static int tunnel_key_geneve_opts_dump(struct sk_buff *skb,
 static int tunnel_key_vxlan_opts_dump(struct sk_buff *skb,
 				      const struct ip_tunnel_info *info)
 {
-	struct vxlan_metadata *md = (struct vxlan_metadata *)(info + 1);
+	struct vxlan_metadata *md =
+		(struct vxlan_metadata *)ip_tunnel_info_opts(info);
 	struct nlattr *start;
 
 	start = nla_nest_start_noflag(skb, TCA_TUNNEL_KEY_ENC_OPTS_VXLAN);
@@ -622,7 +623,8 @@  static int tunnel_key_vxlan_opts_dump(struct sk_buff *skb,
 static int tunnel_key_erspan_opts_dump(struct sk_buff *skb,
 				       const struct ip_tunnel_info *info)
 {
-	struct erspan_metadata *md = (struct erspan_metadata *)(info + 1);
+	struct erspan_metadata *md =
+		(struct erspan_metadata *)ip_tunnel_info_opts(info);
 	struct nlattr *start;
 
 	start = nla_nest_start_noflag(skb, TCA_TUNNEL_KEY_ENC_OPTS_ERSPAN);