* [PATCH net v7 0/3] net/rds: fix the probe cm_id lock ordering
@ 2026-12-04 2:22 Aibing Chen
2026-12-04 2:22 ` [PATCH net v7 1/3] net/rds: register the IB transport last Aibing Chen
` (2 more replies)
0 siblings, 3 replies; 7+ messages in thread
From: Aibing Chen @ 2026-12-04 2:22 UTC (permalink / raw)
To: Allison Henderson; +Cc: netdev, linux-kernel
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 2 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().
Dropping the semaphore means rds_trans_unregister() no longer waits for
an in-flight ->laddr_check(), so the module reference has to be
sufficient on its own. It is not while the module is being initialized:
rds_rdma_init() calls rds_ib_init(), which registers the transport, and
only then creates the RDMA CM listener; if that fails, rds_ib_exit()
unregisters again, and do_init_module() frees the module without waiting
for a reference taken on a module in MODULE_STATE_COMING. Patch 1
registers the transport only once the listener is up, so a transport is
never reachable from a module that can still fail to initialize.
Patch 3 handles the second problem on the same path: 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() 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 recursive
locking once the semaphore cycle is gone. Queue that destroy on rds_wq.
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.
v7:
- add patch 1: the module reference taken once rds_trans_sem is dropped
cannot pin a module in MODULE_STATE_COMING that do_init_module() is
about to free; move the transport registration after the listener.
- patch 3: describe the -ENOMEM bound as bounding the queue of pending
destroys, and note that a failing laddr_check() is handled like any
other unsuccessful check.
- fix the comments that still described the old locking.
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.
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 (3):
net/rds: register the IB transport last
net/rds: drop rds_trans_sem around laddr_check()
net/rds: defer the probe cm_id destroy to rds_wq
net/rds/ib.c | 56 ++++++++++++++++++++++++++++++++++++----
net/rds/rdma_transport.c | 7 ++++-
net/rds/transport.c | 25 +++++++++++++-----
3 files changed, 75 insertions(+), 13 deletions(-)
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH net v7 1/3] net/rds: register the IB transport last
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 ` Aibing Chen
2026-12-05 3:05 ` netdev-bot+sashiko
2026-12-04 2:22 ` [PATCH net v7 2/3] net/rds: drop rds_trans_sem around laddr_check() Aibing Chen
2026-12-04 2:22 ` [PATCH net v7 3/3] net/rds: defer the probe cm_id destroy to rds_wq Aibing Chen
2 siblings, 1 reply; 7+ messages in thread
From: Aibing Chen @ 2026-12-04 2:22 UTC (permalink / raw)
To: Allison Henderson; +Cc: netdev, linux-kernel
rds_rdma_init() calls rds_ib_init(), which registers rds_ib_transport,
and only then creates the RDMA CM listener. If the listener setup fails,
rds_ib_exit() unregisters the transport again. Between the two calls the
transport is visible to rds_trans_get_preferred() while the module is
still being initialized, and try_module_get() succeeds for a module in
MODULE_STATE_COMING. A bind() that races with a failed initialization
can then run ->laddr_check() after do_init_module() freed the module.
Register the transport only once the listener is up, so that it is never
reachable from a module that can still fail to initialize, and unregister
it in rds_rdma_exit() before the transport is torn down.
Signed-off-by: Aibing Chen <chenaibing@cmss.chinamobile.com>
---
net/rds/ib.c | 3 ---
net/rds/rdma_transport.c | 7 ++++++-
2 files changed, 6 insertions(+), 4 deletions(-)
diff --git a/net/rds/ib.c b/net/rds/ib.c
index 4ea9838d0..784d358fe 100644
--- a/net/rds/ib.c
+++ b/net/rds/ib.c
@@ -541,7 +541,6 @@ void rds_ib_exit(void)
rds_ib_destroy_nodev_conns();
rds_ib_sysctl_exit();
rds_ib_recv_exit();
- rds_trans_unregister(&rds_ib_transport);
rds_ib_mr_exit();
}
@@ -605,8 +604,6 @@ int rds_ib_init(void)
if (ret)
goto out_sysctl;
- rds_trans_register(&rds_ib_transport);
-
rds_info_register_func(RDS_INFO_IB_CONNECTIONS, rds_ib_ic_info);
#if IS_ENABLED(CONFIG_IPV6)
rds_info_register_func(RDS6_INFO_IB_CONNECTIONS, rds6_ib_ic_info);
diff --git a/net/rds/rdma_transport.c b/net/rds/rdma_transport.c
index 75532734c..690b8a211 100644
--- a/net/rds/rdma_transport.c
+++ b/net/rds/rdma_transport.c
@@ -344,8 +344,12 @@ static int __init rds_rdma_init(void)
goto out;
ret = rds_rdma_listen_init();
- if (ret)
+ if (ret) {
rds_ib_exit();
+ goto out;
+ }
+
+ rds_trans_register(&rds_ib_transport);
out:
return ret;
}
@@ -355,6 +359,7 @@ static void __exit rds_rdma_exit(void)
{
/* stop listening first to ensure no new connections are attempted */
rds_rdma_listen_stop();
+ rds_trans_unregister(&rds_ib_transport);
rds_ib_exit();
}
module_exit(rds_rdma_exit);
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH net v7 2/3] net/rds: drop rds_trans_sem around laddr_check()
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-04 2:22 ` Aibing Chen
2026-12-05 3:05 ` 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
2 siblings, 1 reply; 7+ messages in thread
From: Aibing Chen @ 2026-12-04 2:22 UTC (permalink / raw)
To: Allison Henderson; +Cc: netdev, linux-kernel
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)
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH net v7 3/3] net/rds: defer the probe cm_id destroy to rds_wq
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-04 2:22 ` [PATCH net v7 2/3] net/rds: drop rds_trans_sem around laddr_check() Aibing Chen
@ 2026-12-04 2:22 ` Aibing Chen
2026-12-05 3:05 ` netdev-bot+sashiko
2 siblings, 1 reply; 7+ messages in thread
From: Aibing Chen @ 2026-12-04 2:22 UTC (permalink / raw)
To: Allison Henderson; +Cc: netdev, linux-kernel
rds_ib_laddr_check() is called from rds_trans_get_preferred(), which runs
both on the bind path and from the passive connection path, where
rdma_cm's handler_mutex is already held:
cma_ib_req_handler()
rds_ib_cm_handle_connect()
rds_conn_create()
rds_trans_get_preferred()
rds_ib_laddr_check()
rdma_destroy_id()
mutex_lock(&id_priv->handler_mutex)
rdma_destroy_id() takes the handler mutex of the probe id, which is a
different instance of the same lock class, so lockdep reports a recursive
locking dependency as soon as a connection is established.
Destroy the probe id from rds_wq instead, so that the destroy runs without
either rds_trans_sem or handler_mutex held. The work item is allocated
before rdma_create_id(), so an allocation failure fails the address check
instead of falling back to the synchronous destroy, and the number of
pending destroys is bounded by RDS_IB_MAX_PROBE_PENDING (64). Above the
bound the check fails with -ENOMEM; callers treat that like any other
unsuccessful laddr_check().
rds_ib_exit() flushes rds_wq before the transport is torn down, so a
queued destroy cannot run after the module text is gone.
Fixes: ec16227e1414 ("RDS/IB: Infiniband transport")
Cc: stable@vger.kernel.org
Signed-off-by: Aibing Chen <chenaibing@cmss.chinamobile.com>
---
net/rds/ib.c | 53 +++++++++++++++++++++++++++++++++++++++++++--
net/rds/transport.c | 7 +++---
2 files changed, 55 insertions(+), 5 deletions(-)
diff --git a/net/rds/ib.c b/net/rds/ib.c
index 784d358fe..a3ee52fa9 100644
--- a/net/rds/ib.c
+++ b/net/rds/ib.c
@@ -391,6 +391,31 @@ static void rds6_ib_ic_info(struct socket *sock, unsigned int len,
}
#endif
+/*
+ * The probe cm_id must not be destroyed from the caller's context:
+ * rds_ib_laddr_check() may run while rdma_cm's handler_mutex is held (the
+ * passive connection path), and rdma_destroy_id() takes the handler_mutex
+ * of the probe id, which is a different instance of the same lock class.
+ * Queue the destruction on rds_wq, which runs without either that mutex
+ * or rds_trans_sem.
+ */
+struct rds_ib_probe_work {
+ struct work_struct work;
+ struct rdma_cm_id *cm_id;
+};
+
+static atomic_t rds_ib_probe_pending = ATOMIC_INIT(0);
+#define RDS_IB_MAX_PROBE_PENDING 64
+
+static void rds_ib_probe_work_fn(struct work_struct *work)
+{
+ struct rds_ib_probe_work *pw =
+ container_of(work, struct rds_ib_probe_work, work);
+
+ rdma_destroy_id(pw->cm_id);
+ kfree(pw);
+ atomic_dec(&rds_ib_probe_pending);
+}
/*
* Early RDS/IB was built to only bind to an address if there is an IPoIB
* device with that address set.
@@ -406,6 +431,7 @@ static int rds_ib_laddr_check_cm(struct net *net, const struct in6_addr *addr,
{
int ret;
struct rdma_cm_id *cm_id;
+ struct rds_ib_probe_work *pw;
#if IS_ENABLED(CONFIG_IPV6)
struct sockaddr_in6 sin6;
#endif
@@ -414,11 +440,25 @@ static int rds_ib_laddr_check_cm(struct net *net, const struct in6_addr *addr,
bool isv4;
isv4 = ipv6_addr_v4mapped(addr);
+
+ pw = kzalloc_obj(*pw);
+ if (!pw)
+ return -ENOMEM;
+
+ if (atomic_inc_return(&rds_ib_probe_pending) > RDS_IB_MAX_PROBE_PENDING) {
+ atomic_dec(&rds_ib_probe_pending);
+ kfree(pw);
+ return -ENOMEM;
+ }
+
/* Create a CMA ID restricted to IB devices and try to bind it. */
cm_id = rdma_create_id(&init_net, rds_rdma_cm_event_handler,
NULL, RDMA_PS_TCP, IB_QPT_RC);
- if (IS_ERR(cm_id))
+ if (IS_ERR(cm_id)) {
+ kfree(pw);
+ atomic_dec(&rds_ib_probe_pending);
return PTR_ERR(cm_id);
+ }
ret = rdma_restrict_node_type(cm_id, RDMA_NODE_IB_CA);
if (ret)
goto out;
@@ -484,7 +524,9 @@ static int rds_ib_laddr_check_cm(struct net *net, const struct in6_addr *addr,
cm_id->device ? cm_id->device->node_type : -1);
out:
- rdma_destroy_id(cm_id);
+ INIT_WORK(&pw->work, rds_ib_probe_work_fn);
+ pw->cm_id = cm_id;
+ queue_work(rds_wq, &pw->work);
return ret;
}
@@ -541,6 +583,13 @@ void rds_ib_exit(void)
rds_ib_destroy_nodev_conns();
rds_ib_sysctl_exit();
rds_ib_recv_exit();
+
+ /*
+ * rds_ib_laddr_check_cm() may have queued a probe destroy on rds_wq;
+ * wait for it before the module text goes away.
+ */
+ flush_workqueue(rds_wq);
+
rds_ib_mr_exit();
}
diff --git a/net/rds/transport.c b/net/rds/transport.c
index 4e667580f..cb37d9b08 100644
--- a/net/rds/transport.c
+++ b/net/rds/transport.c
@@ -105,9 +105,10 @@ struct rds_transport *rds_trans_get_preferred(struct net *net,
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.
+ * ->laddr_check() creates an rdma_cm id and may reach into
+ * rdma_cm's locking. Its destruction is deferred to rds_wq,
+ * but don't hold rds_trans_sem across the check itself: the
+ * module reference keeps trans alive.
*/
up_read(&rds_trans_sem);
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH net v7 1/3] net/rds: register the IB transport last
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
0 siblings, 0 replies; 7+ messages in thread
From: netdev-bot+sashiko @ 2026-12-05 3:05 UTC (permalink / raw)
To: chenaibing; +Cc: achender, netdev, linux-kernel, kuba
Thank you for your contribution! Sashiko AI review found 1 potential
issue(s) to consider.
Critical: 0 · High: 0 · Medium: 1 · Low: 0
If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).
- [Medium] Commit "net/rds: register the IB transport last" fixes a use-
after-free of module memory that users can trigger, but its commit…
--
net/rds: register the IB transport last
This patch moves rds_trans_register(&rds_ib_transport) out of
rds_ib_init(). It now runs in rds_rdma_init(), after
rds_rdma_listen_init() succeeds, and the matching rds_trans_unregister()
moves into rds_rdma_exit(). As a result, rds_trans_get_preferred() can
no longer find the transport while the module can still fail to
initialize.
> Register the transport only once the listener is up, so that it is never
> reachable from a module that can still fail to initialize, and unregister
> it in rds_rdma_exit() before the transport is torn down.
>
> Signed-off-by: Aibing Chen <chenaibing@cmss.chinamobile.com>
[Severity: Medium]
Should this patch carry Fixes: and Cc: stable tags?
The window described in the commit message seems to come from commit
8d5d8a5fd7f9 ("RDS: RDMA: start rdma listening after init"). That commit
moved rds_rdma_listen_init() after rds_ib_init(). Before it, nothing in
rds_rdma_init() could fail once rds_trans_register() had run.
A bind() or setsockopt(SO_RDS_TRANSPORT) can race with a failed load.
Either call can find the transport through rds_trans_get_preferred() or
rds_trans_get(), and try_module_get() succeeds on a module in
MODULE_STATE_COMING. A later rds_trans_put() then reads trans->t_owner
from the freed rds_ib_transport.
Something like:
Fixes: 8d5d8a5fd7f9 ("RDS: RDMA: start rdma listening after init")
Cc: stable@vger.kernel.org
The next patch in the series, "net/rds: drop rds_trans_sem around
laddr_check()", is tagged for stable, and its commit message depends on
this one:
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.
Suppose stable takes that patch without this one. Then
rds_trans_unregister() no longer waits for a laddr_check() that is
already running. After a failed init, rds_ib_laddr_check() could then
run in freed module text.
Could this patch be tagged so that both are backported together?
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261204022245.381-1-chenaibing%40cmss.chinamobile.com
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH net v7 2/3] net/rds: drop rds_trans_sem around laddr_check()
2026-12-04 2:22 ` [PATCH net v7 2/3] net/rds: drop rds_trans_sem around laddr_check() Aibing Chen
@ 2026-12-05 3:05 ` netdev-bot+sashiko
0 siblings, 0 replies; 7+ messages in thread
From: netdev-bot+sashiko @ 2026-12-05 3:05 UTC (permalink / raw)
To: chenaibing; +Cc: achender, netdev, linux-kernel, kuba
Thank you for your contribution! Sashiko AI review found 2 potential
issue(s) to consider.
Critical: 0 · High: 0 (1) · Medium: 2 · Low: 0
If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).
- [Medium] This patch carries `Cc: stable@vger.kernel.org` and `Fixes:
ec16227e1414` ("RDS/IB: Infiniband transport"), which covers every…
- [Medium] net/rds: unaddressed v6 maintainer CR to avoid
rds_trans_get_preferred()
Pre-existing issues:
- [High] This problem wasn't introduced by this patch, but it is in the
direct caller of the modified function and it is reachable without…
--
net/rds: drop rds_trans_sem around laddr_check()
This patch changes rds_trans_get_preferred() so that it takes the
transport module reference under rds_trans_sem, drops the semaphore and
only then calls ->laddr_check(). This avoids a lockdep-reported dependency
between rds_trans_sem and rdma_cm's handler_mutex. A transport that fails
its check is put and the scan continues.
Link: https://lore.kernel.org/all/d83709308a038467b3a4849d814978b84328d2bc.camel@kernel.org/
> diff --git a/net/rds/transport.c b/net/rds/transport.c
> index f8001ec808671..4e667580f8739 100644
> --- a/net/rds/transport.c
> +++ b/net/rds/transport.c
[ ... ]
> @@ -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;
[Severity: Medium]
Allison's review of v6 asked for a different approach to this bug:
https://lore.kernel.org/r/6f68f3e15dcbe159ccb4503f27329de05c125047.camel@kernel.org
That reply was marked pw-bot: cr. It suggested replacing the series
with a single patch that adds a direct local-address helper,
rds_conn_addr_is_local(), and uses it in __rds_conn_create() instead
of calling rds_trans_get_preferred().
v7 keeps the three-patch approach. Neither the changelog nor the cover
letter seems to say why the change request was not adopted.
In __rds_conn_create(), the result of rds_trans_get_preferred() is
only used as a boolean:
net/rds/connection.c:__rds_conn_create() {
...
loop_trans = rds_trans_get_preferred(net, faddr, conn->c_dev_if);
if (loop_trans) {
rds_trans_put(loop_trans);
conn->c_loopback = 1;
...
}
That is also the only place where rds_trans_sem is taken, or
rds_ib_laddr_check() is called, with rdma_cm's handler_mutex held. The
path is rds_ib_cm_handle_connect() -> rds_conn_create(). The other
caller, rds_bind(), runs from syscall context without handler_mutex.
Local IB, IPoIB and RoCE addresses are ordinary local interface
addresses. So __rds_conn_create() could check faddr directly with
inet_addr_type() == RTN_LOCAL and ipv6_chk_addr(). That removes both
the handler_mutex -> rds_trans_sem dependency and the handler_mutex ->
probe rdma_destroy_id() dependency.
With that change, none of the following would be needed:
- dropping and retaking rds_trans_sem around ->laddr_check() here
- reordering the IB transport registration
- deferring the probe cm_id destroy to rds_wq with a 64-entry pending
cap, as patch 3 does
Dropping the semaphore in this loop is also what creates the stable
ordering dependency raised above.
Was the v6 suggestion considered and rejected for a technical reason?
If so, could the changelog explain it? If not, would a respin along
the lines Allison proposed be simpler and easier to backport?
[Severity: Medium]
Is this safe in the stable trees this patch is tagged for? The commit
message says:
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.
That is true in mainline. There, rds_rdma_init() calls
rds_trans_register(&rds_ib_transport) only after rds_rdma_listen_init()
succeeds.
That ordering seems to come from the earlier commit "net/rds: register the
IB transport last". That commit has no Fixes: or Cc: stable tag, and this
patch doesn't list it as a stable prerequisite.
With Fixes: ec16227e1414 and Cc: stable, this patch would go back to
trees where rds_ib_init() still registers the transport before
rds_rdma_listen_init(). That function can fail and call rds_ib_exit().
Before this patch, ->laddr_check() ran under down_read(&rds_trans_sem).
That meant rds_trans_unregister()'s down_write() in the failed init path
had to wait for it.
Now try_module_get() succeeds on a module in MODULE_STATE_COMING, and
do_init_module() frees a module whose init failed regardless of its
refcount:
CPU1 (bind) CPU2 (modprobe rds_rdma)
rds_trans_get_preferred()
try_module_get(trans->t_owner)
up_read(&rds_trans_sem)
rds_rdma_listen_init() fails
rds_ib_exit()
rds_trans_unregister()
do_init_module() frees the module
trans->laddr_check()
or rds_trans_put(trans)
Could this run rds_ib_laddr_check() from freed module text, or call
module_put() on a freed struct module?
The baseline already had a related problem: a successful bind leaves
rs->rs_transport pointing into the freed module. The prerequisite commit
fixes that as well.
Would it make sense to tag "net/rds: register the IB transport last" with
Fixes: and Cc: stable, or to list it as a prerequisite in this patch's
stable tag?
> +
> + rds_trans_put(trans);
> + down_read(&rds_trans_sem);
> }
> up_read(&rds_trans_sem);
>
> - return ret;
> + return NULL;
> }
[Severity: High]
This is a pre-existing issue and wasn't introduced by this patch. It is
in the direct caller of rds_trans_get_preferred(), though. Does rds_bind()
leak the transport module reference when rds_add_bound() fails?
net/rds/bind.c:rds_bind() {
...
} else {
trans = rds_trans_get_preferred(sock_net(sock->sk),
binding_addr, scope_id);
...
rs->rs_transport = trans;
}
sock_set_flag(sk, SOCK_RCU_FREE);
ret = rds_add_bound(rs, binding_addr, &port, scope_id);
if (ret)
rs->rs_transport = NULL;
...
}
The reference may come from rds_trans_get_preferred(), or from
rds_trans_get() when SO_RDS_TRANSPORT was set earlier. Either way it is
dropped by clearing the pointer, with no call to rds_trans_put(trans).
rds_release() later calls rds_trans_put(rs->rs_transport) on NULL, so
module_put() never happens.
Because rs_transport is reset to NULL, this check in rds_set_transport()
no longer stops SO_RDS_TRANSPORT from being set again on the same socket:
if (rs->rs_transport)
return -EOPNOTSUPP; /* previously attached to transport */
An unprivileged user can bind one RDS socket to an addr:port and then
call bind() over and over on a second socket with the same addr:port.
Each -EADDRINUSE from rds_add_bound() leaks one reference on rds_tcp or
rds_rdma.
Besides making the module impossible to unload, this can wrap
struct module::refcnt, which is an unsaturated atomic_t, after around
2^32 leaks. Once the count reaches 0, try_module_get() fails and
rds_trans_get_preferred() returns NULL for every caller.
This looks to have been present since commit 05733434ee9a.
Should the failure path call rds_trans_put(trans) before clearing
rs->rs_transport?
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261204022245.381-1-chenaibing%40cmss.chinamobile.com
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH net v7 3/3] net/rds: defer the probe cm_id destroy to rds_wq
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
0 siblings, 0 replies; 7+ messages in thread
From: netdev-bot+sashiko @ 2026-12-05 3:05 UTC (permalink / raw)
To: chenaibing; +Cc: achender, netdev, linux-kernel, kuba
Thank you for your contribution! Sashiko AI review found 4 potential
issue(s) to consider.
Critical: 0 · High: 1 · Medium: 2 · Low: 1
If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).
- [High] The patch adds a global cap of 64 pending probe destroys
(`rds_ib_probe_pending` / `RDS_IB_MAX_PROBE_PENDING`).
- [Medium] Deferring `rdma_destroy_id()` keeps a successfully bound probe
cm_id attached to its `cma_device` until the shared single-threaded…
- [Medium] rds: unaddressed v6 request to use local-addr check in
__rds_conn_create()
- [Low] The rewritten comment in the generic `rds_trans_get_preferred()`
loop (net/rds/transport.c:107-112) says '->laddr_check() creates an…
--
net/rds: defer the probe cm_id destroy to rds_wq
This patch moves rdma_destroy_id() of the probe cm_id in
rds_ib_laddr_check_cm() onto rds_wq. The goal is to avoid a lockdep
recursive handler_mutex report on the passive connection path. It
preallocates one work item per probe and caps pending destroys at 64,
failing the address check with -ENOMEM above that. It also flushes rds_wq
in rds_ib_exit().
> diff --git a/net/rds/ib.c b/net/rds/ib.c
> index 784d358fe657e..a3ee52fa927e4 100644
> --- a/net/rds/ib.c
> +++ b/net/rds/ib.c
[ ... ]
> @@ -414,11 +440,25 @@ static int rds_ib_laddr_check_cm(struct net *net, const struct in6_addr *addr,
> bool isv4;
>
> isv4 = ipv6_addr_v4mapped(addr);
> +
> + pw = kzalloc_obj(*pw);
> + if (!pw)
> + return -ENOMEM;
> +
> + if (atomic_inc_return(&rds_ib_probe_pending) > RDS_IB_MAX_PROBE_PENDING) {
> + atomic_dec(&rds_ib_probe_pending);
> + kfree(pw);
> + return -ENOMEM;
> + }
[Severity: High]
Can this cap make a valid IB address look like it is not on IB?
Once rds_ib_probe_pending goes above 64, rds_ib_laddr_check_cm() returns
-ENOMEM before it looks at the address at all. The counter is only
decremented in rds_ib_probe_work_fn(), and rds_wq is ordered:
net/rds/threads.c:rds_threads_init() {
...
rds_wq = create_singlethread_workqueue("krdsd");
...
}
rds_wq is also shared with rds_tcp_accept_w, rds_ibdev->free_work,
m_unpin_work and the fallback per-path connection workers. The destroys
therefore drain one at a time, behind unrelated work.
rds_trans_get_preferred() only checks for zero:
if (trans->laddr_check(net, addr, scope_id) == 0)
return trans;
rds_trans_put(trans);
down_read(&rds_trans_sem);
So the -ENOMEM from the cap is treated as "try the next transport". These
are the outcomes:
- rds_bind() with no transport set: rds_tcp_laddr_check() accepts a local
IPoIB address, so the socket is silently bound to rds_tcp_transport and
later RDMA operations fail. If rds_tcp is not loaded, bind fails with
-EADDRNOTAVAIL.
- rds_bind() with SO_RDS_TRANSPORT set to IB fails with -ENOPROTOOPT.
- __rds_conn_create() probes faddr through rds_trans_get_preferred() for
every new connection. A spurious NULL there leaves c_loopback unset for
a local faddr for the life of the conn.
The rds_ib_get_device() fast path in rds_ib_laddr_check() only covers IPv4
addresses that are already in an rds_ib_device ipaddr list. IPv6 binds,
first IPv4 binds and every new-conn faddr probe all use a slot.
The counter is global. Creating an RDS socket and calling bind() need no
capability, and a failed bind leaves the socket unbound so it can retry.
Could an unprivileged user looping bind() from several CPUs hold the
counter at the cap for everyone else in init_net?
rds_tcp_accept_worker() also runs on rds_wq and loops
rds_tcp_accept_one()->rds_conn_create(). None of the destroys it queues
can run until it returns.
The commit message says:
Above the bound the check fails with -ENOMEM; callers treat that like
any other unsuccessful laddr_check().
It does not mention the silent move to TCP or the dependency on the
shared queue. Once the cap is reached there is no wait, reclaim or
synchronous fallback. Is there a way to avoid failing the check outright
here?
> +
> /* Create a CMA ID restricted to IB devices and try to bind it. */
> cm_id = rdma_create_id(&init_net, rds_rdma_cm_event_handler,
> NULL, RDMA_PS_TCP, IB_QPT_RC);
[ ... ]
> @@ -484,7 +524,9 @@ static int rds_ib_laddr_check_cm(struct net *net, const struct in6_addr *addr,
> cm_id->device ? cm_id->device->node_type : -1);
>
> out:
> - rdma_destroy_id(cm_id);
> + INIT_WORK(&pw->work, rds_ib_probe_work_fn);
> + pw->cm_id = cm_id;
> + queue_work(rds_wq, &pw->work);
[Severity: Medium]
Was the v6 review feedback on this approach addressed?
On v6, Allison asked for __rds_conn_create() to stop calling
rds_trans_get_preferred() and to use a direct local-address check
instead. v7 doesn't seem to reflect that. net/rds/connection.c is
unchanged, and this patch still works around the recursion inside
rds_ib_laddr_check_cm().
Only one caller of rds_trans_get_preferred() runs with rdma_cm's
handler_mutex held, the passive connect path:
rds_rdma_cm_event_handler_cmn()
rds_ib_cm_handle_connect()
rds_conn_create()
__rds_conn_create()
rds_trans_get_preferred()
The other caller, rds_bind(), runs from the bind() syscall and not
from an rdma_cm handler.
In __rds_conn_create(), the transport returned for faddr is dropped
with rds_trans_put() right away. It is only used to decide whether
faddr is local, so that c_loopback gets set and the
t_prefer_loopback handling either switches to rds_loop_transport or
returns -EOPNOTSUPP.
A small helper could answer that question directly. It would check
IN_LOOPBACKNET, inet_addr_type() == RTN_LOCAL, ipv6_addr_loopback()
and ipv6_chk_addr() under rcu_read_lock(). Those are the same checks
that rds_tcp_laddr_check() and the loopback shortcut in
rds_trans_get_preferred() already make. It would not take
rds_trans_sem and would not create a probe cm_id under
handler_mutex.
That single change would remove both problems at once:
- the rds_trans_sem/handler_mutex ordering problem handled by "drop
rds_trans_sem around laddr_check()" and "register the IB transport
last";
- the recursive handler_mutex report handled here.
It would also make the deferred destroy unnecessary, along with the
64-entry cap, its spurious -ENOMEM failures and the new dependency
on rds_wq.
On Kconfig: CONFIG_IPV6 is bool on mainline, so calling
ipv6_chk_addr() from connection.c needs no change there. Stable
trees where IPV6 can still be modular would need "depends on IPV6 ||
!IPV6" on RDS.
Is there a reason the local-address helper doesn't work for this
path? If so, could the changelog explain why the asynchronous destroy
was chosen instead?
[Severity: Medium]
Does deferring the destroy here make HCA removal wait on whatever else is
queued on rds_wq?
After a successful rdma_bind_addr(), the probe id is attached to its
cma_device in _cma_attach_to_dev():
cma_dev_get(cma_dev);
id_priv->cma_dev = cma_dev;
That reference is only dropped by cma_release_dev() when the id is
destroyed.
On device removal, cma_process_remove() sends
RDMA_CM_EVENT_DEVICE_REMOVAL to each id. For the probe id,
rds_rdma_cm_event_handler_cmn() has no conn and returns 0:
case RDMA_CM_EVENT_DEVICE_REMOVAL:
case RDMA_CM_EVENT_ADDR_CHANGE:
if (conn)
rds_conn_drop(conn);
break;
So rdma_cm does not destroy the id itself, and cma_process_remove() then
waits with no timeout:
cma_dev_put(cma_dev);
wait_for_completion(&cma_dev->comp);
That wait can now only finish after rds_ib_probe_work_fn() runs on the
ordered rds_wq. Anything queued ahead of it delays it: the TCP accept loop
(which keeps running while remote connects arrive), rds_ib_dev_free,
unpin work and fallback connection workers. Before this patch the destroy
ran inline, right after the bind.
The existing flush_workqueue(rds_wq) calls in rds_ib_unregister_client()
and rds_tcp_listen_stop() also now wait for up to 64 rdma_destroy_id()
calls.
I couldn't show a closed deadlock cycle. Is this new dependency of a
synchronous RDMA core wait on unrelated RDS work intended?
>
> return ret;
> }
[ ... ]
> diff --git a/net/rds/transport.c b/net/rds/transport.c
> index 4e667580f8739..cb37d9b08f12c 100644
> --- a/net/rds/transport.c
> +++ b/net/rds/transport.c
> @@ -105,9 +105,10 @@ struct rds_transport *rds_trans_get_preferred(struct net *net,
> 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.
> + * ->laddr_check() creates an rdma_cm id and may reach into
> + * rdma_cm's locking. Its destruction is deferred to rds_wq,
> + * but don't hold rds_trans_sem across the check itself: the
> + * module reference keeps trans alive.
> */
[Severity: Low]
This isn't a bug, but is this comment accurate for every transport the
loop visits?
rds_tcp_laddr_check() only uses inet_addr_type(), dev_get_by_index_rcu()
and ipv6_chk_addr(). It creates no rdma_cm id and defers nothing.
rds_ib_laddr_check() can also return 0 from the rds_ib_get_device() fast
path without creating an id.
The old "may create" wording was accurate. The new text also presents the
deferral as the reason for dropping rds_trans_sem, but the real constraint
is the IB-specific rdma_cm locking inside the check itself.
> up_read(&rds_trans_sem);
>
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261204022245.381-1-chenaibing%40cmss.chinamobile.com
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2026-12-05 3:05 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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 ` [PATCH net v7 2/3] net/rds: drop rds_trans_sem around laddr_check() Aibing Chen
2026-12-05 3:05 ` 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
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.