vxlan: lock RCU on TX path
authorJakub Kicinski <jakub.kicinski@netronome.com>
Fri, 24 Feb 2017 19:43:36 +0000 (11:43 -0800)
committerDavid S. Miller <davem@davemloft.net>
Wed, 1 Mar 2017 17:58:31 +0000 (09:58 -0800)
There is no guarantees that callers of the TX path will hold
the RCU lock.  Grab it explicitly.

Fixes: c6fcc4fc5f8b ("vxlan: avoid using stale vxlan socket.")
Signed-off-by: Jakub Kicinski <jakub.kicinski@netronome.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/vxlan.c

index b7911994112aebecc691117e15ab32a7c238fdf9..e375560cc74e5ffc09553ddab5c6b657fe1cb6f0 100644 (file)
@@ -2105,6 +2105,7 @@ static void vxlan_xmit_one(struct sk_buff *skb, struct net_device *dev,
        src_port = udp_flow_src_port(dev_net(dev), skb, vxlan->cfg.port_min,
                                     vxlan->cfg.port_max, true);
 
+       rcu_read_lock();
        if (dst->sa.sa_family == AF_INET) {
                struct vxlan_sock *sock4 = rcu_dereference(vxlan->vn4_sock);
                struct rtable *rt;
@@ -2127,7 +2128,7 @@ static void vxlan_xmit_one(struct sk_buff *skb, struct net_device *dev,
                                                    dst_port, vni, &rt->dst,
                                                    rt->rt_flags);
                        if (err)
-                               return;
+                               goto out_unlock;
                } else if (info->key.tun_flags & TUNNEL_DONT_FRAGMENT) {
                        df = htons(IP_DF);
                }
@@ -2166,7 +2167,7 @@ static void vxlan_xmit_one(struct sk_buff *skb, struct net_device *dev,
                                                    dst_port, vni, ndst,
                                                    rt6i_flags);
                        if (err)
-                               return;
+                               goto out_unlock;
                }
 
                tos = ip_tunnel_ecn_encap(tos, old_iph, skb);
@@ -2183,6 +2184,8 @@ static void vxlan_xmit_one(struct sk_buff *skb, struct net_device *dev,
                                     label, src_port, dst_port, !udp_sum);
 #endif
        }
+out_unlock:
+       rcu_read_unlock();
        return;
 
 drop:
@@ -2191,6 +2194,7 @@ drop:
        return;
 
 tx_error:
+       rcu_read_unlock();
        if (err == -ELOOP)
                dev->stats.collisions++;
        else if (err == -ENETUNREACH)