Skip to content

Commit

Permalink
netlink: ensure to loop over all netns in genlmsg_multicast_allns()
Browse files Browse the repository at this point in the history
Nowadays, nlmsg_multicast() returns only 0 or -ESRCH but this was not the
case when commit 134e637 was pushed.
However, there was no reason to stop the loop if a netns does not have
listeners.
Returns -ESRCH only if there was no listeners in all netns.

To avoid having the same problem in the future, I didn't take the
assumption that nlmsg_multicast() returns only 0 or -ESRCH.

Fixes: 134e637 ("genetlink: make netns aware")
CC: Johannes Berg <[email protected]>
Signed-off-by: Nicolas Dichtel <[email protected]>
Signed-off-by: David S. Miller <[email protected]>
  • Loading branch information
NicolasDichtel authored and davem330 committed Feb 8, 2018
1 parent 8c2f826 commit cb9f7a9
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions net/netlink/genetlink.c
Original file line number Diff line number Diff line change
Expand Up @@ -1081,6 +1081,7 @@ static int genlmsg_mcast(struct sk_buff *skb, u32 portid, unsigned long group,
{
struct sk_buff *tmp;
struct net *net, *prev = NULL;
bool delivered = false;
int err;

for_each_net_rcu(net) {
Expand All @@ -1092,14 +1093,21 @@ static int genlmsg_mcast(struct sk_buff *skb, u32 portid, unsigned long group,
}
err = nlmsg_multicast(prev->genl_sock, tmp,
portid, group, flags);
if (err)
if (!err)
delivered = true;
else if (err != -ESRCH)
goto error;
}

prev = net;
}

return nlmsg_multicast(prev->genl_sock, skb, portid, group, flags);
err = nlmsg_multicast(prev->genl_sock, skb, portid, group, flags);
if (!err)
delivered = true;
else if (err != -ESRCH)
goto error;
return delivered ? 0 : -ESRCH;
error:
kfree_skb(skb);
return err;
Expand Down

0 comments on commit cb9f7a9

Please sign in to comment.