mirror of https://lore.kernel.org/lkml/
 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 v6 1/2] net/rds: drop rds_trans_sem around laddr_check()
Date: Wed,  2 Dec 2026 10:40:53 +0800	[thread overview]
Message-ID: <20261202024054.1945-2-chenaibing@cmss.chinamobile.com> (raw)
In-Reply-To: <20261202024054.1945-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 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)



  reply	other threads:[~2026-12-02  2:40 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-02  2:40 [PATCH net v6 0/2] net/rds: fix the probe cm_id lock ordering Aibing Chen
2026-12-02  2:40 ` Aibing Chen [this message]
2026-12-03  3:38   ` [PATCH net v6 1/2] net/rds: drop rds_trans_sem around laddr_check() netdev-bot+sashiko
2026-12-02  2:40 ` [PATCH net v6 2/2] net/rds: defer the probe cm_id destroy to rds_wq Aibing Chen
2026-12-03  3:38   ` netdev-bot+sashiko
2026-12-03 16:40 ` [PATCH net v6 0/2] net/rds: fix the probe cm_id lock ordering Allison Henderson

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=20261202024054.1945-2-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

all inboxes | Powered by JetHome®