From: Hannes Frederic Sowa Date: Wed, 8 Apr 2015 15:01:22 +0000 (+0200) Subject: ipv4: ip_tunnel: use net namespace from rtable not socket X-Git-Url: https://git.karo-electronics.de/?a=commitdiff_plain;h=926a882f6916fd76b6f8ee858d45a2241c5e7999;p=linux-beck.git ipv4: ip_tunnel: use net namespace from rtable not socket The socket parameter might legally be NULL, thus sock_net is sometimes causing a NULL pointer dereference. Using net_device pointer in dst_entry is more reliable. Fixes: b6a7719aedd7e5c ("ipv4: hash net ptr into fragmentation bucket selection") Reported-by: Rick Jones Cc: Rick Jones Cc: David S. Miller Signed-off-by: Hannes Frederic Sowa Signed-off-by: David S. Miller --- diff --git a/net/ipv4/ip_tunnel_core.c b/net/ipv4/ip_tunnel_core.c index 8c4dcc46acd2..ce63ab21b6cd 100644 --- a/net/ipv4/ip_tunnel_core.c +++ b/net/ipv4/ip_tunnel_core.c @@ -74,7 +74,8 @@ int iptunnel_xmit(struct sock *sk, struct rtable *rt, struct sk_buff *skb, iph->daddr = dst; iph->saddr = src; iph->ttl = ttl; - __ip_select_ident(sock_net(sk), iph, skb_shinfo(skb)->gso_segs ?: 1); + __ip_select_ident(dev_net(rt->dst.dev), iph, + skb_shinfo(skb)->gso_segs ?: 1); err = ip_local_out_sk(sk, skb); if (unlikely(net_xmit_eval(err)))