]> git.baikalelectronics.ru Git - kernel.git/commitdiff
devlink: Protect devlink port list traversal
authorParav Pandit <parav@nvidia.com>
Fri, 21 Aug 2020 19:12:21 +0000 (22:12 +0300)
committerDavid S. Miller <davem@davemloft.net>
Mon, 24 Aug 2020 23:02:47 +0000 (16:02 -0700)
Cited patch in fixes tag misses to protect port list traversal
while traversing per port reporter list.

Protect it using devlink instance lock.

Fixes: 5c243a048d48 ("devlink: Implement devlink health reporters on per-port basis")
Signed-off-by: Parav Pandit <parav@nvidia.com>
Reviewed-by: Jiri Pirko <jiri@nvidia.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
net/core/devlink.c

index 9b01f7245fd877b715a1dd4d8ecdb926be82f41c..58c8bb07fa191f74b742669f2a8e7557ec2648af 100644 (file)
@@ -5895,6 +5895,7 @@ devlink_nl_cmd_health_reporter_get_dumpit(struct sk_buff *msg,
        list_for_each_entry(devlink, &devlink_list, list) {
                if (!net_eq(devlink_net(devlink), sock_net(msg->sk)))
                        continue;
+               mutex_lock(&devlink->lock);
                list_for_each_entry(port, &devlink->port_list, list) {
                        mutex_lock(&port->reporters_lock);
                        list_for_each_entry(reporter, &port->reporter_list, list) {
@@ -5909,12 +5910,14 @@ devlink_nl_cmd_health_reporter_get_dumpit(struct sk_buff *msg,
                                                                      NLM_F_MULTI);
                                if (err) {
                                        mutex_unlock(&port->reporters_lock);
+                                       mutex_unlock(&devlink->lock);
                                        goto out;
                                }
                                idx++;
                        }
                        mutex_unlock(&port->reporters_lock);
                }
+               mutex_unlock(&devlink->lock);
        }
 out:
        mutex_unlock(&devlink_mutex);