netlink: ensure to loop over all netns in genlmsg_multicast_allns()
Subsystems (2)
PATCH 1/1 netlink: ensure to loop over all netns in genlmsg_multicast_allns()
Nowadays, nlmsg_multicast() returns only 0 or -ESRCH but this was not the case when commit 134e63756d5f 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.
--- net/netlink/genetlink.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-)
net/netlink/genetlink.c +10 -2
@@ -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) {
@@ -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;
Signature · 1 line
2.15.1
From: Nicolas Dichtel <[email protected]>
Date: Tue, 6 Feb 2018 14:48:32 +0100
Quoted 6 lines
Nowadays,
nlmsg_multicast()returns only 0 or-ESRCHbut this was not the case when commit134e63756d5fwas pushed.
However, there was no reason to stop the loop if a netns does not have listeners.
Returns-ESRCHonly if there was no listeners in all netns.
Quoted 6 lines
To avoid having the same problem in the future, I didn't take the assumption that
nlmsg_multicast()returns only 0 or-ESRCH.Fixes 134e63756d5f ("genetlink: make netns aware")CC Johannes Berg <[email protected]>Signed-off-by Nicolas Dichtel <[email protected]>
Ok, that indeed preserves the original behavior. Given this has been this way since 2.6.32 I wonder if fixing this might break something.
Regardless, applied and queued up for -stable, thanks.