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: syzb…@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=ccdb5058c3df2d94811c
Suggested-by: Allison Henderson <ache…@kernel.org>
Link: https://lore.kernel.org/all/d837…@kernel.org/
Fixes: ec16227e1414 ("RDS/IB: Infiniband transport")
Cc: stab…@vger.kernel.org
Signed-off-by: Aibing Chen <chen…@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)
[PATCH net v6 1/2] net/rds: drop rds_trans_sem around laddr_check()
- From
- chen…@cmss.chinamobile.com (Aibing Chen)
- Organization
- Usenet Network
- Message-ID
- <2026…@cmss.chinamobile.com>
- Date
- Newsgroups
- linux.kernel.netdev