Re: [net,v2] net: add xmit recursion limit to tunnel drivers
From: Paolo Abeni
Date: Thu Mar 05 2026 - 09:39:52 EST
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).