From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.160.176 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796234028; b=siasJaO1SM7dMKjxil8gQKdt04QK5+3mF2QUyhtircrUDqjSPaOasXT1J55PKBrP83oi FmiiFNnTyKLawt+k6wpRhCvDqbWgvGMYva25LciFYRR5PlvweF0O9PTh8/S6N6QL3nDIo gNwnJXVsidQJs+uWlC79A0DuCkcemV77XgnOqVfk76qlBK9vZ4AKdiYu5FN79T+4H/t7/ +gDN9IWLW9ThsFBAcPhG2W3ItJVLKjaC9dJILGprdj8YHtvxQEaRmOmVbWedZPt1SgJah 44FjD651wRyVb2yiaqmMc6cxf78qiIckZ7seX20XTDHjXnaJUO1L35RjE/3q1BtKLcQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796234028; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:To:Cc:Subject:Date:Message-ID:X-Mailer:MIME-Version: Content-Transfer-Encoding; bh=LhThSFLCFVPYEDStsUF46dh/abfuAWyq5KSraMtBEAU=; b=12MA1e7aGy/qlL9XuyOOyRP01w6xRF3/fdlVam4crH46w6FwSn1koG5fDMskOi0RPsAY RlfwsB1wLjGY8B7/td3mw/PXEfCSF3Ydyn5kQwRbeQbaDMgDkR9td5dgiVF4NPChPDjQm qUYYPQh5MFkMjuf40QNX1rzKBJfApC2O/oHdzHmmsd8ejUkclAfHiDOvlKwWI985VynuZ p5Wf/lo91Acpu6QJOyWCnk6c+WgSnYb8XNx3gbUf3pVFk9prT2hB5jTEIrhYqan3yHEXU kUzOoj2krKyzraLtDR/5UuDwXkl5kRoPmBcnqyAZp0wKxp/gH7uG9/Kjt1JCzwU6FMA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none header.from=stellman-greene.com; spf=none smtp.mailfrom=stellman-greene.com; dkim=pass header.d=stellman-greene-com.20260707.gappssmtp.com header.i=@stellman-greene-com.20260707.gappssmtp.com header.a=rsa-sha256 header.s=20260707 header.b=YO+YviZ4; arc=none smtp.remote-ip=209.85.160.176 Received: from mail-qt1-f176.google.com (mail-qt1-f176.google.com [209.85.160.176]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 14EA6606A322 for ; Wed, 2 Dec 2026 17:53:47 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 14EA6606A322 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=stellman-greene.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=stellman-greene.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=stellman-greene-com.20260707.gappssmtp.com header.i=@stellman-greene-com.20260707.gappssmtp.com header.a=rsa-sha256 header.s=20260707 header.b=YO+YviZ4 Received: by mail-qt1-f176.google.com with SMTP id d75a77b69052e-5366ae57896so134723241cf.3 for ; Wed, 02 Dec 2026 09:53:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=stellman-greene-com.20260707.gappssmtp.com; s=20260707; t=1796234027; x=1796838827; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to:content-type; bh=LhThSFLCFVPYEDStsUF46dh/abfuAWyq5KSraMtBEAU=; b=YO+YviZ4bgbLnQvSj7rde72+btERg43KzQ9YY988QV7c//CQv1IvogFkim6WdeFlsP S3JRHc0qUG2zr4poBNU+yoxYTIROkcEDeE8t5nYunWkHyDNsCtmQqLb0tcZkVIfwAGLL ngtw2Ts1UuyqD3RhMQAbhJu2ob67ZdDolbC4pScLiWUI8jxMD7oa1usmCJ+L5JZf+JYb ohHq/0b/8HR4kjg0ZLpfuCL5PUTuwFUW4P9iVOngMGHEStI5V1BTJMa0H9NKSHuTRknJ BbZBCIoQGi1O03DwhrUI7xCMDjS4Wd3Monea34HVlNlnV3ugQG5M/YQQfaQYZCm6NI7q 8oGg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796234027; x=1796838827; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=LhThSFLCFVPYEDStsUF46dh/abfuAWyq5KSraMtBEAU=; b=Alz7IDmZzqr5TXMDrLr0hDs4Q/VENCB6roNGksn0wJfbW98oaCGwhT7UXxXByRxYva d/EHWr+JnlcHFhy00oCgLCLJ2exrFFxas3WghgbUgWEpszehEgFQ0xuD61luQbVqwtn1 mdouySSOv1UtAMnyYHaTd7iC2m1jw9mB1Bi8jkDwv+zpA+9fTqDQAJGDnnyYtz6cPY9g uhHUfl5qNEqnC2LfIKZD/+fnd0GCfkmpyo22oJukWObh1qhGji0EKM9J7UAmUeFi5U8l Grfia8lMVX6aSU1EPYIWEuv3BBieDvxpnJt2V1IKooxahiYZTQYuaPGY/nhpFKNXi8Nr eDBQ== X-Forwarded-Encrypted: i=1; AL+hErG15H5GCSllSCurtY3ZnU0vJQXzf2fZDwm1KXtM+RqzA6AP1f55TpK3sgFimMES8BL+gbLwcSpLplLVfPQ=@vger.kernel.org X-Gm-Message-State: APuU4Z9X1sbtyp3oBP3Gpan4ePUAWxIk3jpES9wKzaZBBwQ152HAM+VA a6qRCeuQhat0xC/cJ6B7wDKDj9bX92ikTyWKfFz+yFW8kGfvUJe+a+urt/tOjcd0KEamXfjLbYB GwlSWE1o= X-Gm-Gg: AZFdTZcO0vHbBDfrUucdUKy/r4jNe4tMpbS1u3kqMUXJXxi8j5M2w9jj8SojWiIezJK IIkQ9tsZKh1Pc1qtWQs/BYOGPEuppAZHclnBi+7pRmKJuUWW4SNd8E9d5d4sXcoTnwK5tUGd2QA ci0yAqIjloPziQ68cIoe3LcAGHjV3j0OOd1myp8gA3fF0BhXFh5ZijB6Vqf7xsolCeofwrMA2XP B3jvbPbtIW22pLjoAB7yEGPZszTSS69a0fyeXQh1f1Ij5KI76u6vamRAc4PqJheatjN22zKxwyh lG2dKrbKTOSogaxnW8sEewoO7eRgef9S7+TKHt2zL38fOEpmKntCcjYTEExfVegvDiTDlxL5k1i IXW22jvoWuu3mgk0sERQDIINMNAoWxFVrb176kNj/1QsPXNwJ7AiXCAU5PtBru+W0tpPUItHOmt bpNPr3sQCEUOrWX7MxSTXK012iir4pLuxX/iRh+bYzAah83DPP+JYwFM5tfoP85dgh3j/HFud6y dzs2hSb2RYb7aTixj4GWwXzwLfpnEvsbst9Fb+q7rWrxNBXY/vS7qMK4j3meW1brNto4Oa/72aW RORwHf8k66v/V7SrB6en+2CYeJrMQELRkuW06xJdJ5EorXHA0ub3qqgVtXRX7fnujcgn04+fNpf xHCDSWFq166pRdclzTs8xAw== X-Received: by 2002:ac8:6906:0:b0:53f:8b7e:c0e with SMTP id d75a77b69052e-55d76a27fabmr694221261cf.24.1796234026922; Wed, 02 Dec 2026 09:53:46 -0800 (PST) Received: from Mac.mynetworksettings.com ([2600:4041:5c28:200:9fd:9761:5b78:f32c]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-55d7887b610sm337047781cf.23.2026.12.02.09.53.46 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Wed, 02 Dec 2026 09:53:46 -0800 (PST) From: Andrew Stellman To: Jason Gunthorpe , Leon Romanovsky Cc: Bernard Metzler , linux-rdma@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v4 rdma-rc] RDMA/iwcm: Handle CLOSE before passive establishment Date: Wed, 2 Dec 2026 12:53:45 -0500 Message-ID: <20261202175345.70627-1-bugs@stellman-greene.com> X-Mailer: git-send-email 2.53.0 X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Andrew Stellman An accepted siw MPA v2 connection enters RDMA mode before it receives the peer's RTR frame. If that frame is malformed, siw reports CLOSE while the passive IWCM ID is still in CONN_RECV, and cm_close_handler() hits the BUG() for unexpected states: [ 4.767386] ------------[ cut here ]------------ [ 4.767396] kernel BUG at drivers/infiniband/core/iwcm.c:966! [ 4.767406] Internal error: Oops - BUG: 00000000f2000800 [#1] SMP [ 4.770343] Modules linked in: [ 4.770836] CPU: 0 UID: 0 PID: 60 Comm: kworker/u32:1 Not tainted 7.4.0-rc4-gf93eb7cfc4bf #14 PREEMPT(full) [ 4.771994] Hardware name: linux,dummy-virt (DT) [ 4.773423] Workqueue: iw_cm_wq cm_work_handler [ 4.774044] pstate: 814000c5 (Nzcv daIF +PAN -UAO -TCO +DIT -SSBS BTYPE=--) [ 4.774971] pc : cm_work_handler+0xf40/0x1098 [ 4.775547] lr : cm_work_handler+0x240/0x1098 [ 4.776080] sp : ffff800080ac79b0 [ 4.776589] x29: ffff800080ac7b60 x28: ffff0000e8473600 x27: ffff0000e6d87a98 [ 4.777487] x26: 0000000000000000 x25: ffff0000e8473948 x24: ffff0000e6d87800 [ 4.778315] x23: ffff0000e8473548 x22: ffff0000e83af000 x21: ffff0000e6d87a90 [ 4.779282] x20: 1ffff00010158f38 x19: ffff0000e6d87800 x18: ffff0000c8726f78 [ 4.780155] x17: ffffd479c0827da0 x16: ffffd479c2b66c44 x15: 0000000000000000 [ 4.784111] x14: 0000000000000000 x13: 0000000000000000 x12: ffff700010158f27 [ 4.784937] x11: 1ffff00010158f26 x10: ffff700010158f26 x9 : dfff800000000000 [ 4.785840] x8 : 0000000000000003 x7 : 0000000000000001 x6 : ffff700010158f26 [ 4.786664] x5 : ffff800080ac7930 x4 : 1fffe0001cdb0f48 x3 : 0000000000000003 [ 4.787577] x2 : 0000000000000000 x1 : 0000000000000000 x0 : 0000000000000002 [ 4.788589] Call trace: [ 4.789495] cm_work_handler+0xf40/0x1098 (P) [ 4.790774] process_one_work+0x5f0/0xcb8 [ 4.791270] worker_thread+0x3ac/0xaa0 [ 4.791781] kthread+0x36c/0x420 [ 4.792361] ret_from_fork+0x10/0x20 [ 4.792811] Code: 978e5ca5 17ffff33 978e5c73 17fffefa (d4210000) [ 4.793544] ---[ end trace 0000000000000000 ]--- Handle CLOSE in CONN_RECV as a failed connection: move the ID to IDLE, clear the connect wait flag, report -ECONNRESET if the provider gave status zero, and wake any waiters. Also ignore an ESTABLISHED event that arrives after CLOSE or a destroy has already moved the ID to IDLE or DESTROYING. Fixes: 6c52fdc244b5 ("rdma/siw: connection management") Signed-off-by: Andrew Stellman --- Leon, here's v4 as a new thread with the full trace, like you asked. Here's what this patch is about. cm_close_handler() only expects CLOSE after the connection is established. When the peer sends a malformed RTR frame, siw reports CLOSE while the passive ID is still in CONN_RECV, and that lands in the BUG(). I didn't fix it in siw, because if siw reported ESTABLISHED with an error status instead, cm_conn_est_handler() would still move the ID to ESTABLISHED and the CMA would deliver RDMA_CM_EVENT_ESTABLISHED. The change in cm_conn_est_handler() is for an ESTABLISHED event that's already queued when CLOSE gets there first. It then arrives after the ID is IDLE or DESTROYING. I only saw that ordering with test-only delays in siw and IWCM. Like in my last patch, to be 100% transparent about AI use: OpenAI GPT-6 (Codex) found this while it was reproducing a different siw bug that my Quality Playbook skill (https://github.com/andrewstellman/quality-playbook) turned up, and GPT-6 drafted the fix. I used Claude Opus 5.5 to help me read the BUG() report and the code, and to help me write this up. For the red-green test, the malformed RTR hit the BUG() above without the patch. With it, the server got RDMA_CM_EVENT_DISCONNECTED with status -104 and no BUG(). A valid RTR still got ESTABLISHED then DISCONNECTED, and rping finished three exchanges. I tested it on mainline ca20d5a011d3 (7.4.0-rc4) in arm64 QEMU with KASAN, with the peer running as uid 1000 and no capabilities. The unpatched BUG() above was at f93eb7cfc4bf. v4: no code change from v3; new thread, full trace, new description. v3: https://lore.kernel.org/r/20261130044601.28226-1-bugs@stellman-greene.com v2: https://lore.kernel.org/r/20261129135257.80754-1-bugs@stellman-greene.com v1: https://lore.kernel.org/r/20261129001745.78689-1-bugs@stellman-greene.com A reproducer is available on request. drivers/infiniband/core/iwcm.c | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/drivers/infiniband/core/iwcm.c b/drivers/infiniband/core/iwcm.c index 4b05867dad895..e03e97cd98c8b 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,12 @@ 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 || + cm_id_priv->state == IW_CM_STATE_DESTROYING) { + /* CLOSE or destroy 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 +957,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 +969,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 +989,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