public inbox for netdev@vger.kernel.org
 help / color / mirror / Atom feed
From: Paolo Abeni <pabeni@redhat.com>
To: bestswngs@gmail.com
Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
	xmei5@asu.edu, kuba@kernel.org, horms@kernel.org,
	pabeni@redhat.com, davem@davemloft.net, edumazet@google.com,
	security@kernel.org
Subject: Re: [net,v2] net: add xmit recursion limit to tunnel drivers
Date: Thu,  5 Mar 2026 15:23:38 +0100	[thread overview]
Message-ID: <20260305142338.369328-1-pabeni@redhat.com> (raw)
In-Reply-To: <20260303164326.1803916-2-bestswngs@gmail.com>

This is an AI-generated review of your patch. The human sending this
email has considered the AI review valid, or at least plausible.

For local reproduction steps see https://netdev-ai.bots.linux.dev/ai-local.html
---
net: add xmit recursion limit to tunnel drivers

This commit adds recursion protection to tunnel drivers to prevent stack
exhaustion from routing loops. It moves dev_xmit_recursion helpers to a
public header and adds recursion checks in ip_tunnel_xmit() and
ip6_tnl_xmit().

> diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
> index d4e6e00bb90a..1a4d2542dbab 100644
> --- a/include/linux/netdevice.h
> +++ b/include/linux/netdevice.h

[ ... ]

> diff --git a/include/net/ip_tunnels.h b/include/net/ip_tunnels.h
> index 4021e6a73e32..80662f812080 100644
> --- a/include/net/ip_tunnels.h
> +++ b/include/net/ip_tunnels.h

[ ... ]

> diff --git a/net/core/dev.h b/net/core/dev.h
> index 98793a738f43..ec974b3c42d9 100644
> --- a/net/core/dev.h
> +++ b/net/core/dev.h

[ ... ]

> diff --git a/net/ipv4/ip_tunnel.c b/net/ipv4/ip_tunnel.c
> index 50d0f5fe4e4c..39822e845a06 100644
> --- a/net/ipv4/ip_tunnel.c
> +++ b/net/ipv4/ip_tunnel.c

[ ... ]

> diff --git a/net/ipv6/ip6_tunnel.c b/net/ipv6/ip6_tunnel.c
> index 4c29aa94e86e..55bedd5cd656 100644
> --- a/net/ipv6/ip6_tunnel.c
> +++ b/net/ipv6/ip6_tunnel.c
> @@ -1101,6 +1101,14 @@ int ip6_tnl_xmit(struct sk_buff *skb, struct net_device *dev, __u8 dsfield,
>  	u8 hop_limit;
>  	int err = -1;
>
> +	if (dev_recursion_level() > IP_TUNNEL_RECURSION_LIMIT) {
> +		net_crit_ratelimited("Dead loop on virtual device %s, fix it urgently!\n",
> +				     dev->name);
> +		DEV_STATS_INC(dev, tx_errors);
> +		kfree_skb(skb);
> +		return -1;
> +	}
> +

Does this create a double-free of skb in ip6_tnl_xmit()?

The new recursion check frees the skb and returns -1. But all callers of
ip6_tnl_xmit() also free the skb when they receive a non-zero error return:

ip6erspan_tunnel_xmit() at net/ipv6/ip6_gre.c calls kfree_skb(skb) in its
tx_err path after ip6_tnl_xmit returns -1:

net/ipv6/ip6_gre.c:ip6erspan_tunnel_xmit() {
    ...
    if (ip6_tnl_xmit(skb, dev, dsfield, &fl6, encap_limit, &mtu,
                     NEXTHDR_GRE))
        goto tx_err;
    ...
tx_err:
    if (!IS_ERR(tun_dst))
        dst_cache_set_ip6(&t->dst_cache, &tun_dst->u.tun_info.key.u.ipv6.dst,
                          &fl6.saddr);
    DEV_STATS_INC(dev, tx_errors);
    kfree_skb(skb);
    return NETDEV_TX_OK;
}

Similarly, ip6_tnl_start_xmit() at net/ipv6/ip6_tunnel.c calls kfree_skb(skb)
after ipxip6_tnl_xmit propagates the -1:

net/ipv6/ip6_tunnel.c:ip6_tnl_start_xmit() {
    ...
    ret = ipxip6_tnl_xmit(skb, dev, dsfield, &fl6, encap_limit, &mtu,
                          protocol);
    if (ret < 0)
        goto tx_err;
    ...
tx_err:
    DEV_STATS_INC(dev, tx_errors);
    kfree_skb(skb);
    return NETDEV_TX_OK;
}

The existing error-return contract of ip6_tnl_xmit() is that the caller
retains skb ownership on error. All pre-existing error paths
(tx_err_link_failure, tx_err_dst_release, ip6_tnl_encap failure) return
negative without freeing skb.

The new recursion check breaks this contract by freeing skb AND returning -1,
causing the caller to kfree_skb() an already-freed skb. This double-free will
cause slab corruption or a crash exactly when the recursion protection
triggers.

Note the IPv4 counterpart ip_tunnel_xmit() is not affected because it returns
void and always owns the skb (its existing error paths also kfree_skb
internally).


  reply	other threads:[~2026-03-05 14:24 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-03 16:43 [PATCH net v2] net: add xmit recursion limit to tunnel drivers bestswngs
2026-03-05 14:23 ` Paolo Abeni [this message]
2026-03-05 14:34 ` Paolo Abeni
2026-03-05 17:08   ` Weiming Shi

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=20260305142338.369328-1-pabeni@redhat.com \
    --to=pabeni@redhat.com \
    --cc=bestswngs@gmail.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=horms@kernel.org \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=security@kernel.org \
    --cc=xmei5@asu.edu \
    /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