From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.230.203 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795960381; b=M8yTZRC1CZ22Ix4RKNnm4RdjxuJ/m+DFbz2P3mMkdtTtVF2Mw3ydHDfZsh/V9l7HC+kv UkU7cEqMp9Ps9usFCLV8wqDJqwxhgwPJ6BWxt+BDfpBhGeD/NlrT8mHGPeXjvIy392svc 0U6e5d+mVdUch6TsyMV1vQ0eWIHGx5D5sigfv93F8fOUjJbxnhIEPRNg5oimltGcRDaf/ KaM7ee7YUmaLnFplpWy83EqXIbgJl8Qyb0yn+yHCjEhqT7541wjIVqqtmpPsxCaLNtdhb PJgfumXTEtFyWjdUWJEyUi1OyQN6vJEyD6RJqVG19WSRB/u1Jdc6rZvj7ngDomX9gWw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795960381; 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=eFw7wtKFuSCeCM7x5czVl7Ww0ixXCeLKjedp6ltK+N8BhgtPCRuDPlUYJB3sc3R22eVR mA79ABXpmlE9gE4E+h3zHwd8uRe17qAc3Ho6mxpJ+t7r0ZaqDyFEyy5NfyjvJPKUnmgvw rDtHG74lyDNCnjnsp+7y+SS/91/SK6so8zKmvIafE9DVL/w/7/BrDlDy8cOj6qsIHT1S0 QjuDxWxBH7HvY9/ezH3+4xdxlwESbOQj+pTGgZ6m/L+O3fMp5cEe+QrF5pNgOlrhKUj8K JzsdzoygJitPeGkBa1ELE4hV38vBW9asKiVhhSh/LORwVeF0uXytHoIBJOGfKj41JEQ== 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.203 Received: from mail-qk2-f11.google.com (mail-qk2-f11.google.com [74.125.230.203]) (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 82737606A323 for ; Sun, 29 Nov 2026 13:53:00 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 82737606A323 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) 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-f11.google.com with SMTP id d75a77b69052e-5364605e711so26530131cf.0 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=n2uLxozXKjC3rNQIUO/PiQGAg2DI03uJWljE09GHZlhhsRhp06aerI4owb2T7dcfcC ga7gOckfzyxsKvWkRTCJF6He8d3U4QQR8LrgyHyNQkUCX3q2CfAyxvRAV4pi81RZS+u3 lvseURKuluOCOsqNKwHKJv08EQ1rmlDd459RQ7yL7yd1XlS/VdYnCoHpA4DuOKOX9Y0q rGrwW0LIPr4wydpMtKHolCwWncfVwn/W5lqTvi/BseD83iYC2OPmVww2t/PpW6492MtJ atBCxhu/rXOAdDvOvqGfnV5n66DPzOLJf7g5gXgXUXcwmE0FGpKlBiJjFfcKl7oJqjG5 clmw== X-Forwarded-Encrypted: i=1; AL+hErEgegbVVcmFNHqo0r6vARw7tvkxKHRhfntcTyfsLpiVnFfTNQQLcO13tSdfBNC1vBnWhSbg4ywbsflk@vger.kernel.org X-Gm-Message-State: APuU4Z/vhYEjkXjPjXddFZq5kTLUsylT/D7NWvYhiZx3k0mi0ddA1Mwm AzzcGHa0ck2v1m7d7KfgT+DiWUs1U7HutbFuxWqm74f6nZr8seECbqmsmvmxoHK52wI= X-Gm-Gg: AZFdTZeYY5esiMBP8zPR2m89s/i0R2utFGBNHiQwUiDihYZTQDLbPlEGOuixmZ8PyF/ Jzv8mDn3rJyJ2317oG98r5FnLfmMf3jahudytwRw+8hFDRwrf2AtKCD8lHn1oHnarC1QsqY1bfq 03wyWdFvmKQRwmn6qxvhpQB6D4+1LxeN0fcEhiZNsZfyQDN1pVx0iJuGUTmh10Ie6WaF2sYeBEX CQZDSL+65GBnwKDdXq+cEgkxoOFeSSypXy5LDAW+b7C8LOCm3DCK85g9jD5DtsAGitjy6sljeRj IyBxDAW8+ct1MgwECJBb8KfIvXAAi9RX8N4p8LrX+XSkhsloG0GSlqiGqgcvZHPEIL6Zzd07t15 Dx+6820JQFQ8TNACN/xLjJhYAr7bY0rojaIFTuxXbFAwn9cDyq8gIPK0s2tEw+C61Bk9qxU84I5 LtYtj4+A9SdzS5+pLGBiMNQi9Qv538bQs5zPqGNQysITQNGT4XtzvBLqWBAJvotui+VX3ge0MPY rChGK03UWuDNx5nrtMX55LZPWEXGtVm4fdlLR6hkNsV7UYVaWuuVdQNMJdC67t3WraoYXJXeZTq YAAvI7RfrseG/AnBatjVE87M/CZdVJP3JKPi+gOYZQQ25lEO0wDVxhK5ZZqD/2mbb1gwQTxwsEK 8MA== 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-rdma@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