Skip to content

Commit b187c9b

Browse files
paravmellanoxkuba-moo
authored andcommitted
devlink: Hold rtnl lock while reading netdev attributes
A netdevice of a devlink port can be moved to different net namespace than its parent devlink instance. This scenario occurs when devlink reload is not used. When netdevice is undergoing migration to net namespace, its ifindex and name may change. In such use case, devlink port query may read stale netdev attributes. Fix it by reading them under rtnl lock. Fixes: bfcd3a4 ("Introduce devlink infrastructure") Signed-off-by: Parav Pandit <parav@nvidia.com> Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent 3cb2e6d commit b187c9b

1 file changed

Lines changed: 4 additions & 0 deletions

File tree

net/core/devlink.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -772,6 +772,8 @@ static int devlink_nl_port_fill(struct sk_buff *msg, struct devlink *devlink,
772772
if (nla_put_u32(msg, DEVLINK_ATTR_PORT_INDEX, devlink_port->index))
773773
goto nla_put_failure;
774774

775+
/* Hold rtnl lock while accessing port's netdev attributes. */
776+
rtnl_lock();
775777
spin_lock_bh(&devlink_port->type_lock);
776778
if (nla_put_u16(msg, DEVLINK_ATTR_PORT_TYPE, devlink_port->type))
777779
goto nla_put_failure_type_locked;
@@ -798,6 +800,7 @@ static int devlink_nl_port_fill(struct sk_buff *msg, struct devlink *devlink,
798800
goto nla_put_failure_type_locked;
799801
}
800802
spin_unlock_bh(&devlink_port->type_lock);
803+
rtnl_unlock();
801804
if (devlink_nl_port_attrs_put(msg, devlink_port))
802805
goto nla_put_failure;
803806
if (devlink_nl_port_function_attrs_put(msg, devlink_port, extack))
@@ -808,6 +811,7 @@ static int devlink_nl_port_fill(struct sk_buff *msg, struct devlink *devlink,
808811

809812
nla_put_failure_type_locked:
810813
spin_unlock_bh(&devlink_port->type_lock);
814+
rtnl_unlock();
811815
nla_put_failure:
812816
genlmsg_cancel(msg, hdr);
813817
return -EMSGSIZE;

0 commit comments

Comments
 (0)