* [PATCH rdma-rc] RDMA/iwcm: Handle CLOSE before passive establishment
@ 2026-11-29 0:17 Andrew Stellman
2026-11-29 0:37 ` sashiko-bot
2026-11-29 13:52 ` [PATCH v2 " Andrew Stellman
0 siblings, 2 replies; 4+ messages in thread
From: Andrew Stellman @ 2026-11-29 0:17 UTC (permalink / raw)
To: Jason Gunthorpe, Leon Romanovsky
Cc: Bernard Metzler, linux-rdma, linux-kernel
From: Andrew Stellman <astellman@stellman-greene.com>
An accepted siw MPA v2 connection enters RDMA mode before receiving the
peer's RTR frame. If the peer resets TCP or sends a malformed RTR frame,
siw reports CLOSE while the passive IWCM ID is still in CONN_RECV.
cm_close_handler() treats that state as impossible and hits BUG():
kernel BUG at drivers/infiniband/core/iwcm.c:966!
Internal error: Oops - BUG: 00000000f2000800 [#1] SMP
Workqueue: iw_cm_wq cm_work_handler
pc : cm_work_handler+0xf40/0x1098
Call trace:
cm_work_handler+0xf40/0x1098 (P)
process_one_work+0x5f0/0xcb8
worker_thread+0x3ac/0xaa0
kthread+0x36c/0x420
ret_from_fork+0x10/0x20
The fix belongs in the IWCM core rather than siw, because siw can't
report this as ESTABLISHED with an error status: cm_conn_est_handler()
moves CONN_RECV to ESTABLISHED regardless of status, and the CMA turns
it into RDMA_CM_EVENT_ESTABLISHED.
Handle CLOSE in CONN_RECV as a failed passive connection. Move the ID to
IDLE, clear the connect wait flag, notify the consumer with
-ECONNRESET if the provider gave status zero, and wake waiters. The
existing exit path drops the QP reference. The consumer now gets a
disconnect event for this case instead of the BUG().
Tested in QEMU (arm64) on mainline as of 2026-11-28 with KASAN. A peer
running as uid 1000 with no capabilities that sent a malformed RTR
frame, or reset TCP after the MPA reply, hit the BUG() without the
patch. With the patch, the server got RDMA_CM_EVENT_DISCONNECTED with
status -104 and no BUG(). rping and a valid RTR connection behaved the
same with and without the patch.
The issue was found by OpenAI GPT-6 (Codex) while reproducing another
siw bug. The fix was drafted with OpenAI GPT-6 (Codex) and this
changelog with Claude Opus 5.5, and both were reviewed by me.
Fixes: 6c52fdc244b5 ("rdma/siw: connection management")
Signed-off-by: Andrew Stellman <astellman@stellman-greene.com>
---
A reproducer is available on request.
drivers/infiniband/core/iwcm.c | 20 +++++++++++++++++---
1 file changed, 17 insertions(+), 3 deletions(-)
diff --git a/drivers/infiniband/core/iwcm.c b/drivers/infiniband/core/iwcm.c
index 4b05867dad895a..60579e2a0999a3 100644
--- a/drivers/infiniband/core/iwcm.c
+++ b/drivers/infiniband/core/iwcm.c
@@ -843,9 +843,10 @@ static void cm_conn_req_handler(struct iwcm_id_private *listen_id_priv,
* FPDU mode.
*
* This event can only be received in the CONN_RECV state. If the
- * remote peer closed, the ESTABLISHED event would be received followed
- * by the CLOSE event. If the app closes, it will block until we wake
- * it up after processing this event.
+ * remote peer closes after establishment, ESTABLISHED is followed by
+ * CLOSE. If it closes before establishment, CLOSE can arrive first.
+ * If the app closes, it will block until we wake it up after processing
+ * this event.
*/
static int cm_conn_est_handler(struct iwcm_id_private *cm_id_priv,
struct iw_cm_event *iw_event)
@@ -950,6 +951,8 @@ static int cm_close_handler(struct iwcm_id_private *cm_id_priv,
struct ib_qp *qp;
unsigned long flags;
int ret = 0, notify_event = 0;
+ bool wake_connect = false;
+
spin_lock_irqsave(&cm_id_priv->lock, flags);
qp = cm_id_priv->qp;
cm_id_priv->qp = NULL;
@@ -960,6 +963,15 @@ static int cm_close_handler(struct iwcm_id_private *cm_id_priv,
cm_id_priv->state = IW_CM_STATE_IDLE;
notify_event = 1;
break;
+ case IW_CM_STATE_CONN_RECV:
+ /* The accepted connection closed before establishment. */
+ cm_id_priv->state = IW_CM_STATE_IDLE;
+ clear_bit(IWCM_F_CONNECT_WAIT, &cm_id_priv->flags);
+ if (!iw_event->status)
+ iw_event->status = -ECONNRESET;
+ notify_event = 1;
+ wake_connect = true;
+ break;
case IW_CM_STATE_DESTROYING:
break;
default:
@@ -971,6 +983,8 @@ static int cm_close_handler(struct iwcm_id_private *cm_id_priv,
cm_id_priv->id.device->ops.iw_rem_ref(qp);
if (notify_event)
ret = cm_id_priv->id.cm_handler(&cm_id_priv->id, iw_event);
+ if (wake_connect)
+ wake_up_all(&cm_id_priv->connect_wait);
return ret;
}
--
2.53.0
^ permalink raw reply related [flat|nested] 4+ messages in thread* Re: [PATCH rdma-rc] RDMA/iwcm: Handle CLOSE before passive establishment
2026-11-29 0:17 [PATCH rdma-rc] RDMA/iwcm: Handle CLOSE before passive establishment Andrew Stellman
@ 2026-11-29 0:37 ` sashiko-bot
2026-11-29 13:52 ` [PATCH v2 " Andrew Stellman
1 sibling, 0 replies; 4+ messages in thread
From: sashiko-bot @ 2026-11-29 0:37 UTC (permalink / raw)
To: Andrew Stellman; +Cc: linux-rdma
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [High] RDMA/iwcm: BUG_ON() in cm_conn_est_handler() when CLOSE
precedes ESTABLISHED
--
commit 987e45dea45deac1e061d0f23777d7b22f32b888
Author: Andrew Stellman <astellman@stellman-greene.com>
RDMA/iwcm: Handle CLOSE before passive establishment
This commit updates cm_close_handler() to handle IW_CM_EVENT_CLOSE while an
accepted passive IWCM ID is still in IW_CM_STATE_CONN_RECV, transitioning it
to IW_CM_STATE_IDLE and notifying the consumer.
> diff --git a/drivers/infiniband/core/iwcm.c b/drivers/infiniband/core/iwcm.c
> index 94a92434063ae..554cef2469aac 100644
> --- a/drivers/infiniband/core/iwcm.c
> +++ b/drivers/infiniband/core/iwcm.c
> @@ -867,9 +867,10 @@ static void cm_conn_req_handler(struct iwcm_id_private *listen_id_priv,
> * FPDU mode.
> *
> * This event can only be received in the CONN_RECV state. If the
> - * remote peer closed, the ESTABLISHED event would be received followed
> - * by the CLOSE event. If the app closes, it will block until we wake
> - * it up after processing this event.
> + * remote peer closes after establishment, ESTABLISHED is followed by
> + * CLOSE. If it closes before establishment, CLOSE can arrive first.
> + * If the app closes, it will block until we wake it up after processing
> + * this event.
> */
> static int cm_conn_est_handler(struct iwcm_id_private *cm_id_priv,
> struct iw_cm_event *iw_event)
> @@ -974,6 +975,8 @@ static int cm_close_handler(struct iwcm_id_private *cm_id_priv,
> struct ib_qp *qp;
> unsigned long flags;
> int ret = 0, notify_event = 0;
> + bool wake_connect = false;
> +
> spin_lock_irqsave(&cm_id_priv->lock, flags);
> qp = cm_id_priv->qp;
> cm_id_priv->qp = NULL;
> @@ -984,6 +987,15 @@ static int cm_close_handler(struct iwcm_id_private *cm_id_priv,
> cm_id_priv->state = IW_CM_STATE_IDLE;
> notify_event = 1;
> break;
> + case IW_CM_STATE_CONN_RECV:
> + /* The accepted connection closed before establishment. */
> + cm_id_priv->state = IW_CM_STATE_IDLE;
> + clear_bit(IWCM_F_CONNECT_WAIT, &cm_id_priv->flags);
> + if (!iw_event->status)
> + iw_event->status = -ECONNRESET;
> + notify_event = 1;
> + wake_connect = true;
> + break;
[Severity: High]
Can cm_conn_est_handler() hit BUG_ON(cm_id_priv->state !=
IW_CM_STATE_CONN_RECV) if IW_CM_EVENT_CLOSE is queued before
IW_CM_EVENT_ESTABLISHED?
When a peer sends a TCP packet with FIN (such as an MPA v2 RTR frame with
TCPHDR_FIN), tcp_data_queue() runs tcp_fin() before tcp_data_ready(). In
siw, siw_cm_llp_state_change() queues SIW_CM_WORK_PEER_CLOSE without setting
qp->rx_stream.rx_suspend, while siw_rtr_data_ready() runs without
siw_cep_set_inuse() and queues IW_CM_EVENT_ESTABLISHED if rx_suspend is
still zero:
<softirq> siw_cm_wq / iw_cm_wq
tcp_data_queue()
tcp_fin()
siw_cm_llp_state_change()
siw_cm_queue_work(...,
SIW_CM_WORK_PEER_CLOSE)
siw_cm_work_handler()
siw_cm_upcall(..., IW_CM_EVENT_CLOSE)
tcp_data_ready()
siw_rtr_data_ready()
if (!qp->rx_stream.rx_suspend)
siw_cm_upcall(...,
IW_CM_EVENT_ESTABLISHED)
cm_close_handler()
cm_id_priv->state = IW_CM_STATE_IDLE
cm_conn_est_handler()
BUG_ON(cm_id_priv->state !=
IW_CM_STATE_CONN_RECV) <-- BUG()
Since cm_close_handler() now transitions cm_id_priv->state from
IW_CM_STATE_CONN_RECV to IW_CM_STATE_IDLE without crashing, a subsequent
IW_CM_EVENT_ESTABLISHED reaches cm_conn_est_handler() in IW_CM_STATE_IDLE
(when the consumer callback does not destroy the cm_id on disconnect) and
triggers the BUG_ON().
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261129001745.78689-1-bugs@stellman-greene.com?part=1
^ permalink raw reply [flat|nested] 4+ messages in thread* [PATCH v2 rdma-rc] RDMA/iwcm: Handle CLOSE before passive establishment
2026-11-29 0:17 [PATCH rdma-rc] RDMA/iwcm: Handle CLOSE before passive establishment Andrew Stellman
2026-11-29 0:37 ` sashiko-bot
@ 2026-11-29 13:52 ` Andrew Stellman
2026-11-29 14:07 ` sashiko-bot
1 sibling, 1 reply; 4+ messages in thread
From: Andrew Stellman @ 2026-11-29 13:52 UTC (permalink / raw)
To: Jason Gunthorpe, Leon Romanovsky
Cc: Bernard Metzler, linux-rdma, linux-kernel
From: Andrew Stellman <astellman@stellman-greene.com>
An accepted siw MPA v2 connection enters RDMA mode before receiving the
peer's RTR frame. If the peer sends a malformed RTR frame, siw reports
CLOSE while the passive IWCM ID is still in CONN_RECV.
cm_close_handler() treats that state as impossible and hits BUG():
kernel BUG at drivers/infiniband/core/iwcm.c:966!
Internal error: Oops - BUG: 00000000f2000800 [#1] SMP
Workqueue: iw_cm_wq cm_work_handler
pc : cm_work_handler+0xf40/0x1098
Call trace:
cm_work_handler+0xf40/0x1098 (P)
process_one_work+0x5f0/0xcb8
worker_thread+0x3ac/0xaa0
kthread+0x36c/0x420
ret_from_fork+0x10/0x20
The fix belongs in the IWCM core rather than siw, because siw can't
report this as ESTABLISHED with an error status: cm_conn_est_handler()
moves CONN_RECV to ESTABLISHED regardless of status, and the CMA turns
it into RDMA_CM_EVENT_ESTABLISHED.
Handle CLOSE in CONN_RECV as a failed passive connection. Move the ID to
IDLE, clear the connect wait flag, notify the consumer with
-ECONNRESET if the provider gave status zero, and wake waiters. The
existing exit path drops the QP reference. The consumer now gets a
disconnect event for this case instead of the BUG().
If the peer sends its RTR frame and then FIN, siw can queue CLOSE before
ESTABLISHED. After CLOSE has moved the ID to IDLE, ESTABLISHED would hit
the BUG_ON() in cm_conn_est_handler(), so ignore ESTABLISHED in IDLE.
ESTABLISHED in CONN_RECV is handled as before.
Tested in QEMU (arm64) on mainline 7.4.0-rc4 with KASAN. A peer
running as uid 1000 with no capabilities that sent a malformed RTR
frame hit the BUG() without the patch. With the patch, the server got
RDMA_CM_EVENT_DISCONNECTED with status -104 and no BUG(). rping and a
valid RTR connection behaved the same with and without the patch.
The RTR-then-FIN ordering only occurred with test-only delays added to
siw (50 ms after it queues PEER_CLOSE, 100 ms after its CLOSE upcall).
With those delays, a peer that sent a zero-length RTR frame and then
shut down its socket hit the BUG_ON() in cm_conn_est_handler() with v1
of this patch. With this version, the server got
RDMA_CM_EVENT_DISCONNECTED with status -104 and no BUG. Without the
delays, one run with v1 and one with this version got ESTABLISHED
before CLOSE.
The issue was found by OpenAI GPT-6 (Codex) while reproducing another
siw bug. The fix was drafted with OpenAI GPT-6 (Codex) and this
changelog with Claude Opus 5.5, and both were reviewed by me.
Fixes: 6c52fdc244b5 ("rdma/siw: connection management")
Signed-off-by: Andrew Stellman <astellman@stellman-greene.com>
---
v2: Ignore ESTABLISHED after CLOSE has moved the ID to IDLE. Sashiko
reported this ordering in its review of v1:
https://lore.kernel.org/linux-rdma/20261129001745.78689-1-bugs@stellman-greene.com/
Dropped the TCP reset case from the testing note, since it wasn't
retested on v2.
Tested at mainline f93eb7cfc4bf (7.4.0-rc4).
A reproducer is available on request.
drivers/infiniband/core/iwcm.c | 25 ++++++++++++++++++++++---
1 file changed, 22 insertions(+), 3 deletions(-)
diff --git a/drivers/infiniband/core/iwcm.c b/drivers/infiniband/core/iwcm.c
index 4b05867dad895..71929fb71f301 100644
--- a/drivers/infiniband/core/iwcm.c
+++ b/drivers/infiniband/core/iwcm.c
@@ -843,9 +843,10 @@ static void cm_conn_req_handler(struct iwcm_id_private *listen_id_priv,
* FPDU mode.
*
* This event can only be received in the CONN_RECV state. If the
- * remote peer closed, the ESTABLISHED event would be received followed
- * by the CLOSE event. If the app closes, it will block until we wake
- * it up after processing this event.
+ * remote peer closes after establishment, ESTABLISHED is followed by
+ * CLOSE. If it closes before establishment, CLOSE can arrive first.
+ * If the app closes, it will block until we wake it up after processing
+ * this event.
*/
static int cm_conn_est_handler(struct iwcm_id_private *cm_id_priv,
struct iw_cm_event *iw_event)
@@ -861,6 +862,11 @@ static int cm_conn_est_handler(struct iwcm_id_private *cm_id_priv,
* from a callback handler is not allowed.
*/
clear_bit(IWCM_F_CONNECT_WAIT, &cm_id_priv->flags);
+ if (cm_id_priv->state == IW_CM_STATE_IDLE) {
+ /* CLOSE won the race with passive establishment. */
+ spin_unlock_irqrestore(&cm_id_priv->lock, flags);
+ return 0;
+ }
BUG_ON(cm_id_priv->state != IW_CM_STATE_CONN_RECV);
cm_id_priv->state = IW_CM_STATE_ESTABLISHED;
spin_unlock_irqrestore(&cm_id_priv->lock, flags);
@@ -950,6 +956,8 @@ static int cm_close_handler(struct iwcm_id_private *cm_id_priv,
struct ib_qp *qp;
unsigned long flags;
int ret = 0, notify_event = 0;
+ bool wake_connect = false;
+
spin_lock_irqsave(&cm_id_priv->lock, flags);
qp = cm_id_priv->qp;
cm_id_priv->qp = NULL;
@@ -960,6 +968,15 @@ static int cm_close_handler(struct iwcm_id_private *cm_id_priv,
cm_id_priv->state = IW_CM_STATE_IDLE;
notify_event = 1;
break;
+ case IW_CM_STATE_CONN_RECV:
+ /* The accepted connection closed before establishment. */
+ cm_id_priv->state = IW_CM_STATE_IDLE;
+ clear_bit(IWCM_F_CONNECT_WAIT, &cm_id_priv->flags);
+ if (!iw_event->status)
+ iw_event->status = -ECONNRESET;
+ notify_event = 1;
+ wake_connect = true;
+ break;
case IW_CM_STATE_DESTROYING:
break;
default:
@@ -971,6 +988,8 @@ static int cm_close_handler(struct iwcm_id_private *cm_id_priv,
cm_id_priv->id.device->ops.iw_rem_ref(qp);
if (notify_event)
ret = cm_id_priv->id.cm_handler(&cm_id_priv->id, iw_event);
+ if (wake_connect)
+ wake_up_all(&cm_id_priv->connect_wait);
return ret;
}
--
2.53.0
^ permalink raw reply related [flat|nested] 4+ messages in thread* Re: [PATCH v2 rdma-rc] RDMA/iwcm: Handle CLOSE before passive establishment
2026-11-29 13:52 ` [PATCH v2 " Andrew Stellman
@ 2026-11-29 14:07 ` sashiko-bot
0 siblings, 0 replies; 4+ messages in thread
From: sashiko-bot @ 2026-11-29 14:07 UTC (permalink / raw)
To: Andrew Stellman; +Cc: linux-rdma
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [High] RDMA/iwcm: BUG_ON() in cm_conn_est_handler() on race with
destroy_cm_id()
--
commit ca6826a9ffc5ebdff07e4969c6a9471c1e22af28
Author: Andrew Stellman <astellman@stellman-greene.com>
RDMA/iwcm: Handle CLOSE before passive establishment
This commit updates cm_close_handler() to handle IW_CM_EVENT_CLOSE while a
passive connection is in IW_CM_STATE_CONN_RECV, and teaches
cm_conn_est_handler() to ignore a subsequent IW_CM_EVENT_ESTABLISHED after
the ID has moved to IW_CM_STATE_IDLE.
> diff --git a/drivers/infiniband/core/iwcm.c b/drivers/infiniband/core/iwcm.c
> index 94a92434063ae..3ce99640f9ae6 100644
> --- a/drivers/infiniband/core/iwcm.c
> +++ b/drivers/infiniband/core/iwcm.c
> @@ -867,9 +867,10 @@ static void cm_conn_req_handler(struct iwcm_id_private *listen_id_priv,
> * FPDU mode.
> *
> * This event can only be received in the CONN_RECV state. If the
> - * remote peer closed, the ESTABLISHED event would be received followed
> - * by the CLOSE event. If the app closes, it will block until we wake
> - * it up after processing this event.
> + * remote peer closes after establishment, ESTABLISHED is followed by
> + * CLOSE. If it closes before establishment, CLOSE can arrive first.
> + * If the app closes, it will block until we wake it up after processing
> + * this event.
> */
> static int cm_conn_est_handler(struct iwcm_id_private *cm_id_priv,
> struct iw_cm_event *iw_event)
> @@ -885,6 +886,11 @@ static int cm_conn_est_handler(struct iwcm_id_private *cm_id_priv,
> * from a callback handler is not allowed.
> */
> clear_bit(IWCM_F_CONNECT_WAIT, &cm_id_priv->flags);
> + if (cm_id_priv->state == IW_CM_STATE_IDLE) {
> + /* CLOSE won the race with passive establishment. */
> + spin_unlock_irqrestore(&cm_id_priv->lock, flags);
> + return 0;
> + }
> BUG_ON(cm_id_priv->state != IW_CM_STATE_CONN_RECV);
[Severity: High]
Can cm_conn_est_handler() still hit BUG_ON() if destroy_cm_id() transitions
cm_id_priv->state from IW_CM_STATE_IDLE to IW_CM_STATE_DESTROYING before the
trailing ESTABLISHED work item takes cm_id_priv->lock?
Previously, IWCM_F_CONNECT_WAIT stayed set until cm_conn_est_handler() ran,
keeping destroy_cm_id() blocked in wait_event(). With cm_close_handler() now
clearing IWCM_F_CONNECT_WAIT and moving cm_id_priv->state to
IW_CM_STATE_IDLE, destroy_cm_id() can proceed while a queued
IW_CM_EVENT_ESTABLISHED work item is already entering cm_work_handler():
CPU0 (iwcm_wq) CPU1
cm_work_handler() [CLOSE]
cm_close_handler()
state = IW_CM_STATE_IDLE
clear_bit(IWCM_F_CONNECT_WAIT)
wake_up_all(&connect_wait)
cm_work_handler() [ESTABLISHED]
!test_bit(IWCM_F_DROP_EVENTS)
destroy_cm_id()
set_bit(IWCM_F_DROP_EVENTS)
spin_lock_irqsave(&lock)
state = IW_CM_STATE_DESTROYING
spin_unlock_irqrestore(&lock)
process_event()
cm_conn_est_handler()
spin_lock_irqsave(&lock)
state == IW_CM_STATE_IDLE (false)
BUG_ON(state != IW_CM_STATE_CONN_RECV) <-- BUG()
Checking for IW_CM_STATE_DESTROYING alongside IW_CM_STATE_IDLE (as
cm_close_handler() does) would avoid this crash.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261129135257.80754-1-bugs@stellman-greene.com?part=1
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-11-29 14:07 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-29 0:17 [PATCH rdma-rc] RDMA/iwcm: Handle CLOSE before passive establishment Andrew Stellman
2026-11-29 0:37 ` sashiko-bot
2026-11-29 13:52 ` [PATCH v2 " Andrew Stellman
2026-11-29 14:07 ` sashiko-bot
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox