diff mbox series

[net,2/2] devlink: Make sure devlink instance and port are in same net namespace

Message ID 20201122061257.60425-3-parav@nvidia.com
State New
Headers show
Series devlink port attribute fixes | expand

Commit Message

Parav Pandit Nov. 22, 2020, 6:12 a.m. UTC
When devlink reload operation is not used, netdev of an Ethernet port
may be present in different net namespace than the net namespace of the
devlink instance.

Ensure that both the devlink instance and devlink port netdev are
located in same net namespace.

Fixes: 070c63f20f6c ("net: devlink: allow to change namespaces during reload")
Signed-off-by: Parav Pandit <parav@nvidia.com>
 net/core/devlink.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
diff mbox series


diff --git a/net/core/devlink.c b/net/core/devlink.c
index 6135ef5972ce..2e1b0e82a102 100644
--- a/net/core/devlink.c
+++ b/net/core/devlink.c
@@ -778,12 +778,15 @@  devlink_nl_port_function_attrs_put(struct sk_buff *msg, struct devlink_port *por
 static int devlink_nl_port_netdev_fill(struct sk_buff *msg, struct devlink_port *devlink_port)
 	struct net_device *netdev = devlink_port->type_dev;
-	int err;
+	int err = 0;
 	if (!netdev)
 		return 0;
+	if (!net_eq(devlink_net(devlink_port->devlink), dev_net(netdev)))
+		goto done;
 	err = nla_put_u32(msg, DEVLINK_ATTR_PORT_NETDEV_IFINDEX, netdev->ifindex);
 	if (err)
 		goto done;