net: Revert "ipv4: fix a deadlock in ip_ra_control"
authorKirill Tkhai <ktkhai@virtuozzo.com>
Thu, 22 Mar 2018 09:45:22 +0000 (12:45 +0300)
committerDavid S. Miller <davem@davemloft.net>
Thu, 22 Mar 2018 19:12:56 +0000 (15:12 -0400)
This reverts commit 1215e51edad1.
Since raw_close() is used on every RAW socket destruction,
the changes made by 1215e51edad1 scale sadly. This clearly
seen on endless unshare(CLONE_NEWNET) test, and cleanup_net()
kwork spends a lot of time waiting for rtnl_lock() introduced
by this commit.

Previous patch moved IP_ROUTER_ALERT out of rtnl_lock(),
so we revert this patch.

Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
net/ipv4/ip_sockglue.c
net/ipv4/ipmr.c
net/ipv4/raw.c

index dcbf6afe27e7266788ea6351f7c607c19c60788f..bf5f44b27b7e6dbe9f4c1903877db82282e97863 100644 (file)
@@ -594,7 +594,6 @@ static bool setsockopt_needs_rtnl(int optname)
        case MCAST_LEAVE_GROUP:
        case MCAST_LEAVE_SOURCE_GROUP:
        case MCAST_UNBLOCK_SOURCE:
-       case IP_ROUTER_ALERT:
                return true;
        }
        return false;
index d752a70855d8b6957d201db9772da3c4992b895b..f6be5db16da2640a44032770ca3ef8b90bc14b29 100644 (file)
@@ -1399,7 +1399,7 @@ static void mrtsock_destruct(struct sock *sk)
        struct net *net = sock_net(sk);
        struct mr_table *mrt;
 
-       ASSERT_RTNL();
+       rtnl_lock();
        ipmr_for_each_table(mrt, net) {
                if (sk == rtnl_dereference(mrt->mroute_sk)) {
                        IPV4_DEVCONF_ALL(net, MC_FORWARDING)--;
@@ -1411,6 +1411,7 @@ static void mrtsock_destruct(struct sock *sk)
                        mroute_clean_tables(mrt, false);
                }
        }
+       rtnl_unlock();
 }
 
 /* Socket options and virtual interface manipulation. The whole
@@ -1475,8 +1476,13 @@ int ip_mroute_setsockopt(struct sock *sk, int optname, char __user *optval,
                if (sk != rcu_access_pointer(mrt->mroute_sk)) {
                        ret = -EACCES;
                } else {
+                       /* We need to unlock here because mrtsock_destruct takes
+                        * care of rtnl itself and we can't change that due to
+                        * the IP_ROUTER_ALERT setsockopt which runs without it.
+                        */
+                       rtnl_unlock();
                        ret = ip_ra_control(sk, 0, NULL);
-                       goto out_unlock;
+                       goto out;
                }
                break;
        case MRT_ADD_VIF:
@@ -1588,6 +1594,7 @@ int ip_mroute_setsockopt(struct sock *sk, int optname, char __user *optval,
        }
 out_unlock:
        rtnl_unlock();
+out:
        return ret;
 }
 
index 54648d20bf0f87e1b9a2cceb7bb18a31c8df319a..720bef7da2f6d13e9b09269c38d14a7945ae4c5e 100644 (file)
@@ -711,9 +711,7 @@ static void raw_close(struct sock *sk, long timeout)
        /*
         * Raw sockets may have direct kernel references. Kill them.
         */
-       rtnl_lock();
        ip_ra_control(sk, 0, NULL);
-       rtnl_unlock();
 
        sk_common_release(sk);
 }