Skip to content

Commit c38b8f5

Browse files
edumazetPaolo Abeni
authored andcommitted
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. Fixes: 6f1a914 ("net: add xmit recursion limit to tunnel xmit functions") Signed-off-by: Eric Dumazet <[email protected]> CC: Weiming Shi <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Paolo Abeni <[email protected]>
1 parent 87f7dff commit c38b8f5

2 files changed

Lines changed: 12 additions & 8 deletions

File tree

include/net/ip6_tunnel.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -156,10 +156,12 @@ static inline void ip6tunnel_xmit(struct sock *sk, struct sk_buff *skb,
156156
{
157157
int pkt_len, err;
158158

159-
if (dev_recursion_level() > IP_TUNNEL_RECURSION_LIMIT) {
160-
net_crit_ratelimited("Dead loop on virtual device %s, fix it urgently!\n",
161-
dev->name);
162-
DEV_STATS_INC(dev, tx_errors);
159+
if (unlikely(dev_recursion_level() > IP_TUNNEL_RECURSION_LIMIT)) {
160+
if (dev) {
161+
net_crit_ratelimited("Dead loop on virtual device %s, fix it urgently!\n",
162+
dev->name);
163+
DEV_STATS_INC(dev, tx_errors);
164+
}
163165
kfree_skb(skb);
164166
return;
165167
}

net/ipv4/ip_tunnel_core.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,12 @@ void iptunnel_xmit(struct sock *sk, struct rtable *rt, struct sk_buff *skb,
5858
struct iphdr *iph;
5959
int err;
6060

61-
if (dev_recursion_level() > IP_TUNNEL_RECURSION_LIMIT) {
62-
net_crit_ratelimited("Dead loop on virtual device %s, fix it urgently!\n",
63-
dev->name);
64-
DEV_STATS_INC(dev, tx_errors);
61+
if (unlikely(dev_recursion_level() > IP_TUNNEL_RECURSION_LIMIT)) {
62+
if (dev) {
63+
net_crit_ratelimited("Dead loop on virtual device %s, fix it urgently!\n",
64+
dev->name);
65+
DEV_STATS_INC(dev, tx_errors);
66+
}
6567
ip_rt_put(rt);
6668
kfree_skb(skb);
6769
return;

0 commit comments

Comments
 (0)