devlink: protect devlink dump by the instance lock
authorJakub Kicinski <kuba@kernel.org>
Fri, 16 Dec 2022 04:41:22 +0000 (20:41 -0800)
committerJakub Kicinski <kuba@kernel.org>
Sat, 17 Dec 2022 05:16:28 +0000 (21:16 -0800)
Take the instance lock around devlink_nl_fill() when dumping,
doit takes it already.

We are only dumping basic info so in the worst case we were risking
data races around the reload statistics. Until the big devlink mutex
was removed all relevant code was protected by it, so the missing
instance lock was not exposed.

Fixes: d3efc2a6a6d8 ("net: devlink: remove devlink_mutex")
Reviewed-by: Jiri Pirko <jiri@nvidia.com>
Reviewed-by: Jacob Keller <jacob.e.keller@intel.com>
Link: https://lore.kernel.org/r/20221216044122.1863550-1-kuba@kernel.org
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
net/core/devlink.c

index d2df308290832308aa99adb925575869b4de440c..032d6d0a5ce64ad3db1fe89bdb6454bcf2aad7ef 100644 (file)
@@ -1648,10 +1648,13 @@ static int devlink_nl_cmd_get_dumpit(struct sk_buff *msg,
                        continue;
                }
 
+               devl_lock(devlink);
                err = devlink_nl_fill(msg, devlink, DEVLINK_CMD_NEW,
                                      NETLINK_CB(cb->skb).portid,
                                      cb->nlh->nlmsg_seq, NLM_F_MULTI);
+               devl_unlock(devlink);
                devlink_put(devlink);
+
                if (err)
                        goto out;
                idx++;