]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
ieee802154: 6lowpan: Validate link netns in newlink() of rtnl_link_ops
authorXiao Liang <shaw.leon@gmail.com>
Wed, 19 Feb 2025 12:50:30 +0000 (20:50 +0800)
committerJakub Kicinski <kuba@kernel.org>
Fri, 21 Feb 2025 23:28:02 +0000 (15:28 -0800)
Device denoted by IFLA_LINK is in link_net (IFLA_LINK_NETNSID) or
source netns by design, but 6lowpan uses dev_net.

Note dev->netns_local is set to true and currently link_net is
implemented via a netns change. These together effectively reject
IFLA_LINK_NETNSID.

This patch adds a validation to ensure link_net is either NULL or
identical to dev_net. Thus it would be fine to continue using dev_net
when rtnetlink core begins to create devices directly in target netns.

Signed-off-by: Xiao Liang <shaw.leon@gmail.com>
Reviewed-by: Kuniyuki Iwashima <kuniyu@amazon.com>
Link: https://patch.msgid.link/20250219125039.18024-5-shaw.leon@gmail.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
net/ieee802154/6lowpan/core.c

index 704bf9e3f097534961d90eb4586faae2068f1efd..ee318d46817d4031bea77abb5b767d64348dfba7 100644 (file)
@@ -143,6 +143,8 @@ static int lowpan_newlink(struct net_device *ldev,
 
        if (!tb[IFLA_LINK])
                return -EINVAL;
+       if (params->link_net && !net_eq(params->link_net, dev_net(ldev)))
+               return -EINVAL;
        /* find and hold wpan device */
        wdev = dev_get_by_index(dev_net(ldev), nla_get_u32(tb[IFLA_LINK]));
        if (!wdev)