diff mbox series

devlink: use devlink lock on DEVLINK_CMD_PORT_SPLIT

Message ID 18b57f7b-6aa6-e87f-e187-feead42fc90a@ugent.be (mailing list archive)
State Rejected
Delegated to: Netdev Maintainers
Headers show
Series devlink: use devlink lock on DEVLINK_CMD_PORT_SPLIT | expand

Checks

Context Check Description
netdev/fixes_present success Fixes tag not required for -next series
netdev/subject_prefix warning Target tree name not specified in the subject
netdev/cover_letter success Single patches do not need cover letters
netdev/patch_count success Link
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 2 this patch: 2
netdev/cc_maintainers fail 2 blamed authors not CCed: arkadis@mellanox.com davem@davemloft.net; 3 maintainers not CCed: arkadis@mellanox.com davem@davemloft.net kuba@kernel.org
netdev/build_clang success Errors and warnings before: 18 this patch: 18
netdev/module_param success Was 0 now: 0
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/verify_fixes success Fixes tag looks correct
netdev/build_allmodconfig_warn success Errors and warnings before: 7 this patch: 7
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 7 lines checked
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0
netdev/tree_selection success Guessing tree name failed - patch did not apply

Commit Message

Niels Dossche Feb. 21, 2022, 1:33 p.m. UTC
devlink_nl_cmd_port_split_doit is executed without taking the devlink
instance lock. This function calls to devlink_port_get_from_info, which
calls devlink_port_get_from_attrs, which calls
devlink_port_get_by_index, which accesses devlink->port_list without the
instance lock taken, while in other places devlink->port_list access
always happens with the instance lock taken. The documentation in the
struct also say that the devlink lock protects the port_list.

The flag for no locking was added after refactoring the code to no
longer use a global lock.

Fixes: 2406e7e546b2 ("devlink: Add per devlink instance lock")
Signed-off-by: Niels Dossche <niels.dossche@ugent.be>
---
 net/core/devlink.c | 1 -
 1 file changed, 1 deletion(-)

Comments

Jakub Kicinski Feb. 22, 2022, 4:54 a.m. UTC | #1
On Mon, 21 Feb 2022 14:33:25 +0100 Niels Dossche wrote:
> devlink_nl_cmd_port_split_doit is executed without taking the devlink
> instance lock. This function calls to devlink_port_get_from_info, which
> calls devlink_port_get_from_attrs, which calls
> devlink_port_get_by_index, which accesses devlink->port_list without the
> instance lock taken, while in other places devlink->port_list access
> always happens with the instance lock taken. The documentation in the
> struct also say that the devlink lock protects the port_list.
> 
> The flag for no locking was added after refactoring the code to no
> longer use a global lock.
> 
> Fixes: 2406e7e546b2 ("devlink: Add per devlink instance lock")
> Signed-off-by: Niels Dossche <niels.dossche@ugent.be>

You can't do this, driver will likely try to register ports and try 
to re-acquire the same lock. I have a series queued to fix this by
moving the locking into drivers. I'll send it out this week.
diff mbox series

Patch

diff --git a/net/core/devlink.c b/net/core/devlink.c
index fcd9f6d85cf1..563becaa03a6 100644
--- a/net/core/devlink.c
+++ b/net/core/devlink.c
@@ -8645,7 +8645,6 @@  static const struct genl_small_ops devlink_nl_ops[] = {
 		.validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
 		.doit = devlink_nl_cmd_port_split_doit,
 		.flags = GENL_ADMIN_PERM,
-		.internal_flags = DEVLINK_NL_FLAG_NO_LOCK,
 	},
 	{
 		.cmd = DEVLINK_CMD_PORT_UNSPLIT,