lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <174265454113.356712.15920821128646833231.stgit@pro.pro>
Date: Sat, 22 Mar 2025 17:42:21 +0300
From: Kirill Tkhai <tkhai@...ru>
To: netdev@...r.kernel.org,
	linux-kernel@...r.kernel.org
Cc: tkhai@...ru
Subject: [PATCH NET-PREV 36/51] ieee802154: Use fallback_nd_lock for registered devices

For now we use fallback_nd_lock for all drivers registering
via ieee802154_if_add().

One of the reasons is that they are used as a bunch
in cfg802154_switch_netns(), while we want to call
dev_change_net_namespace() under nd_lock in one of
next patches.

Signed-off-by: Kirill Tkhai <tkhai@...ru>
---
 net/ieee802154/nl802154.c |    7 +++++++
 net/mac802154/cfg.c       |    2 ++
 net/mac802154/iface.c     |   10 ++++++++--
 net/mac802154/main.c      |    2 ++
 4 files changed, 19 insertions(+), 2 deletions(-)

diff --git a/net/ieee802154/nl802154.c b/net/ieee802154/nl802154.c
index 7eb37de3add2..a512f2a647e8 100644
--- a/net/ieee802154/nl802154.c
+++ b/net/ieee802154/nl802154.c
@@ -2691,6 +2691,7 @@ static int nl802154_del_llsec_seclevel(struct sk_buff *skb,
 #define NL802154_FLAG_NEED_RTNL		0x04
 #define NL802154_FLAG_CHECK_NETDEV_UP	0x08
 #define NL802154_FLAG_NEED_WPAN_DEV	0x10
+#define NL802154_FLAG_NEED_FALLBACK_ND_LOCK	0x20
 
 static int nl802154_pre_doit(const struct genl_split_ops *ops,
 			     struct sk_buff *skb,
@@ -2700,9 +2701,12 @@ static int nl802154_pre_doit(const struct genl_split_ops *ops,
 	struct wpan_dev *wpan_dev;
 	struct net_device *dev;
 	bool rtnl = ops->internal_flags & NL802154_FLAG_NEED_RTNL;
+	bool nd = ops->internal_flags & NL802154_FLAG_NEED_FALLBACK_ND_LOCK;
 
 	if (rtnl)
 		rtnl_lock();
+	if (nd)
+		mutex_lock(&fallback_nd_lock.mutex);
 
 	if (ops->internal_flags & NL802154_FLAG_NEED_WPAN_PHY) {
 		rdev = cfg802154_get_dev_from_info(genl_info_net(info), info);
@@ -2769,6 +2773,8 @@ static void nl802154_post_doit(const struct genl_split_ops *ops,
 		}
 	}
 
+	if (ops->internal_flags & NL802154_FLAG_NEED_FALLBACK_ND_LOCK)
+		mutex_unlock(&fallback_nd_lock.mutex);
 	if (ops->internal_flags & NL802154_FLAG_NEED_RTNL)
 		rtnl_unlock();
 }
@@ -2800,6 +2806,7 @@ static const struct genl_ops nl802154_ops[] = {
 		.doit = nl802154_new_interface,
 		.flags = GENL_ADMIN_PERM,
 		.internal_flags = NL802154_FLAG_NEED_WPAN_PHY |
+				  NL802154_FLAG_NEED_FALLBACK_ND_LOCK |
 				  NL802154_FLAG_NEED_RTNL,
 	},
 	{
diff --git a/net/mac802154/cfg.c b/net/mac802154/cfg.c
index ef7f23af043f..405183d258b6 100644
--- a/net/mac802154/cfg.c
+++ b/net/mac802154/cfg.c
@@ -23,8 +23,10 @@ ieee802154_add_iface_deprecated(struct wpan_phy *wpan_phy,
 	struct net_device *dev;
 
 	rtnl_lock();
+	mutex_lock(&fallback_nd_lock.mutex);
 	dev = ieee802154_if_add(local, name, name_assign_type, type,
 				cpu_to_le64(0x0000000000000000ULL));
+	mutex_unlock(&fallback_nd_lock.mutex);
 	rtnl_unlock();
 
 	return dev;
diff --git a/net/mac802154/iface.c b/net/mac802154/iface.c
index c0e2da5072be..7ec23e8268de 100644
--- a/net/mac802154/iface.c
+++ b/net/mac802154/iface.c
@@ -664,9 +664,15 @@ ieee802154_if_add(struct ieee802154_local *local, const char *name,
 	if (ret)
 		goto err;
 
-	ret = register_netdevice(ndev);
-	if (ret < 0)
+	ret = -EXDEV;
+	if (!mutex_is_locked(&fallback_nd_lock.mutex))
+		goto err;
+	attach_nd_lock(ndev, &fallback_nd_lock);
+	ret = __register_netdevice(ndev);
+	if (ret < 0) {
+		detach_nd_lock(ndev);
 		goto err;
+	}
 
 	mutex_lock(&local->iflist_mtx);
 	list_add_tail_rcu(&sdata->list, &local->interfaces);
diff --git a/net/mac802154/main.c b/net/mac802154/main.c
index 21b7c3b280b4..14bcad399dae 100644
--- a/net/mac802154/main.c
+++ b/net/mac802154/main.c
@@ -246,9 +246,11 @@ int ieee802154_register_hw(struct ieee802154_hw *hw)
 
 	rtnl_lock();
 
+	mutex_lock(&fallback_nd_lock.mutex);
 	dev = ieee802154_if_add(local, "wpan%d", NET_NAME_ENUM,
 				NL802154_IFTYPE_NODE,
 				cpu_to_le64(0x0000000000000000ULL));
+	mutex_unlock(&fallback_nd_lock.mutex);
 	if (IS_ERR(dev)) {
 		rtnl_unlock();
 		rc = PTR_ERR(dev);


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ