net: prevent NULL deref in ip[6]tunnel_xmit()
Subsystems (3)
PATCH v2 1/1 net: prevent NULL deref in ip[6]tunnel_xmit()
Blamed commit missed that both functions can be called with dev == NULL.
Also add unlikely() hints for these conditions that only fuzzers can hit.
---
I am sending v2 without the usual ~24 hours delay, hoping to catch our PR today.
v2: avoid DEV_STATS_INC(NULL, tx_errors) as well.
add unlikely() hints.
include/net/ip6_tunnel.h | 10 ++++++---- net/ipv4/ip_tunnel_core.c | 10 ++++++---- 2 files changed, 12 insertions(+), 8 deletions(-)
include/net/ip6_tunnel.h +6 -4
@@ -156,10 +156,12 @@ static inline void ip6tunnel_xmit(struct sock *sk, struct sk_buff *skb, {int pkt_len, err; -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); +if (unlikely (dev_recursion_level () >IP_TUNNEL_RECURSION_LIMIT )) { +if (dev) { +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 ; }
net/ipv4/ip_tunnel_core.c +6 -4
@@ -58,10 +58,12 @@ void iptunnel_xmit(struct sock *sk, struct rtable *rt, struct sk_buff *skb,struct iphdr *iph;int err; -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); +if (unlikely (dev_recursion_level () >IP_TUNNEL_RECURSION_LIMIT )) { +if (dev) { +net_crit_ratelimited ("Dead loop on virtual device %s, fix it urgently!\n" , + dev->name); +DEV_STATS_INC (dev, tx_errors); + }ip_rt_put (rt);kfree_skb (skb);return ;
Signature · 1 line
2.53.0.473.g4a7958ca14-goog
Quoted 3 lines · Eric Dumazet
Blamed commit missed that both functions can be called with dev == NULL.
Also add
unlikely()hints for these conditions that only fuzzers can hit.
Hi Eric,
Thank you for the quick fix. I missed the NULL dev case despite the existing if (dev) guard in iptunnel_xmit().
Thanks,
Weiming Shi
Quoted 59 lines
Fixes 6f1a9140ecda ("net: add xmit recursion limit to tunnel xmit functions")Signed-off-by Eric Dumazet <[email protected]>CC Weiming Shi <[email protected]>---
I am sending v2 without the usual ~24 hours delay, hoping to catch our PR today.
v2: avoid
DEV_STATS_INC(NULL, tx_errors)as well.
addunlikely()hints.include/net/ip6_tunnel.h | 10 ++++++---- net/ipv4/ip_tunnel_core.c | 10 ++++++---- 2 files changed, 12 insertions(+), 8 deletions(-)include/net/ip6_tunnel.h +6
-4@@ -156,10 +156,12 @@ static inline void ip6tunnel_xmit(struct sock *sk, struct sk_buff *skb, {int pkt_len, err; -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); +if (unlikely (dev_recursion_level () >IP_TUNNEL_RECURSION_LIMIT )) { +if (dev) { +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 ; }net/ipv4/ip_tunnel_core.c +6
-4@@ -58,10 +58,12 @@ void iptunnel_xmit(struct sock *sk, struct rtable *rt, struct sk_buff *skb,struct iphdr *iph;int err; -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); +if (unlikely (dev_recursion_level () >IP_TUNNEL_RECURSION_LIMIT )) { +if (dev) { +net_crit_ratelimited ("Dead loop on virtual device %s, fix it urgently!\n" , + dev->name); +DEV_STATS_INC (dev, tx_errors); + }ip_rt_put (rt);kfree_skb (skb);return ;Signature · 1 line
2.53.0.473.g4a7958ca14-goog
This patch was applied to netdev/net.git (main) by Paolo Abeni <[email protected]>:
Hello:
This patch was applied to netdev/net.git (main)
by Paolo Abeni <[email protected]>:
Quoted 9 lines · On Thu, 12 Mar 2026 04:39:08 +0000 you wrote:
Blamed commit missed that both functions can be called with dev == NULL.
Also add
unlikely()hints for these conditions that only fuzzers can hit.Fixes 6f1a9140ecda ("net: add xmit recursion limit to tunnel xmit functions")Signed-off-by Eric Dumazet <[email protected]>CC Weiming Shi <[email protected]>[...]
Here is the summary with links:
- [v2,net] net: prevent NULL deref in ip[6]tunnel_xmit()
https://git.kernel.org/netdev/net/c/c38b8f5f791e
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html