summaryrefslogtreecommitdiff
path: root/net/core
diff options
context:
space:
mode:
authorDmytro Linkin <dlinkin@nvidia.com>2021-06-23 16:43:15 +0300
committerDavid S. Miller <davem@davemloft.net>2021-06-23 15:46:25 -0700
commita3e5e5797faad0db319d106afaa31b9020fac44f (patch)
tree97d736059ad5dd500ad2c0ab91f99b30c5355243 /net/core
parentff99324ded0176d28c3d8de7cac44580cf79d52a (diff)
downloadlinux-rpi-a3e5e5797faad0db319d106afaa31b9020fac44f.tar.gz
linux-rpi-a3e5e5797faad0db319d106afaa31b9020fac44f.tar.bz2
linux-rpi-a3e5e5797faad0db319d106afaa31b9020fac44f.zip
devlink: Protect rate list with lock while switching modes
Devlink eswitch set command doesn't hold devlink->lock, which makes possible race condition between rate list traversing and others devlink rate KAPI calls, like devlink_rate_nodes_destroy(). Hold devlink lock while traversing the list. Fixes: a8ecb93ef03d ("devlink: Introduce rate nodes") Signed-off-by: Dmytro Linkin <dlinkin@nvidia.com> Reviewed-by: Parav Pandit <parav@nvidia.com> Reviewed-by: Jiri Pirko <jiri@nvidia.com> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/core')
-rw-r--r--net/core/devlink.c4
1 files changed, 4 insertions, 0 deletions
diff --git a/net/core/devlink.c b/net/core/devlink.c
index 153d432f6daf..8fdd04f00fd7 100644
--- a/net/core/devlink.c
+++ b/net/core/devlink.c
@@ -2710,11 +2710,15 @@ static int devlink_rate_nodes_check(struct devlink *devlink, u16 mode,
{
struct devlink_rate *devlink_rate;
+ /* Take the lock to sync with devlink_rate_nodes_destroy() */
+ mutex_lock(&devlink->lock);
list_for_each_entry(devlink_rate, &devlink->rate_list, list)
if (devlink_rate_is_node(devlink_rate)) {
+ mutex_unlock(&devlink->lock);
NL_SET_ERR_MSG_MOD(extack, "Rate node(s) exists.");
return -EBUSY;
}
+ mutex_unlock(&devlink->lock);
return 0;
}