* [PATCH] IB/iser: Fix deadlock during blocking connect
@ 2026-11-23 14:44 Ziyu Zhang
2026-11-23 15:02 ` sashiko-bot
2026-11-26 9:23 ` Leon Romanovsky
0 siblings, 2 replies; 4+ messages in thread
From: Ziyu Zhang @ 2026-11-23 14:44 UTC (permalink / raw)
To: sagi, mgurtovoy, jgg, leon
Cc: linux-rdma, linux-kernel, baijiaju1990, ziyuzhang201
iser_connect() holds state_mutex while waiting for up_completion. The
CMA handler for the same connection needs state_mutex before it can call
iser_connected_handler() and complete up_completion. A blocking connect
can therefore prevent its own connection completion and leave the waiter
blocked until a signal arrives.
Drop state_mutex around the wait and reacquire it before checking the
connection state, preserving serialization of state and cleanup paths.
Fixes: 504130c039f9 ("IB/iser: Protect iser state machine with a mutex")
Cc: stable@vger.kernel.org
Signed-off-by: Ziyu Zhang <ziyuzhang201@gmail.com>
---
drivers/infiniband/ulp/iser/iser_verbs.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/drivers/infiniband/ulp/iser/iser_verbs.c b/drivers/infiniband/ulp/iser/iser_verbs.c
index 55fe68e..9fe2d3f 100644
--- a/drivers/infiniband/ulp/iser/iser_verbs.c
+++ b/drivers/infiniband/ulp/iser/iser_verbs.c
@@ -778,7 +778,9 @@ int iser_connect(struct iser_conn *iser_conn, struct sockaddr *src_addr,
}
if (!non_blocking) {
+ mutex_unlock(&iser_conn->state_mutex);
wait_for_completion_interruptible(&iser_conn->up_completion);
+ mutex_lock(&iser_conn->state_mutex);
if (iser_conn->state != ISER_CONN_UP) {
err = -EIO;
--
2.34.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] IB/iser: Fix deadlock during blocking connect
2026-11-23 14:44 [PATCH] IB/iser: Fix deadlock during blocking connect Ziyu Zhang
@ 2026-11-23 15:02 ` sashiko-bot
2026-11-26 9:23 ` Leon Romanovsky
1 sibling, 0 replies; 4+ messages in thread
From: sashiko-bot @ 2026-11-23 15:02 UTC (permalink / raw)
To: Ziyu Zhang; +Cc: linux-rdma
Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [High] IB/iser: double destroy of iscsi_endpoint and CMA race on
connect_failure
- [High] IB/iser: blocking iser_connect() still hangs when connection
fails
--
commit 25481c11c640d37ac59ae7c53e55d7c62c9a8e55
Author: Ziyu Zhang <ziyuzhang201@gmail.com>
IB/iser: Fix deadlock during blocking connect
This commit drops and reacquires iser_conn->state_mutex around
wait_for_completion_interruptible() in iser_connect() so the CMA handler
can acquire state_mutex and complete up_completion during a blocking
connect.
> diff --git a/drivers/infiniband/ulp/iser/iser_verbs.c b/drivers/infiniband/ulp/iser/iser_verbs.c
> index ab2a27d23478a..5d865b9bfc983 100644
> --- a/drivers/infiniband/ulp/iser/iser_verbs.c
> +++ b/drivers/infiniband/ulp/iser/iser_verbs.c
> @@ -778,7 +778,9 @@ int iser_connect(struct iser_conn *iser_conn, struct sockaddr *src_addr,
> }
>
> if (!non_blocking) {
> + mutex_unlock(&iser_conn->state_mutex);
> wait_for_completion_interruptible(&iser_conn->up_completion);
> + mutex_lock(&iser_conn->state_mutex);
[Severity: High]
Does wait_for_completion_interruptible(&iser_conn->up_completion) still
hang when the connection attempt fails or is rejected?
up_completion is only completed in iser_connected_handler() on
RDMA_CM_EVENT_ESTABLISHED. On address, route, or connect failure,
iser_connect_error() sets iser_conn->state = ISER_CONN_TERMINATING without
completing up_completion, leaving a blocking iser_connect() asleep until a
signal arrives while holding rx_queue_mutex in iscsi_if_rx().
(Note that if error paths complete up_completion, iscsi_iser_ep_poll() will
also need to check iser_conn->state == ISER_CONN_UP when
wait_for_completion_interruptible_timeout() returns a positive value.)
>
> if (iser_conn->state != ISER_CONN_UP) {
> err = -EIO;
[Severity: High]
When wait_for_completion_interruptible() returns with iser_conn->state !=
ISER_CONN_UP, jumping to connect_failure leaves iser_conn->state as
ISER_CONN_PENDING or ISER_CONN_TERMINATING instead of setting
ISER_CONN_DOWN:
drivers/infiniband/ulp/iser/iser_verbs.c:iser_connect() {
...
addr_failure:
iser_conn->state = ISER_CONN_DOWN;
connect_failure:
mutex_unlock(&iser_conn->state_mutex);
iser_conn_release(iser_conn);
return err;
}
Does this cause iscsi_destroy_endpoint() to be called twice on the same
iscsi_endpoint?
Because iser_conn->state is not ISER_CONN_DOWN, iser_conn_release() calls
iscsi_destroy_endpoint(iser_conn->ep), and then iscsi_iser_ep_connect()
calls iscsi_destroy_endpoint(ep) a second time when iser_connect() returns
an error, causing a use-after-free and double free of ep. In addition,
unlocking state_mutex at connect_failure while state is still
ISER_CONN_PENDING allows concurrent iser_cma_handler() callbacks to keep
running during teardown before iser_conn_release() reacquires state_mutex.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261123144440.65441-1-ziyuzhang201@gmail.com?part=1
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] IB/iser: Fix deadlock during blocking connect
2026-11-23 14:44 [PATCH] IB/iser: Fix deadlock during blocking connect Ziyu Zhang
2026-11-23 15:02 ` sashiko-bot
@ 2026-11-26 9:23 ` Leon Romanovsky
2026-11-26 10:22 ` ziyu zhang
1 sibling, 1 reply; 4+ messages in thread
From: Leon Romanovsky @ 2026-11-26 9:23 UTC (permalink / raw)
To: Ziyu Zhang; +Cc: sagi, mgurtovoy, jgg, linux-rdma, linux-kernel, baijiaju1990
On Mon, Nov 23, 2026 at 10:44:40PM +0800, Ziyu Zhang wrote:
> iser_connect() holds state_mutex while waiting for up_completion. The
> CMA handler for the same connection needs state_mutex before it can call
> iser_connected_handler() and complete up_completion. A blocking connect
> can therefore prevent its own connection completion and leave the waiter
> blocked until a signal arrives.
>
> Drop state_mutex around the wait and reacquire it before checking the
> connection state, preserving serialization of state and cleanup paths.
You can't randomly drop locks without any explanation why it is safe.
Thanks
>
> Fixes: 504130c039f9 ("IB/iser: Protect iser state machine with a mutex")
> Cc: stable@vger.kernel.org
> Signed-off-by: Ziyu Zhang <ziyuzhang201@gmail.com>
> ---
> drivers/infiniband/ulp/iser/iser_verbs.c | 2 ++
> 1 file changed, 2 insertions(+)
>
> diff --git a/drivers/infiniband/ulp/iser/iser_verbs.c b/drivers/infiniband/ulp/iser/iser_verbs.c
> index 55fe68e..9fe2d3f 100644
> --- a/drivers/infiniband/ulp/iser/iser_verbs.c
> +++ b/drivers/infiniband/ulp/iser/iser_verbs.c
> @@ -778,7 +778,9 @@ int iser_connect(struct iser_conn *iser_conn, struct sockaddr *src_addr,
> }
>
> if (!non_blocking) {
> + mutex_unlock(&iser_conn->state_mutex);
> wait_for_completion_interruptible(&iser_conn->up_completion);
> + mutex_lock(&iser_conn->state_mutex);
>
> if (iser_conn->state != ISER_CONN_UP) {
> err = -EIO;
> --
> 2.34.1
>
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] IB/iser: Fix deadlock during blocking connect
2026-11-26 9:23 ` Leon Romanovsky
@ 2026-11-26 10:22 ` ziyu zhang
0 siblings, 0 replies; 4+ messages in thread
From: ziyu zhang @ 2026-11-26 10:22 UTC (permalink / raw)
To: Leon Romanovsky
Cc: sagi, mgurtovoy, jgg, linux-rdma, linux-kernel, baijiaju1990
On Thu, 26 Nov 2026 at 17:24, Leon Romanovsky <leon@kernel.org> wrote:
>
> On Mon, Nov 23, 2026 at 10:44:40PM +0800, Ziyu Zhang wrote:
> > iser_connect() holds state_mutex while waiting for up_completion. The
> > CMA handler for the same connection needs state_mutex before it can call
> > iser_connected_handler() and complete up_completion. A blocking connect
> > can therefore prevent its own connection completion and leave the waiter
> > blocked until a signal arrives.
> >
> > Drop state_mutex around the wait and reacquire it before checking the
> > connection state, preserving serialization of state and cleanup paths.
>
> You can't randomly drop locks without any explanation why it is safe.
>
> Thanks
Thanks for pointing this out. I should have explained what keeps the
connection alive while state_mutex is dropped.
iscsi_if_rx() holds rx_queue_mutex for the entire ep_connect() call,
so a netlink bind or disconnect cannot run against this endpoint
during the wait. The endpoint is still unbound, and the connect path
owns iser_conn. RDMA CM callbacks can advance the connection state
or clean up RDMA resources during that window. The only operation
between unlocking and relocking is the wait on up_completion, and
iser_connect() checks the connection state under state_mutex after
reacquiring it.
I sent v2 after the bot review. It also wakes the waiter on
establishment failure and fixes the endpoint double free on the
connect error path.
https://lore.kernel.org/r/20261124090121.77115-1-ziyuzhang201@gmail.com
>
> >
> > Fixes: 504130c039f9 ("IB/iser: Protect iser state machine with a mutex")
> > Cc: stable@vger.kernel.org
> > Signed-off-by: Ziyu Zhang <ziyuzhang201@gmail.com>
> > ---
> > drivers/infiniband/ulp/iser/iser_verbs.c | 2 ++
> > 1 file changed, 2 insertions(+)
> >
> > diff --git a/drivers/infiniband/ulp/iser/iser_verbs.c b/drivers/infiniband/ulp/iser/iser_verbs.c
> > index 55fe68e..9fe2d3f 100644
> > --- a/drivers/infiniband/ulp/iser/iser_verbs.c
> > +++ b/drivers/infiniband/ulp/iser/iser_verbs.c
> > @@ -778,7 +778,9 @@ int iser_connect(struct iser_conn *iser_conn, struct sockaddr *src_addr,
> > }
> >
> > if (!non_blocking) {
> > + mutex_unlock(&iser_conn->state_mutex);
> > wait_for_completion_interruptible(&iser_conn->up_completion);
> > + mutex_lock(&iser_conn->state_mutex);
> >
> > if (iser_conn->state != ISER_CONN_UP) {
> > err = -EIO;
> > --
> > 2.34.1
> >
> >
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-11-26 10:22 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-23 14:44 [PATCH] IB/iser: Fix deadlock during blocking connect Ziyu Zhang
2026-11-23 15:02 ` sashiko-bot
2026-11-26 9:23 ` Leon Romanovsky
2026-11-26 10:22 ` ziyu zhang
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox