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

Kirill Tkhai posted 51 patches 9 months ago
[PATCH NET-PREV 43/51] net: Now check nobody calls netdev_master_upper_dev_link() without nd_lock attached
Posted by Kirill Tkhai 9 months ago
... 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 --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);