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: <174265445402.356712.9364160514313425614.stgit@pro.pro>
Date: Sat, 22 Mar 2025 17:40:54 +0300
From: Kirill Tkhai <tkhai@...ru>
To: netdev@...r.kernel.org,
	linux-kernel@...r.kernel.org
Cc: tkhai@...ru
Subject: [PATCH NET-PREV 24/51] lapbeth: Provide determined context in __register_netdevice()

In case of caller already owns nd_lock, there is
nesting without underlying that to lockdep.

So we use trylock and __register_netdevice() here.

XXX: after callers of netdevice notifyiers are converted,
we will inherit @edev nd_lock instead.

Signed-off-by: Kirill Tkhai <tkhai@...ru>
---
 drivers/net/wan/lapbether.c |   28 +++++++++++++++++++++++++---
 1 file changed, 25 insertions(+), 3 deletions(-)

diff --git a/drivers/net/wan/lapbether.c b/drivers/net/wan/lapbether.c
index 56326f38fe8a..793a2ed424c0 100644
--- a/drivers/net/wan/lapbether.c
+++ b/drivers/net/wan/lapbether.c
@@ -380,6 +380,7 @@ static int lapbeth_new_device(struct net_device *dev)
 {
 	struct net_device *ndev;
 	struct lapbethdev *lapbeth;
+	struct nd_lock *nd_lock;
 	int rc = -ENOMEM;
 
 	ASSERT_RTNL();
@@ -392,6 +393,23 @@ static int lapbeth_new_device(struct net_device *dev)
 	if (!ndev)
 		goto out;
 
+	rc = -ENOMEM;
+	nd_lock = alloc_nd_lock();
+	if (!nd_lock)
+		goto err_free;
+
+	/* This is called from netdevice notifier, which is not converted yet.
+	 * The context is unknown: either some nd_lock is locked or not. Since
+	 * @ndev is undependent of @edev (on this stage of convertation we don't
+	 * require that, we will require when we convert unregister_netdev()).
+	 * So, a new nd_lock is used for @ndev for now.
+	 * Q: Why is trylock, despite it can't fail?
+	 * A: Caller may own some other nd_lock, so lockdep will unhappy seeing
+	 * there is nested lock without mutex_lock_nested() prefix.
+	 */
+	BUG_ON(!mutex_trylock(&nd_lock->mutex));
+	attach_nd_lock(ndev, nd_lock);
+
 	/* When transmitting data:
 	 * first this driver removes a pseudo header of 1 byte,
 	 * then the lapb module prepends an LAPB header of at most 3 bytes,
@@ -415,15 +433,19 @@ static int lapbeth_new_device(struct net_device *dev)
 	netif_napi_add_weight(ndev, &lapbeth->napi, lapbeth_napi_poll, 16);
 
 	rc = -EIO;
-	if (register_netdevice(ndev))
-		goto fail;
+	if (__register_netdevice(ndev))
+		goto err_put;
+	unlock_netdev(nd_lock);
 
 	list_add_rcu(&lapbeth->node, &lapbeth_devices);
 	rc = 0;
 out:
 	return rc;
-fail:
+err_put:
 	dev_put(dev);
+	detach_nd_lock(ndev);
+	unlock_netdev(nd_lock);
+err_free:
 	free_netdev(ndev);
 	goto out;
 }


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ