mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Andrew Stellman <bugs@stellman-greene.com>
To: Jason Gunthorpe <jgg@ziepe.ca>, Leon Romanovsky <leon@kernel.org>
Cc: Bernard Metzler <bernard.metzler@linux.dev>,
	linux-rdma@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH rdma-rc] RDMA/iwcm: Handle CLOSE before passive establishment
Date: Sat, 28 Nov 2026 19:17:45 -0500	[thread overview]
Message-ID: <20261129001745.78689-1-bugs@stellman-greene.com> (raw)

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


                 reply	other threads:[~2026-11-29  0:17 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261129001745.78689-1-bugs@stellman-greene.com \
    --to=bugs@stellman-greene.com \
    --cc=bernard.metzler@linux.dev \
    --cc=jgg@ziepe.ca \
    --cc=leon@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-rdma@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®