Skip to content

Commit 2907c35

Browse files
Eric Dumazetdavem330
authored andcommitted
net: hold rtnl again in dump callbacks
Commit e67f88d (dont hold rtnl mutex during netlink dump callbacks) missed fact that rtnl_fill_ifinfo() must be called with rtnl held. Because of possible deadlocks between two mutexes (cb_mutex and rtnl), its not easy to solve this problem, so revert this part of the patch. It also forgot one rcu_read_unlock() in FIB dump_rules() Add one ASSERT_RTNL() in rtnl_fill_ifinfo() to remind us the rule. Signed-off-by: Eric Dumazet <eric.dumazet@gmail.com> CC: Patrick McHardy <kaber@trash.net> CC: Stephen Hemminger <shemminger@vyatta.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 1dcb14d commit 2907c35

2 files changed

Lines changed: 8 additions & 2 deletions

File tree

‎net/core/fib_rules.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -602,6 +602,7 @@ static int dump_rules(struct sk_buff *skb, struct netlink_callback *cb,
602602
skip:
603603
idx++;
604604
}
605+
rcu_read_unlock();
605606
cb->args[1] = idx;
606607
rules_ops_put(ops);
607608

‎net/core/rtnetlink.c‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -850,6 +850,7 @@ static int rtnl_fill_ifinfo(struct sk_buff *skb, struct net_device *dev,
850850
struct nlattr *attr, *af_spec;
851851
struct rtnl_af_ops *af_ops;
852852

853+
ASSERT_RTNL();
853854
nlh = nlmsg_put(skb, pid, seq, type, sizeof(*ifm), flags);
854855
if (nlh == NULL)
855856
return -EMSGSIZE;
@@ -1876,6 +1877,7 @@ static int rtnetlink_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
18761877
int min_len;
18771878
int family;
18781879
int type;
1880+
int err;
18791881

18801882
type = nlh->nlmsg_type;
18811883
if (type > RTM_MAX)
@@ -1902,8 +1904,11 @@ static int rtnetlink_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
19021904
if (dumpit == NULL)
19031905
return -EOPNOTSUPP;
19041906

1907+
__rtnl_unlock();
19051908
rtnl = net->rtnl;
1906-
return netlink_dump_start(rtnl, skb, nlh, dumpit, NULL);
1909+
err = netlink_dump_start(rtnl, skb, nlh, dumpit, NULL);
1910+
rtnl_lock();
1911+
return err;
19071912
}
19081913

19091914
memset(rta_buf, 0, (rtattr_max * sizeof(struct rtattr *)));
@@ -1975,7 +1980,7 @@ static int __net_init rtnetlink_net_init(struct net *net)
19751980
{
19761981
struct sock *sk;
19771982
sk = netlink_kernel_create(net, NETLINK_ROUTE, RTNLGRP_MAX,
1978-
rtnetlink_rcv, NULL, THIS_MODULE);
1983+
rtnetlink_rcv, &rtnl_mutex, THIS_MODULE);
19791984
if (!sk)
19801985
return -ENOMEM;
19811986
net->rtnl = sk;

0 commit comments

Comments
 (0)