diff mbox series

[NET-PREV,43/51] net: Now check nobody calls netdev_master_upper_dev_link() without nd_lock attached

Message ID 174265459205.356712.8546283286984099636.stgit@pro.pro (mailing list archive)
State RFC
Delegated to: Netdev Maintainers
Headers show
Series Kill rtnl_lock using fine-grained nd_lock | expand

Checks

Context Check Description
netdev/tree_selection success Guessing tree name failed - patch did not apply, async

Commit Message

Kirill Tkhai March 22, 2025, 2:43 p.m. UTC
... or with devices not related to the same nd_lock,

since at this moment all callers are switched to follow this way.

Signed-off-by: Kirill Tkhai <tkhai@ya.ru>
---
 net/core/dev.c |    6 ++++++
 1 file changed, 6 insertions(+)
diff mbox series

Patch

diff --git a/net/core/dev.c b/net/core/dev.c
index 1c447446215d..55df8157bca9 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -8126,6 +8126,12 @@  int netdev_master_upper_dev_link(struct net_device *dev,
 		.flags = NESTED_SYNC_IMM | NESTED_SYNC_TODO,
 		.data = NULL,
 	};
+	struct nd_lock *nd_lock;
+
+	nd_lock = rcu_dereference_protected(upper_dev->nd_lock, true);
+	if (WARN_ON(!mutex_is_locked(&nd_lock->mutex) ||
+		    nd_lock != rcu_dereference_protected(dev->nd_lock, true)))
+		return -EXDEV;
 
 	return __netdev_upper_dev_link(dev, upper_dev, true,
 				       upper_priv, upper_info, &priv, extack);