ipv4: fix a deadlock in ip_ra_control
authorWANG Cong <xiyou.wangcong@gmail.com>
Wed, 12 Apr 2017 19:32:13 +0000 (12:32 -0700)
committerDavid S. Miller <davem@davemloft.net>
Mon, 17 Apr 2017 16:46:50 +0000 (12:46 -0400)
commit1215e51edad1272e669172b26aa12aac94810c7f
tree273156966c9fb351ee4181712ebbcfc576495258
parent271a8b428f8361f3ad4c599835ccd34dd458b212
ipv4: fix a deadlock in ip_ra_control

Similar to commit 87e9f0315952
("ipv4: fix a potential deadlock in mcast getsockopt() path"),
there is a deadlock scenario for IP_ROUTER_ALERT too:

       CPU0                    CPU1
       ----                    ----
  lock(rtnl_mutex);
                               lock(sk_lock-AF_INET);
                               lock(rtnl_mutex);
  lock(sk_lock-AF_INET);

Fix this by always locking RTNL first on all setsockopt() paths.

Note, after this patch ip_ra_lock is no longer needed either.

Reported-by: Dmitry Vyukov <dvyukov@google.com>
Tested-by: Andrey Konovalov <andreyknvl@google.com>
Signed-off-by: Cong Wang <xiyou.wangcong@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
net/ipv4/ip_sockglue.c
net/ipv4/ipmr.c
net/ipv4/raw.c