Subject: [RFC net-next 04/15] devlink: protect devlink dump by the instance lock

From: Jakub Kicinski <[email-masked]>
Date: Wed, 14 Dec 2022 18:01:44 -0800

Take the instance lock around devlink_nl_fill() when the dumping.
We are only dumping basic info so in the worst case we were only
risking data races until now.

Signed-off-by: Jakub Kicinski <[email-masked]>
---
 net/devlink/basic.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/net/devlink/basic.c b/net/devlink/basic.c
index 4b0938a1854e..e01ba7999b91 100644
--- a/net/devlink/basic.c
+++ b/net/devlink/basic.c
@@ -1330,10 +1330,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++;
-- 
2.38.1