ipv6: fix rtnl locking in setsockopt for anycast and multicast
Calling setsockopt with IPV6_JOIN_ANYCAST or IPV6_LEAVE_ANYCAST triggers the assertion in addrconf_join_solict()/addrconf_leave_solict() ipv6_sock_ac_join(), ipv6_sock_ac_drop(), ipv6_sock_ac_close() need to take RTNL before calling ipv6_dev_ac_inc/dec. Same thing with ipv6_sock_mc_join(), ipv6_sock_mc_drop(), ipv6_sock_mc_close() before calling ipv6_dev_mc_inc/dec. This patch moves ASSERT_RTNL() up a level in the call stack. Signed-off-by: Cong Wang <xiyou.wangcong@gmail.com> Signed-off-by: Sabrina Dubroca <sd@queasysnail.net> Reported-by: Tommi Rantala <tt.rantala@gmail.com> Acked-by: Hannes Frederic Sowa <hannes@stressinduktion.org> Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:

committed by
David S. Miller

parent
4ad9a64f53
commit
a9ed4a2986
@@ -77,6 +77,7 @@ int ipv6_sock_ac_join(struct sock *sk, int ifindex, const struct in6_addr *addr)
|
||||
pac->acl_next = NULL;
|
||||
pac->acl_addr = *addr;
|
||||
|
||||
rtnl_lock();
|
||||
rcu_read_lock();
|
||||
if (ifindex == 0) {
|
||||
struct rt6_info *rt;
|
||||
@@ -137,6 +138,7 @@ int ipv6_sock_ac_join(struct sock *sk, int ifindex, const struct in6_addr *addr)
|
||||
|
||||
error:
|
||||
rcu_read_unlock();
|
||||
rtnl_unlock();
|
||||
if (pac)
|
||||
sock_kfree_s(sk, pac, sizeof(*pac));
|
||||
return err;
|
||||
@@ -171,13 +173,17 @@ int ipv6_sock_ac_drop(struct sock *sk, int ifindex, const struct in6_addr *addr)
|
||||
|
||||
spin_unlock_bh(&ipv6_sk_ac_lock);
|
||||
|
||||
rtnl_lock();
|
||||
rcu_read_lock();
|
||||
dev = dev_get_by_index_rcu(net, pac->acl_ifindex);
|
||||
if (dev)
|
||||
ipv6_dev_ac_dec(dev, &pac->acl_addr);
|
||||
rcu_read_unlock();
|
||||
rtnl_unlock();
|
||||
|
||||
sock_kfree_s(sk, pac, sizeof(*pac));
|
||||
if (!dev)
|
||||
return -ENODEV;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -198,6 +204,7 @@ void ipv6_sock_ac_close(struct sock *sk)
|
||||
spin_unlock_bh(&ipv6_sk_ac_lock);
|
||||
|
||||
prev_index = 0;
|
||||
rtnl_lock();
|
||||
rcu_read_lock();
|
||||
while (pac) {
|
||||
struct ipv6_ac_socklist *next = pac->acl_next;
|
||||
@@ -212,6 +219,7 @@ void ipv6_sock_ac_close(struct sock *sk)
|
||||
pac = next;
|
||||
}
|
||||
rcu_read_unlock();
|
||||
rtnl_unlock();
|
||||
}
|
||||
|
||||
static void aca_put(struct ifacaddr6 *ac)
|
||||
@@ -233,6 +241,8 @@ int ipv6_dev_ac_inc(struct net_device *dev, const struct in6_addr *addr)
|
||||
struct rt6_info *rt;
|
||||
int err;
|
||||
|
||||
ASSERT_RTNL();
|
||||
|
||||
idev = in6_dev_get(dev);
|
||||
|
||||
if (idev == NULL)
|
||||
@@ -302,6 +312,8 @@ int __ipv6_dev_ac_dec(struct inet6_dev *idev, const struct in6_addr *addr)
|
||||
{
|
||||
struct ifacaddr6 *aca, *prev_aca;
|
||||
|
||||
ASSERT_RTNL();
|
||||
|
||||
write_lock_bh(&idev->lock);
|
||||
prev_aca = NULL;
|
||||
for (aca = idev->ac_list; aca; aca = aca->aca_next) {
|
||||
|
Reference in New Issue
Block a user