Netdev List
 help / color / mirror / Atom feed
From: Aibing Chen <chenaibing@cmss.chinamobile.com>
To: Allison Henderson <achender@kernel.org>
Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH net v7 2/3] net/rds: drop rds_trans_sem around laddr_check()
Date: Fri,  4 Dec 2026 10:22:43 +0800	[thread overview]
Message-ID: <20261204022245.381-3-chenaibing@cmss.chinamobile.com> (raw)
In-Reply-To: <20261204022245.381-1-chenaibing@cmss.chinamobile.com>

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 takes rdma_cm's handler_mutex, while the CM
callback path takes handler_mutex before entering RDS through
rds_conn_create() -> rds_trans_get_preferred() -> down_read(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 under 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.

The transport is only registered once rds_rdma_init() can no longer fail,
so the reference cannot be taken on a module that is about to be freed.

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..4e667580f 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 an rdma_cm id and take
+		 * 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)



  parent reply	other threads:[~2026-12-04  2:22 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-04  2:22 [PATCH net v7 0/3] net/rds: fix the probe cm_id lock ordering Aibing Chen
2026-12-04  2:22 ` [PATCH net v7 1/3] net/rds: register the IB transport last Aibing Chen
2026-12-05  3:05   ` netdev-bot+sashiko
2026-12-04  2:22 ` Aibing Chen [this message]
2026-12-05  3:05   ` [PATCH net v7 2/3] net/rds: drop rds_trans_sem around laddr_check() netdev-bot+sashiko
2026-12-04  2:22 ` [PATCH net v7 3/3] net/rds: defer the probe cm_id destroy to rds_wq Aibing Chen
2026-12-05  3:05   ` netdev-bot+sashiko

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261204022245.381-3-chenaibing@cmss.chinamobile.com \
    --to=chenaibing@cmss.chinamobile.com \
    --cc=achender@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox