🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: linux.kernel.netdev
2 messages
2 total messages Started by Aibing Chen Wed, 02 Dec 2026 02:40
[PATCH net v6 0/2] net/rds: fix the probe cm_id lock ordering
#25573
Author: Aibing Chen
Date: Wed, 02 Dec 2026 02:40
78 lines
11784 bytes
syzbot reported a circular locking dependency between rds_trans_sem and
rdma_cm's handler_mutex:

  CPU0 (passive connection)          CPU1 (bind)
  ----                               ----
  mutex_lock(&handler_mutex)         down_read(&rds_trans_sem)
  rds_ib_cm_handle_connect()         rds_ib_laddr_check()
    rds_conn_create()                  rdma_destroy_id()
      rds_trans_get_preferred()          mutex_lock(&handler_mutex)
        down_read(&rds_trans_sem)

Patch 1 fixes the cycle the way the review asked for: take the module
reference for the candidate transport under rds_trans_sem, drop the
semaphore, and only then call ->laddr_check().

Running that on a two-node rxe setup showed one more problem on the same
path, which patch 2 fixes: when ->laddr_check() runs from the passive
connection path, cma_ib_req_handler() already holds the listener's
handler_mutex, and rds_ib_laddr_check() creates and destroys a probe
cm_id whose rdma_destroy_id() takes the handler mutex of the probe id.
Both are instances of the same lock class, so lockdep reports a
recursive locking dependency.  Destroy the probe id from rds_wq, where
neither lock is held.

Evidence, both nodes on a PROVE_LOCKING kernel, rxe0 on each node, an RDS
connection established and then a bind() to an address that is not on an
RDMA device (which is what reaches rds_ib_laddr_check_cm()):

  mainline:  WARNING: possible circular locking dependency detected
             rds_trans_sem --> &id_priv->handler_mutex
                           --> &id_priv->handler_mutex/1
             ... rdma_destroy_id <- rds_ib_laddr_check
                 <- rds_trans_get_preferred <- rds_bind
                 and down_read(rds_trans_sem) <- rds_trans_get_preferred
                 <- __rds_conn_create

  this series: no lockdep report at all in the same run.

I could not run syzbot's reproducer; the setup above is a hand-made
equivalent.  No runtime testing on real RDMA hardware was done, so the
patches are compile tested (W=1) and tested on rxe only.

v6:
- add patch 2: the ordering fix alone still leaves the probe cm_id
  destroy nested under the CM handler's mutex, which lockdep reports as
  recursive locking once the semaphore cycle is gone.
- patch 2 fails the address check with -ENOMEM above the bound instead
  of returning -EAGAIN, so rds_trans_get_preferred() cannot fall back to
  another transport.

v5:
- implement the ordering fix in rds_trans_get_preferred() as requested
  in the review (dropping the net/rds/ib.c workqueue, the global cap and
  the rds_wq flush of v4) and describe the report as a lock class
  conflict rather than a deadlock.

v4 and earlier:
- deferred rdma_destroy_id() to a workqueue and bounded the backlog.

Reported-by: syzbot+ccdb5058c3df2d94811c@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=ccdb5058c3df2d94811c
Suggested-by: Allison Henderson <achender@kernel.org>
Link: https://lore.kernel.org/all/d83709308a038467b3a4849d814978b84328d2bc.camel@kernel.org/
Fixes: ec16227e1414 ("RDS/IB: Infiniband transport")
Cc: stable@vger.kernel.org
Signed-off-by: Aibing Chen <chenaibing@cmss.chinamobile.com>

Aibing Chen (2):
  net/rds: drop rds_trans_sem around laddr_check()
  net/rds: defer the probe cm_id destroy to rds_wq

 net/rds/ib.c        | 50 +++++++++++++++++++++++++++++++++++++++++++++++--
 net/rds/transport.c | 24 +++++++++++++++-------
 2 files changed, 67 insertions(+), 7 deletions(-)

-- 
2.50.1.windows.1
[PATCH net v6 1/2] net/rds: drop rds_trans_sem around laddr_check()
#25576
Author: Aibing Chen
Date: Wed, 02 Dec 2026 02:40
77 lines
11326 bytes
rds_trans_get_preferred() calls ->laddr_check() while holding
rds_trans_sem for reading.  The IB transport's laddr_check() creates a
temporary rdma_cm id and destroys it again, and rdma_destroy_id() takes
rdma_cm's handler_mutex.  The CM callback path takes handler_mutex before
entering RDS through rds_conn_create(), which ends up in
rds_trans_get_preferred() and takes rds_trans_sem, so lockdep reports a
circular locking dependency between the semaphore and the handler mutex
class.

All handler_mutex instances share one lock class and the probe id's mutex
is private to it, so this is a lock class conflict rather than a single
deadlock, but rds_trans_sem should not be held across a call that reaches
into another subsystem's locking.

Take the module reference for the candidate transport while holding
rds_trans_sem, drop the semaphore, and only then call ->laddr_check().
The module reference keeps the transport and its callback alive, and
rds_trans_sem is no longer held when handler_mutex is taken.  A transport
that fails its check is put and the scan continues.

Reported-by: syzbot+ccdb5058c3df2d94811c@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=ccdb5058c3df2d94811c
Suggested-by: Allison Henderson <achender@kernel.org>
Link: https://lore.kernel.org/all/d83709308a038467b3a4849d814978b84328d2bc.camel@kernel.org/
Fixes: ec16227e1414 ("RDS/IB: Infiniband transport")
Cc: stable@vger.kernel.org
Signed-off-by: Aibing Chen <chenaibing@cmss.chinamobile.com>
---
 net/rds/transport.c | 24 +++++++++++++++++-------
 1 file changed, 17 insertions(+), 7 deletions(-)

diff --git a/net/rds/transport.c b/net/rds/transport.c
index f8001ec80..904b9351e 100644
--- a/net/rds/transport.c
+++ b/net/rds/transport.c
@@ -86,7 +86,6 @@ struct rds_transport *rds_trans_get_preferred(struct net *net,
 					      const struct in6_addr *addr,
 					      __u32 scope_id)
 {
-	struct rds_transport *ret = NULL;
 	struct rds_transport *trans;
 	unsigned int i;
 
@@ -101,15 +100,26 @@ struct rds_transport *rds_trans_get_preferred(struct net *net,
 	for (i = 0; i < RDS_TRANS_COUNT; i++) {
 		trans = transports[i];
 
-		if (trans && (trans->laddr_check(net, addr, scope_id) == 0) &&
-		    (!trans->t_owner || try_module_get(trans->t_owner))) {
-			ret = trans;
-			break;
-		}
+		if (!trans ||
+		    (trans->t_owner && !try_module_get(trans->t_owner)))
+			continue;
+
+		/*
+		 * ->laddr_check() may create and destroy an rdma_cm id, which
+		 * takes rdma_cm's handler_mutex.  Don't hold rds_trans_sem
+		 * across it: the module reference keeps trans alive.
+		 */
+		up_read(&rds_trans_sem);
+
+		if (trans->laddr_check(net, addr, scope_id) == 0)
+			return trans;
+
+		rds_trans_put(trans);
+		down_read(&rds_trans_sem);
 	}
 	up_read(&rds_trans_sem);
 
-	return ret;
+	return NULL;
 }
 
 struct rds_transport *rds_trans_get(int t_type)
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads