devlink: don't allow to change net namespace for FW_ACTIVATE reload action
authorJiri Pirko <jiri@nvidia.com>
Mon, 13 Feb 2023 11:58:36 +0000 (12:58 +0100)
committerPaolo Abeni <pabeni@redhat.com>
Tue, 14 Feb 2023 13:04:21 +0000 (14:04 +0100)
The change on network namespace only makes sense during re-init reload
action. For FW activation it is not applicable. So check if user passed
an ATTR indicating network namespace change request and forbid it.

Signed-off-by: Jiri Pirko <jiri@nvidia.com>
Acked-by: Jakub Kicinski <kuba@kernel.org>
Link: https://lore.kernel.org/r/20230213115836.3404039-1-jiri@resnulli.us
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
net/devlink/dev.c

index ab4e0f3c4e3d7a123fd0ff330ef967b637e4fb34..b40153fa26800cda521de53ffe59e54b266a4679 100644 (file)
@@ -476,6 +476,12 @@ int devlink_nl_cmd_reload(struct sk_buff *skb, struct genl_info *info)
                dest_net = devlink_netns_get(skb, info);
                if (IS_ERR(dest_net))
                        return PTR_ERR(dest_net);
+               if (!net_eq(dest_net, devlink_net(devlink)) &&
+                   action != DEVLINK_RELOAD_ACTION_DRIVER_REINIT) {
+                       NL_SET_ERR_MSG_MOD(info->extack,
+                                          "Changing namespace is only supported for reinit action");
+                       return -EOPNOTSUPP;
+               }
        }
 
        err = devlink_reload(devlink, dest_net, action, limit, &actions_performed, info->extack);