netlink: don't send unknown nsid

The NETLINK_F_LISTEN_ALL_NSID otion enables to listen all netns that have a
nsid assigned into the netns where the netlink socket is opened.
The nsid is sent as metadata to userland, but the existence of this nsid is
checked only for netns that are different from the socket netns. Thus, if
no nsid is assigned to the socket netns, NETNSA_NSID_NOT_ASSIGNED is
reported to the userland. This value is confusing and useless.
After this patch, only valid nsid are sent to userland.

Reported-by: Flavio Leitner <fbl@sysclose.org>
Signed-off-by: Nicolas Dichtel <nicolas.dichtel@6wind.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
Nicolas Dichtel 2017-06-01 10:00:07 +02:00 committed by David S. Miller
parent 5ea6d691aa
commit 7212462fa6
1 changed files with 3 additions and 1 deletions

View File

@ -62,6 +62,7 @@
#include <asm/cacheflush.h> #include <asm/cacheflush.h>
#include <linux/hash.h> #include <linux/hash.h>
#include <linux/genetlink.h> #include <linux/genetlink.h>
#include <linux/net_namespace.h>
#include <net/net_namespace.h> #include <net/net_namespace.h>
#include <net/sock.h> #include <net/sock.h>
@ -1415,7 +1416,8 @@ static void do_one_broadcast(struct sock *sk,
goto out; goto out;
} }
NETLINK_CB(p->skb2).nsid = peernet2id(sock_net(sk), p->net); NETLINK_CB(p->skb2).nsid = peernet2id(sock_net(sk), p->net);
NETLINK_CB(p->skb2).nsid_is_set = true; if (NETLINK_CB(p->skb2).nsid != NETNSA_NSID_NOT_ASSIGNED)
NETLINK_CB(p->skb2).nsid_is_set = true;
val = netlink_broadcast_deliver(sk, p->skb2); val = netlink_broadcast_deliver(sk, p->skb2);
if (val < 0) { if (val < 0) {
netlink_overrun(sk); netlink_overrun(sk);