devlink: protect devlink dump by the instance lock
Subsystems (2)
Jakub Kicinski
maintainerPATCH 1/1 devlink: protect devlink dump by the instance lock
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. Also note that the reloads themselves had not been under the instance lock until recently, so the selection of the Fixes tag is inherently questionable.
---
CC: [email protected]
CC: [email protected]
--- net/core/devlink.c | 3 +++ 1 file changed, 3 insertions(+)
net/core/devlink.c +3 -0
@@ -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++;
Signature · 1 line
2.38.1
Jakub Kicinski
maintainerQuoted 9 lines · On Thu, 15 Dec 2022 20:41:22 -0800 Jakub Kicinski wrote:
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. Also note that the reloads themselves had not been under the instance lock until recently, so the selection of the Fixes tag is inherently questionable.
Fixes a254c264267e ("devlink: Add reload stats")
On second thought, the drivers can't call reload, so until we got rid of the big bad mutex there could have been no race. I'll swap the tag for:
when/if applying.
Quoted 26 lines
Signed-off-by Jakub Kicinski <[email protected]>---
CC: [email protected]
CC: [email protected]--- net/core/devlink.c | 3 +++ 1 file changed, 3 insertions(+)net/core/devlink.c +3
-0@@ -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++;
Jiri Pirko
Reviewed-byQuoted 11 lines · Fri, Dec 16, 2022 at 05:44:47AM CET, [email protected] wrote:
Quoted 9 lines · On Thu, 15 Dec 2022 20:41:22 -0800 Jakub Kicinski wrote:
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. Also note that the reloads themselves had not been under the instance lock until recently, so the selection of the Fixes tag is inherently questionable.
Fixes a254c264267e ("devlink: Add reload stats")
Quoted 7 lines
On second thought, the drivers can't call reload, so until we got rid of the big bad mutex there could have been no race. I'll swap the tag for:
Fixes d3efc2a6a6d8 ("net: devlink: remove devlink_mutex")when/if applying.
You are right.
Thanks!
Jacob Keller
Reviewed-byQuoted 18 lines · Jiri Pirko
Quoted 17 lines · Fri, Dec 16, 2022 at 05:44:47AM CET, [email protected] wrote:
Quoted 9 lines · On Thu, 15 Dec 2022 20:41:22 -0800 Jakub Kicinski wrote:
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. Also note that the reloads themselves had not been under the instance lock until recently, so the selection of the Fixes tag is inherently questionable.
Fixes a254c264267e ("devlink: Add reload stats")On second thought, the drivers can't call reload, so until we got rid of the big bad mutex there could have been no race. I'll swap the tag for:
Fixes d3efc2a6a6d8 ("net: devlink: remove devlink_mutex")
Quoted 7 lines
Quoted 1 line
when/if applying.
You are right.
Reviewed-by Jiri Pirko <[email protected]>Thanks!
Agreed!
This patch was applied to netdev/net.git (master) by Jakub Kicinski <[email protected]>:
Hello:
This patch was applied to netdev/net.git (master)
by Jakub Kicinski <[email protected]>:
Quoted 9 lines · On Thu, 15 Dec 2022 20:41:22 -0800 you wrote:
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. Also note that the reloads themselves had not been under the instance lock until recently, so the selection of the Fixes tag is inherently questionable.
[...]
Here is the summary with links:
- [net] devlink: protect devlink dump by the instance lock
https://git.kernel.org/netdev/net/c/214964a13ab5
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html