[PATCH net v7 2/3] net/rds: drop rds_trans_sem around laddr_check()
From: Aibing Chen
Date: Thu Dec 03 2026 - 21:23:07 EST
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@xxxxxxxxxxxxxxxxxxxxxxxxx
Closes: https://syzkaller.appspot.com/bug?extid=ccdb5058c3df2d94811c
Suggested-by: Allison Henderson <achender@xxxxxxxxxx>
Link: https://lore.kernel.org/all/d83709308a038467b3a4849d814978b84328d2bc.camel@xxxxxxxxxx/
Fixes: ec16227e1414 ("RDS/IB: Infiniband transport")
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Aibing Chen <chenaibing@xxxxxxxxxxxxxxxxxxxx>
---
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)