netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net] netlink: ensure to loop over all netns in genlmsg_multicast_allns()
@ 2018-02-06 13:48 Nicolas Dichtel
  2018-02-08 19:06 ` David Miller
  0 siblings, 1 reply; 2+ messages in thread
From: Nicolas Dichtel @ 2018-02-06 13:48 UTC (permalink / raw)
  To: davem; +Cc: netdev, Nicolas Dichtel, Johannes Berg

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.

Fixes: 134e63756d5f ("genetlink: make netns aware")
CC: Johannes Berg <johannes.berg@intel.com>
Signed-off-by: Nicolas Dichtel <nicolas.dichtel@6wind.com>
---
 net/netlink/genetlink.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/net/netlink/genetlink.c b/net/netlink/genetlink.c
index d444daf1ac04..6f02499ef007 100644
--- a/net/netlink/genetlink.c
+++ b/net/netlink/genetlink.c
@@ -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;
-- 
2.15.1

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH net] netlink: ensure to loop over all netns in genlmsg_multicast_allns()
  2018-02-06 13:48 [PATCH net] netlink: ensure to loop over all netns in genlmsg_multicast_allns() Nicolas Dichtel
@ 2018-02-08 19:06 ` David Miller
  0 siblings, 0 replies; 2+ messages in thread
From: David Miller @ 2018-02-08 19:06 UTC (permalink / raw)
  To: nicolas.dichtel; +Cc: netdev, johannes.berg

From: Nicolas Dichtel <nicolas.dichtel@6wind.com>
Date: Tue,  6 Feb 2018 14:48:32 +0100

> 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.
> 
> Fixes: 134e63756d5f ("genetlink: make netns aware")
> CC: Johannes Berg <johannes.berg@intel.com>
> Signed-off-by: Nicolas Dichtel <nicolas.dichtel@6wind.com>

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.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2018-02-08 19:06 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-02-06 13:48 [PATCH net] netlink: ensure to loop over all netns in genlmsg_multicast_allns() Nicolas Dichtel
2018-02-08 19:06 ` David Miller

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).