Skip to content

Commit 1c2d670

Browse files
kaberDavid S. Miller
authored andcommitted
[RTNETLINK]: Hold rtnl_mutex during netlink dump callbacks
Hold rtnl_mutex during the entire netlink dump operation. This allows to simplify locking in the dump callbacks, since they can now rely on that no concurrent changes happen. Signed-off-by: Patrick McHardy <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent af65bdf commit 1c2d670

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

net/core/rtnetlink.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -859,6 +859,7 @@ static int rtnetlink_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
859859
int min_len;
860860
int family;
861861
int type;
862+
int err;
862863

863864
type = nlh->nlmsg_type;
864865
if (type > RTM_MAX)
@@ -887,7 +888,10 @@ static int rtnetlink_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
887888
if (dumpit == NULL)
888889
return -EOPNOTSUPP;
889890

890-
return netlink_dump_start(rtnl, skb, nlh, dumpit, NULL);
891+
__rtnl_unlock();
892+
err = netlink_dump_start(rtnl, skb, nlh, dumpit, NULL);
893+
rtnl_lock();
894+
return err;
891895
}
892896

893897
memset(rta_buf, 0, (rtattr_max * sizeof(struct rtattr *)));
@@ -972,7 +976,7 @@ void __init rtnetlink_init(void)
972976
panic("rtnetlink_init: cannot allocate rta_buf\n");
973977

974978
rtnl = netlink_kernel_create(NETLINK_ROUTE, RTNLGRP_MAX, rtnetlink_rcv,
975-
NULL, THIS_MODULE);
979+
&rtnl_mutex, THIS_MODULE);
976980
if (rtnl == NULL)
977981
panic("rtnetlink_init: cannot initialize rtnetlink\n");
978982
netlink_set_nonroot(NETLINK_ROUTE, NL_NONROOT_RECV);

0 commit comments

Comments
 (0)