Commit 0f9ea5d2 authored by Eric Dumazet's avatar Eric Dumazet Committed by Roland Dreier

RDMA/addr: Use appropriate locking with for_each_netdev()

for_each_netdev() should be used with RTNL or dev_base_lock held,
or else we risk a crash.
Signed-off-by: default avatarEric Dumazet <eric.dumazet@gmail.com>
Signed-off-by: default avatarSean Hefty <sean.hefty@intel.com>
Signed-off-by: default avatarRoland Dreier <rolandd@cisco.com>
parent a7ca1f00
...@@ -131,6 +131,7 @@ int rdma_translate_ip(struct sockaddr *addr, struct rdma_dev_addr *dev_addr) ...@@ -131,6 +131,7 @@ int rdma_translate_ip(struct sockaddr *addr, struct rdma_dev_addr *dev_addr)
#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE) #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
case AF_INET6: case AF_INET6:
read_lock(&dev_base_lock);
for_each_netdev(&init_net, dev) { for_each_netdev(&init_net, dev) {
if (ipv6_chk_addr(&init_net, if (ipv6_chk_addr(&init_net,
&((struct sockaddr_in6 *) addr)->sin6_addr, &((struct sockaddr_in6 *) addr)->sin6_addr,
...@@ -139,6 +140,7 @@ int rdma_translate_ip(struct sockaddr *addr, struct rdma_dev_addr *dev_addr) ...@@ -139,6 +140,7 @@ int rdma_translate_ip(struct sockaddr *addr, struct rdma_dev_addr *dev_addr)
break; break;
} }
} }
read_unlock(&dev_base_lock);
break; break;
#endif #endif
} }
...@@ -391,14 +393,17 @@ static int addr_resolve_local(struct sockaddr *src_in, ...@@ -391,14 +393,17 @@ static int addr_resolve_local(struct sockaddr *src_in,
{ {
struct in6_addr *a; struct in6_addr *a;
read_lock(&dev_base_lock);
for_each_netdev(&init_net, dev) for_each_netdev(&init_net, dev)
if (ipv6_chk_addr(&init_net, if (ipv6_chk_addr(&init_net,
&((struct sockaddr_in6 *) dst_in)->sin6_addr, &((struct sockaddr_in6 *) dst_in)->sin6_addr,
dev, 1)) dev, 1))
break; break;
if (!dev) if (!dev) {
read_unlock(&dev_base_lock);
return -EADDRNOTAVAIL; return -EADDRNOTAVAIL;
}
a = &((struct sockaddr_in6 *) src_in)->sin6_addr; a = &((struct sockaddr_in6 *) src_in)->sin6_addr;
...@@ -416,6 +421,7 @@ static int addr_resolve_local(struct sockaddr *src_in, ...@@ -416,6 +421,7 @@ static int addr_resolve_local(struct sockaddr *src_in,
if (!ret) if (!ret)
memcpy(addr->dst_dev_addr, dev->dev_addr, MAX_ADDR_LEN); memcpy(addr->dst_dev_addr, dev->dev_addr, MAX_ADDR_LEN);
} }
read_unlock(&dev_base_lock);
break; break;
} }
#endif #endif
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment