diff options
author | Parav Pandit <parav@nvidia.com> | 2020-11-25 11:16:19 +0200 |
---|---|---|
committer | Jakub Kicinski <kuba@kernel.org> | 2020-11-25 17:26:34 -0800 |
commit | b187c9b4178b87954dbc94e78a7094715794714f (patch) | |
tree | 1198ba7ba2156a4d6b10983528c356344cbaf12f /net/core | |
parent | 3cb2e6d92be637b79d6ba0746d610a8dfcc0400b (diff) | |
download | linux-b187c9b4178b87954dbc94e78a7094715794714f.tar.gz linux-b187c9b4178b87954dbc94e78a7094715794714f.tar.bz2 linux-b187c9b4178b87954dbc94e78a7094715794714f.zip |
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: bfcd3a466172 ("Introduce devlink infrastructure")
Signed-off-by: Parav Pandit <parav@nvidia.com>
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Diffstat (limited to 'net/core')
-rw-r--r-- | net/core/devlink.c | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/net/core/devlink.c b/net/core/devlink.c index c91e15b7a2bd..79b8df41bea3 100644 --- a/net/core/devlink.c +++ b/net/core/devlink.c @@ -772,6 +772,8 @@ static int devlink_nl_port_fill(struct sk_buff *msg, struct devlink *devlink, if (nla_put_u32(msg, DEVLINK_ATTR_PORT_INDEX, devlink_port->index)) goto nla_put_failure; + /* Hold rtnl lock while accessing port's netdev attributes. */ + rtnl_lock(); spin_lock_bh(&devlink_port->type_lock); if (nla_put_u16(msg, DEVLINK_ATTR_PORT_TYPE, devlink_port->type)) goto nla_put_failure_type_locked; @@ -798,6 +800,7 @@ static int devlink_nl_port_fill(struct sk_buff *msg, struct devlink *devlink, goto nla_put_failure_type_locked; } spin_unlock_bh(&devlink_port->type_lock); + rtnl_unlock(); if (devlink_nl_port_attrs_put(msg, devlink_port)) goto nla_put_failure; 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, nla_put_failure_type_locked: spin_unlock_bh(&devlink_port->type_lock); + rtnl_unlock(); nla_put_failure: genlmsg_cancel(msg, hdr); return -EMSGSIZE; |