From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796377771; b=CtIVHK4m6qBoP8mlShI2MmqjmxO+9eRjPeiilDDeiUzdyHubS8u+UeVtXNJZrEfBSxLc ZiSUcf5S0bxMS30KuvEV6X6NygRn4/R35BlvAqL+kFK5jvGmys+h4Upeyzv8C+vTseKWm 3Rk9xglCEfTr51m/l536EwGqox+3XIjdP9UX1K12NFprf6ShTYBMy3ZXCiz2gHF4uXPgK WbWphriP3hthcPaoocqPIlO8eSRgzOvjMyJdxlczrCDxgIqTMzRnrZegE4v3PL4vIQYJ0 rMUuki7lDHvkVdYVzmwqSi/YC3x4BOFmjEk3i0m1BxXtZ7pCAI8YXBmaRXyAldx0XIw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796377771; h=Received:DKIM-Signature:Subject:From:To:Cc:Date:Message-ID: In-Reply-To:References:X-sashiko-severity:Content-Type: Content-Transfer-Encoding:MIME-Version; bh=Oo5gRf39mLwLfxgrcwM2xGC0PSuWnA8r0Fiy6dlOKxM=; b=ffKw5thHCxzaa/rRtYYSCCfMZOTFEPD3wQfF1lojck/0NTVtv6bVvcW3rLxpXK+4cn5B hUaPgLt8oSfvyGGCzLr6Ad3vIz20M3NZghvK2IPOrDI1V49aMlxF24uI6176jcWaWRYP4 FxJJGVaouArrVjvOviz8b0edUnKM4+QIclm2ts0xYRqT1tmmxgdMaDkbetyhX9jQCxsTI /ff7B1dIYgX0hsXlwzARXVAT0kARL8vMQwZB2i8QM9sZq76OmnOkYGTcUxj/EU48EBb7p OhmsInzm/67LfPNMs4mdam2sR8jawAuvxUE6Lj2k1pivzDkzZEYQkTyqCAxftPK3nyA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=hohYBArK; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 29C00606A32F; Fri, 4 Dec 2026 09:49:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=hohYBArK Received: by smtp.kernel.org (Postfix) with ESMTPSA id B68271F000CE; Fri, 4 Dec 2026 09:49:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796377771; bh=Oo5gRf39mLwLfxgrcwM2xGC0PSuWnA8r0Fiy6dlOKxM=; h=Subject:From:To:Cc:Date:In-Reply-To:References; b=hohYBArKWh1QdVarvReKW5WrjEfdWkTwlDgG76S/ZY1AfMzMxONUrU1Y8hhsF2jcZ EMM0ZuhleIptb5htRd76qFkaJVSzKqf8t6Y8nYLWTtFKZQIjsHtfYCnNJsTYhJiRY6 KOujAvhqy7QGbQUy9VjMkS8s/UNkPGl7PoX56mPLds4sm096GNLOCgumfhHLx70MAr lsSWOAEJjdjeDG3nSpxOII/LevC1Inlh5TJfUXztZuA3lirnPSbMTTXj35K+LNeTXZ TSs2bSbGZApBtMNZSH7ZC5JMLXcC5RpxdcmP5Snj7GsEaKWWzDbbascCNT0r9sFUHV fP/vAwZyun/Pg== Subject: Re: [PATCH net v3 2/7] net/smc: do not credit stale CDC completions after a link switch From: netdev-bot+sashiko@kernel.org To: hexlabsecurity@proton.me Cc: edumazet@kernel.org, pabeni@redhat.com, davem@davemloft.net, kuba@kernel.org, mjambigi@linux.ibm.com, sidraya@linux.ibm.com, alibuda@linux.alibaba.com, willemb@google.com, dust.li@linux.alibaba.com, guwen@linux.alibaba.com, guangguan.wang@linux.alibaba.com, tonylu@linux.alibaba.com, ubraun@linux.ibm.com, linux-rdma@vger.kernel.org, linux-s390@vger.kernel.org, hidayath@linux.ibm.com, horms@kernel.org, wenjia@linux.ibm.com, linux-kernel@vger.kernel.org, raspl@linux.ibm.com, netdev@vger.kernel.org Date: Fri, 04 Dec 2026 09:49:29 +0000 Message-ID: <179637776924.3146.12706685496080448498@kernel.org> In-Reply-To: <20261203-b4-disp-ba1ad55e-v3-2-6834ff90c5d0@proton.me> References: <20261203-b4-disp-ba1ad55e-v3-2-6834ff90c5d0@proton.me> X-sashiko-severity: Critical Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit X-Mailing-List: netdev@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider. Critical: 1 · High: 0 (1) · Medium: 0 · Low: 1 If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough). - [Critical] net/smc: stale CDC completion wraparound overflows sndbuf_space - [Low] Undocumented stable backport dependency. Pre-existing issues: - [High] This problem wasn't introduced by this patch, but connections in closing states lose in-flight data on a link switch. -- net/smc: do not credit stale CDC completions after a link switch Each CDC pending send now carries a switch generation, and smc_switch_cursor() bumps that generation. smc_cdc_tx_handler() then credits sndbuf_space only for completions of the current generation whose cursor is not behind tx_curs_fin. The goal is to stop rewound bytes from being credited, and to stop the same bytes being credited twice after a link switch. > diff --git a/net/smc/smc_cdc.c b/net/smc/smc_cdc.c > index 32d6d03df3214..d1f346376c08c 100644 > --- a/net/smc/smc_cdc.c > +++ b/net/smc/smc_cdc.c > @@ -36,7 +36,15 @@ static void smc_cdc_tx_handler(struct smc_wr_tx_pend_priv *pnd_snd, > sndbuf_desc = conn->sndbuf_desc; > smc = container_of(conn, struct smc_sock, conn); > bh_lock_sock(&smc->sk); > - if (!wc_status && sndbuf_desc) { > + /* A CDC posted before a link switch rewound the cursors: its bytes > + * are resent on the new link or credited by the switch's catch-up. > + * A cursor behind tx_curs_fin (completions on two links in any > + * order) was credited already. > + */ > + if (!wc_status && sndbuf_desc && > + cdcpend->switch_gen == conn->tx_switch_gen && > + smc_curs_sdiff(sndbuf_desc->len, &conn->tx_curs_fin, > + &cdcpend->cursor) >= 0) { > diff = smc_curs_diff(sndbuf_desc->len, > &cdcpend->conn->tx_curs_fin, > &cdcpend->cursor); [Severity: Critical] Can a stale completion from the old link still pass this check once the connection has streamed far enough on the new link? The closing-state branch in smc_switch_conns() moves SMC_APPCLOSEWAIT1 connections with smc_switch_link_and_count() only and never calls smc_switch_cursor(), so tx_switch_gen is not bumped on that path. A CDC still pending on the old link keeps the current generation, and the switch_gen comparison does not filter it out. smc_sendmsg() keeps accepting data in SMC_APPCLOSEWAIT1, so the application can go on streaming on the new link. The old CDC does not have to fail either. smc_ib_modify_qp_rts() sets rnr_retry to SMC_QP_RNR_RETRY (7, retry forever), and after smc_switch_conns() smc_llc_process_srv_delete_link() then waits in smc_wr_tx_wait_no_pending_sends(lnk_del) with no timeout while lnk_del stays in RTS. A peer that withholds receive WQEs on that link can keep the WR outstanding for as long as it likes. The comment on smc_curs_sdiff() says it only holds for cursors less than 32768 rings apart, and nothing bounds that here. With a 16 KiB send buffer that is 512 MiB, which does not take long on RoCE. Once tx_curs_fin.wrap is more than 32768 ahead of cdcpend->cursor.wrap, the s16 cast turns the negative wrap difference positive, smc_curs_sdiff() returns a large positive value, and the >= 0 test passes. smc_curs_diff() then only checks whether the wraps differ and returns (sndbuf_desc->len - tx_curs_fin.count) + cdcpend->cursor.count, up to 2 * sndbuf_desc->len - 1. That is added to sndbuf_space and tx_curs_fin is moved back to the stale cursor. With sndbuf_space above sndbuf_desc->len, smc_tx_sendmsg() can pick a copylen larger than the send buffer. The second chunk then calls memcpy_from_msg() at sndbuf_base with chunk_len > sndbuf_desc->len and writes past the end of sndbuf_desc->cpu_addr. smc_curs_add() also leaves tx_curs_prep.count >= sndbuf_desc->len, and the next sndbuf_desc->len - tx_cnt_prep underflows. Bounding the check by sndbuf_desc->len would narrow this, but the u16 wrap counter aliases back after 65536 rings, so it would not close it. Bumping tx_switch_gen in the closing-state branch alone would leave the bytes in flight on the old link uncredited, since that branch does not rewind or resend them. How should completions from the old link be handled on that path, so they cannot be credited once the wrap distance has gone past what smc_curs_sdiff() can represent? Nothing later in the series appears to change smc_cdc_tx_handler() or smc_switch_conns() for this. [Severity: High] This isn't a bug introduced by this patch, but can a connection in a closing state lose in-flight data on a link switch? The commit message says closing-state connections move to the new link without a rewind. In smc_switch_conns() that branch only does this: if (smc->sk.sk_state == SMC_CLOSED || ... smc->sk.sk_state == SMC_APPCLOSEWAIT1 || ... smc->sk.sk_state == SMC_PROCESSABORT) { spin_lock_bh(&conn->send_lock); smc_switch_link_and_count(conn, to_lnk); spin_unlock_bh(&conn->send_lock); continue; } So tx_curs_sent and local_tx_ctrl.prod are not rewound, and nothing is resent. smc_sendmsg() still accepts writes in SMC_APPCLOSEWAIT1: } else if ((sk->sk_state != SMC_ACTIVE) && (sk->sk_state != SMC_APPCLOSEWAIT1) && (sk->sk_state != SMC_INIT)) { That means RDMA writes and CDCs can still be outstanding on the old link when it fails. smcr_link_clear()->smc_ib_modify_qp_error() flushes those WRs. They reach smc_cdc_tx_handler() through smc_wr_tx_process_cqe() with a non-zero wc_status, so nothing is credited. tx_curs_fin stays behind, but tx_curs_sent and local_tx_ctrl.prod already point past the flushed range. The next CDC posted on the new link then carries a prod cursor past the lost range. That could be a later smc_tx_rdma_writes() send, a consumer cursor update, or the close CDC from smc_close_wr(). Would the peer then read stale RMB contents as stream data? When that CDC completes, it has the current tx_switch_gen and its cursor is ahead of tx_curs_fin. The new check accepts it, and smc_curs_diff() credits sndbuf_space for the whole range, including the bytes that were never delivered. This has been present since c6f02ebeea3a ("net/smc: switch connections to alternate link"). Nothing later in the series appears to fix the missing resend. [ ... ] > diff --git a/net/smc/smc_core.c b/net/smc/smc_core.c > index 73e86100e6db2..fb9f6a4eb6835 100644 > --- a/net/smc/smc_core.c > +++ b/net/smc/smc_core.c > @@ -1058,6 +1058,7 @@ static int smc_switch_cursor(struct smc_sock *smc, struct smc_cdc_tx_pend *pend, > int rc = 0; > int diff; > > + conn->tx_switch_gen++; /* completions of earlier sends: no credit */ > smc_curs_copy(&conn->tx_curs_sent, &conn->tx_curs_fin, conn); > smc_curs_copy(&fin, &conn->local_tx_ctrl_fin, conn); > /* set prod cursor to old state, enforce tx_rdma_writes() */ [Severity: Low] Does this rely on the preceding patch in the series, "net/smc: take the socket spinlock across the failover cursor switch"? smc_cdc_tx_handler() reads tx_switch_gen and tx_curs_fin under bh_lock_sock() only. The handler sees this bump and the rewind after it as atomic only because the preceding patch takes the socket spinlock around the call in smc_switch_conns(): local_bh_disable(); bh_lock_sock(&smc->sk); spin_lock(&conn->send_lock); smc_switch_link_and_count(conn, to_lnk); rc = smc_switch_cursor(smc, pend, wr_buf); Without that patch, smc_switch_cursor() runs under send_lock only. The completion handler on another CPU can then see switch_gen == tx_switch_gen just before the bump, and credit and overwrite tx_curs_fin while the switch is rewinding it. This hunk applies and builds without the preceding patch, and both patches carry Cc: stable with the same Fixes: tag. "net/smc: order the urgent mark across the cursor wrap rollover" in the same series has a "# depends on" note. Should this commit have one too, so a stable backport does not take it alone? -- Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261203-b4-disp-ba1ad55e-v3-0-6834ff90c5d0%40proton.me