From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.230.198 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795960380; b=vqrEpStXScmnaOAya+4AZP23PjcZLtIngWhaya+k3fpOxHOlbHNvB8dR02WavSm/vU97 sF8YGuI3YpbRDkehpHv2KC/fTAS6ibY7Eg0R/BYILDgvc2CT8rZtwe6DBx2uIEHdST+Z2 uW1Bpvg2MYUqBofuHh/DTERksEkd29eOmUfLLb4Wc9IndpWyCDRdj9oOOmescrPALlvgH aFvIeWqNt7BvyjQoi0WoyFdNVCTrlxSPxL9FMo/6WLTYRixkyn6a1qg7ULT7BMfkUcsQ8 TbFqcWmujCtZ8+bFHRJgfx+pWw529YMTsOxZrTISVtbp5/7qB6fWiGyJ5jKpjjkdOlA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795960380; 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:In-Reply-To:References: MIME-Version:Content-Transfer-Encoding; bh=L06l8WqArR/hJ2b7MA0BjgHz+xDgnReUS+VQ4/GGnow=; b=S7OMiwO0ZoEATfk0oHerXcjdnN+bdPFVAWVbMLxQ9Vq9dhb4q3Wv4RFWhFp4SyxD1MvM hhr0PQ3vt+6B61bS5zhexToPG6oeShqK8Sj5FwN/VY1DzjAWYHH4LJW/hSADPAUK/qywh R0Y76W3Tv8cW89jOyIK1aItLLHO+YmlrXmGhB0ypQQzLpmv4tv7YiTQzic5NWovaO/ZGA Zfy8vRpsTmvG8d1J9QFFRtGQiW/2BLg94Fdpt1VWSkx9fqjzarXk3Cx55NJ12ypuWYHmB LCddAS7Fuyv5pc/6RCrvMdenEr3Iy9KiWjQ6VacfA1RxUhwebjq150dQnsi47uZLCig== 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=ENxJVbbf; arc=none smtp.remote-ip=74.125.230.198 Received: from mail-qk2-f6.google.com (mail-qk2-f6.google.com [74.125.230.198]) (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 7D14A606A31C for ; Sun, 29 Nov 2026 13:53:00 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 7D14A606A31C 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=ENxJVbbf Received: by mail-qk2-f6.google.com with SMTP id d75a77b69052e-551d90addacso29244551cf.1 for ; Sun, 29 Nov 2026 05:53:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=stellman-greene-com.20260707.gappssmtp.com; s=20260707; t=1795960379; x=1796565179; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=L06l8WqArR/hJ2b7MA0BjgHz+xDgnReUS+VQ4/GGnow=; b=ENxJVbbfUL8AUsFlF8ECIEtCHz5rHPtqWznzNLGCYiagyLinL8blCXG84WdDjxjIcN E6TIS0SDlDIbRUzCQ7BYDSiBAKdQYcjqC9eqCGzINXSV6d+rRuQRtbMN1p8VRw9o+ee3 bmOKtAakkrlheEf/WU9Q43m9/28B3W4IKsz3iDR0NDcIIOnJaVdgmXW94zjGueS3Gi5X HhHyYnw1yTq/G38hmlmdIP/OuG8XYinyHXtE6aBSZcQn85mjg2mQ7I4mvsV5bI1m7pWs RI163SGfNwZ8+JRuyTv+/7LltsvVSsa4/DJoP/SldeKOnUul3sY5eBB35ZXZJ2jvm18Y msuA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1795960379; x=1796565179; h=content-transfer-encoding:mime-version:references:in-reply-to :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=L06l8WqArR/hJ2b7MA0BjgHz+xDgnReUS+VQ4/GGnow=; b=NfvHDm0n8J+DiWQtIz0QRM89zleBSSdRr7ocgy+LP39ktEhDzKWqlp6QMH4yBLmljn m0P7Ycg71wm8STAoGFxK9E8NHS9mYPvhxKanBKvN0E9Xe6onXtT9/4mivXPHShX0jQ4q fs0h8/S52Jl2qz8O19G1y/L3K2e8/QrWc9cwwAipEPILVa4AEom9FOenHmJoWnVDPmGL piGkLDApAWheAZJRAikxbi7U5oB1frgQpNgDOyZUojBAX7TpOQY+/Z7Cf8JIeF268kwO 5qbRjZKjIfmwH/YJB6QOkQnhn0PXsCHHarV5sTzLaEyM0Rq8GFnCT/4q8yqewgoqI6gN 1/cg== X-Forwarded-Encrypted: i=1; AL+hErHfOetVnyRTiwFqZvJU/OiFzCY5nDckjd3No4CEDHuh/GYG1D1sHTlkGGBKTds+PJTYsLOe+cYwuK9mnwg=@vger.kernel.org X-Gm-Message-State: APuU4Z8tBbVjD0x+88SuMMCgTH/bjrLyeAcUHDRhHmwtf3TB+ji2AGI7 JT1E7RmetvZgNDAVgh+9yiuM+r2PwXBgWVPuv2bZGGa9Zz23lOvlavsA3afy+3Qny4mlajZNkv4 LN7kNf//sQw== X-Gm-Gg: AZFdTZdZ939Cf6Y7VklMBuu56j2Vkx/uOmuCYU5HEGLtOoVMpW++i3kS/mnj6sIy40v MlarLZt7isxTSVvftRo9ThD1U4rUeQcEMWoxwPtXYpQrtVmO3LEGEQd9zgpnsVqDpw6p/5sDpbH Q/7cE/EitgbCZs5dvJuw5yfD88TOTuUfcUpIDgNlTOuww07kTAlsCwJP/X+WN5I01H+GcSoGMqx 8I9T0tERLVgWmzhlzNlZa2lyuyhe65GwE67VQjYGj032Xh7ARXIJzvKYAneboaXZe4JLxkoZbMB H7xPbYvDn5JjrZKb/+uvLlTI2YxFo+Iabzhai2d6TCzQlJ66cnxK+Yp3XdRxh+T7TEav1fXZ4Rv USGkT9efOjXHUEVJTdZVb2vyu/BszOhOFJK5p7LIKf7V+AA++gFiAuhnYoflfM1YFnkzAs6yjfT ZCcAk9cPMKrL2UfLvCODypk+306U1Q66l2ds2V4zKffEq36eC3MES0TrCs5y2YUlrG2DbATECnx atJB1wuX824l7kHUt0sE2SxZxaK/eg2QZ9penvXz9LlDsyoNcVQzPpldx1KhDLzNP/r8iRjxyKn PDysLMnDCgqRkNRBdiRZE78ytESIsQD9nly3NfhZm7Bo0cuiSF9b/DOVE35sdttpnIWCgBV7aGG LaA== X-Received: by 2002:a05:622a:1ba2:b0:55c:d707:598c with SMTP id d75a77b69052e-55d76a5402amr598197761cf.60.1795960379332; Sun, 29 Nov 2026 05:52:59 -0800 (PST) Received: from Mac.mynetworksettings.com ([2600:4041:5c28:200:3c29:a645:a023:b4a7]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-55dc8895beesm79214981cf.11.2026.11.29.05.52.58 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Sun, 29 Nov 2026 05:52:59 -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 v2 rdma-rc] RDMA/iwcm: Handle CLOSE before passive establishment Date: Sun, 29 Nov 2026 08:52:57 -0500 Message-ID: <20261129135257.80754-1-bugs@stellman-greene.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20261129001745.78689-1-bugs@stellman-greene.com> References: <20261129001745.78689-1-bugs@stellman-greene.com> 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 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 --- 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