Article View: linux.kernel.netdev
Article #16156[PATCH net 3/4] net/smc: fix the failover catch-up across the cursor wrap rollover
From: Bryam Vargas via B4 Relay
Date: Sat, 14 Nov 2026 04:14
Date: Sat, 14 Nov 2026 04:14
103 lines
14845 bytes
14845 bytes
From: Bryam Vargas <hexlabsecurity@proton.me>
smc_switch_cursor() orders the peer's consumer cursor against
local_tx_ctrl_fin with smc_curs_comp(), which misorders them across the
65535 -> 0 rollover of the u16 wrap. A consumer cursor behind reads as
ahead: the catch-up can credit sndbuf_space for bytes never sent and
tell the peer they are in its RMB, so the next send() can copy past the
end of the send buffer. One ahead reads as behind and the catch-up is
skipped. With a send buffer larger than the peer's RMB, the catch-up can
also be short once the peer is more than one RMB past local_tx_ctrl_fin,
and the connection then stalls.
Use the signed cursor distance, advance the RMB cursors across any
number of wraps, and bound the catch-up by the bytes sent, which a
peer's consumer cursor cannot legitimately pass.
Fixes: c6f02ebeea3a ("net/smc: switch connections to alternate link")
Reported-by: Sashiko <sashiko-bot@kernel.org>
Closes: https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261029-b4-disp-33001ace-v8-0-f9bb96e17827%40proton.me?part=4
Cc: stable@vger.kernel.org
Signed-off-by: Bryam Vargas <hexlabsecurity@proton.me>
---
net/smc/smc_cdc.h | 10 ++++++++++
net/smc/smc_core.c | 22 ++++++++++++++--------
2 files changed, 24 insertions(+), 8 deletions(-)
diff --git a/net/smc/smc_cdc.h b/net/smc/smc_cdc.h
index 597acb2e123f..4b586a20dfc2 100644
--- a/net/smc/smc_cdc.h
+++ b/net/smc/smc_cdc.h
@@ -97,6 +97,16 @@ static inline void smc_curs_add(int size, union smc_host_cursor *curs,
}
}
+/* smc_curs_add() for a value that may span more than one ring */
+static inline void smc_curs_advance(unsigned int size,
+ union smc_host_cursor *curs, u32 value)
+{
+ u32 count = curs->count + value;
+
+ curs->wrap += count / size;
+ curs->count = count % size;
+}
+
/* Copy cursor src into tgt */
static inline void smc_curs_copy(union smc_host_cursor *tgt,
union smc_host_cursor *src,
diff --git a/net/smc/smc_core.c b/net/smc/smc_core.c
index fb9f6a4eb683..76a577a20e4a 100644
--- a/net/smc/smc_core.c
+++ b/net/smc/smc_core.c
@@ -1054,22 +1054,28 @@ static int smc_switch_cursor(struct smc_sock *smc, struct smc_cdc_tx_pend *pend,
struct smc_wr_buf *wr_buf)
{
struct smc_connection *conn = &smc->conn;
- union smc_host_cursor cons, fin;
+ union smc_host_cursor cons, fin, sent;
int rc = 0;
- int diff;
+ s64 diff;
conn->tx_switch_gen++; /* completions of earlier sends: no credit */
+ smc_curs_copy(&sent, &conn->tx_curs_sent, conn);
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() */
smc_curs_copy(&conn->local_tx_ctrl.prod, &fin, conn);
smc_curs_copy(&cons, &conn->local_rx_ctrl.cons, conn);
- if (smc_curs_comp(conn->peer_rmbe_size, &cons, &fin) < 0) {
+ /* not past what was sent, whatever cons says; that also keeps
+ * diff within one send buffer for smc_curs_add()
+ */
+ diff = min(smc_curs_sdiff(conn->peer_rmbe_size, &fin, &cons),
+ smc_curs_sdiff(conn->sndbuf_desc->len,
+ &conn->tx_curs_fin, &sent));
+ if (diff > 0) {
/* cons cursor advanced more than fin, and prod was set
* fin above, so now prod is smaller than cons. Fix that.
*/
- diff = smc_curs_diff(conn->peer_rmbe_size, &fin, &cons);
smc_curs_add(conn->sndbuf_desc->len,
&conn->tx_curs_sent, diff);
smc_curs_add(conn->sndbuf_desc->len,
@@ -1079,10 +1085,10 @@ static int smc_switch_cursor(struct smc_sock *smc, struct smc_cdc_tx_pend *pend,
atomic_add(diff, &conn->sndbuf_space);
smp_mb__after_atomic();
- smc_curs_add(conn->peer_rmbe_size,
- &conn->local_tx_ctrl.prod, diff);
- smc_curs_add(conn->peer_rmbe_size,
- &conn->local_tx_ctrl_fin, diff);
+ smc_curs_advance(conn->peer_rmbe_size,
+ &conn->local_tx_ctrl.prod, diff);
+ smc_curs_advance(conn->peer_rmbe_size,
+ &conn->local_tx_ctrl_fin, diff);
}
/* recalculate, value is used by tx_rdma_writes() */
atomic_set(&smc->conn.peer_rmbe_space, smc_write_space(conn));
--
2.56.0
Technical Details
Message-ID:
<20261113-b4-disp-1a9ab9b0-v1-3-4a7c8d85d849@proton.me>Path:
mbox-mo1.pugleaf.net!news-lax.pugleaf.net!srl.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-363096-linux-kernel-netdev=dewy.ruReferences:
<20261113-b4-disp-1a9ab9b0-v1-0-4a7c8d85d849@proton.me>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-lax.pugleaf.net!srl.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-363096-linux-kernel-netdev=dewy.ru From: devnull+hexlabsecurity.proton.me@kernel.org (Bryam Vargas via B4 Relay) Newsgroups: linux.kernel.netdev Subject: [PATCH net 3/4] net/smc: fix the failover catch-up across the cursor wrap rollover Date: Fri, 13 Nov 2026 23:14:42 -0500 Organization: Usenet Network Message-ID: <20261113-b4-disp-1a9ab9b0-v1-3-4a7c8d85d849@proton.me> References: <20261113-b4-disp-1a9ab9b0-v1-0-4a7c8d85d849@proton.me> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Injection-Info: usenet.network; logging-data="1506237"; mail-complaints-to="abuse@usenet.network" Cancel-Lock: sha1:VzQtSsxV+v1hLuJmqva++cup+no= sha256:m+YpaTBVTLmTURIk9chEzSapEIozX2UrM0P3N+s5fW8= sha1:/hSTmXwHOpdExTi9+1WJ/isYEYQ= sha256:TzVV+OpEolUuk0n8SYWWhMmmNm91n+EDMVD8/oOlSbc= List-ID: <netdev.vger.kernel.org> X-Mailpost-Empty-Hdrs: X-Spam-Level X-Received: from localhost (localhost [127.0.0.1]) by mail.dewy.ru (Postfix) with ESMTP id 2FF33114759; Sat, 14 Nov 2026 07:16:06 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at usenet.network X-Spam-Flag: NO X-Spam-Score: -3.401 X-Spam-Status: No, score=-3.401 tagged_above=-9999 required=6.31 tests=[DCC_REPUT_70_89=0.1, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001] autolearn=ham autolearn_force=no X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key) header.d=kernel.org X-Received: from mail.dewy.ru ([127.0.0.1]) by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id GMm10wIR4A6m; Sat, 14 Nov 2026 07:16:01 +0300 (MSK) X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.105.105.114; helo=tor.lore.kernel.org; envelope-from=netdev+bounces-363096-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> X-Authentication-Results: OpenDMARC; dmarc=pass (p=quarantine dis=none) header.from=kernel.org X-Received: from tor.lore.kernel.org (tor.lore.kernel.org [172.105.105.114]) by mail.dewy.ru (Postfix) with ESMTPS id 3206F11475E; Sat, 14 Nov 2026 07:15:52 +0300 (MSK) X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92]) by tor.lore.kernel.org (Postfix) with ESMTP id 15F9346114; Sat, 14 Nov 2026 04:15:38 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 X-ARC-Seal: i=3; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1794629694; b=GJ+UZ35JVTJBFYkpwB4LcD0mbW9ygTj5O8GVtt4dlT8DmHpeG9DY8PEoOIVGTwtCTh1U wKiZRpNWGxkBRNhvVVcwHlbURqFfV5pcRxIMBcFRY3XfhNqvLEaWFENQxghTsEziD9afB y+CKUHcKJf7D2qD/e5ilBCLrNs50wS8JIdiJOXppokAj72ZXb2MWYyHWRiCx5Kb8mh3rS dY4HhlVljf55U47u9YSo8U3RW/R/Q//iW/cScZ5BR5tKrNJBUn/bH6ymuUU/6Jt31ARih +wU5qMK2rsAOLFgG5Jc5IEtFjbMPpHxRRnNvC5rc62Oz/1Kl3vSmi1ZVYgZJJTjo3oA== X-ARC-Message-Signature: i=3; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794629694; h=X-Original-To:Received:Received:DKIM-Signature:Received:From:Date: Subject:X-Mailing-List:List-Id:List-Post:List-Help:List-Subscribe: List-Unsubscribe:List-Owner:Precedence:MIME-Version:Content-Type: Message-Id:References:In-Reply-To:To:Cc:X-Mailer: X-Developer-Signature:X-Developer-Key:X-Endpoint-Received: X-Original-From:Reply-To:Content-Transfer-Encoding; bh=cO6oAOXIgzMpetBE3e7i5weblbBDQaW8Yu+sv7kIn3I=; b=ZZgfIYlbIgMGRXD5cVL/ClswUhs3cDIqU+kPTCl3VNsiH7/y4cF4z10v+Bznn/580W/h r4C81Jg2eQLV3P8TB4Kup0PzNY/aR2Nr/N6KMnPRQeBJ2iTB+3kmvdosFM0PcH27C0WT3 roqdqqM7RtcEXjJH3ehEuSCOEtC0mVr8PAhSoiQ6Dno/5Dd15hamXIS3PdzplU1Cg8zMd 33nZI+ZY2/6w0F2Iog+sXzUqp5dvQeDB0WiKjmUmQjfFGGiow7Nf4Kxx/XNAZKVoG/8Nx gSjYzPgrric3PjDd8jGOG5N0ZIKTqtAT897Fungknafc1IN8Uew6eP5ItFq4f+S+XCw== X-ARC-Authentication-Results: i=3; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=EPzxDc45; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 X-Received: from localhost.localdomain (localhost [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 69034606A885; Sat, 14 Nov 2026 04:14:54 +0000 (UTC) X-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=EPzxDc45 X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=100.103.45.18 X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1794629683; b=A3LMkjGlhx4hJ1x6bMf8I01i2lSiglBD/4Pt1lfnWLWq8IWjksS2oT9VeFTo0Egb/7jA zQje98OlAF9kYSzVgrRwU94L+xdMmShNVdBzzXdmxvlCohdpgLf1+M5PWbL9z6OwLGwu0 SQKHDq7kmgEMGCfOI8tA9n/7xU4NCKd4TD5v3WnneROUP6agB/TWUM5Y3WHkItZz5RqSu 7WoI2CBlwex3x2mPfa4tGV+AmUEmzZ8ePHIJjgJstucpB1fKjDeiz/nFty2472wXMEprD 7XNrutxaBieGvArVKO9GBALBk4RGcHrKe2wlQyKSw3dyApf3hWFh8axOW8lDo7wyVbg== X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794629683; h=Received:DKIM-Signature:Received:From:Date:Subject:MIME-Version: Content-Type:Message-Id:References:In-Reply-To:To:Cc:X-Mailer: X-Developer-Signature:X-Developer-Key:X-Endpoint-Received: X-Original-From:Reply-To:Content-Transfer-Encoding; bh=cO6oAOXIgzMpetBE3e7i5weblbBDQaW8Yu+sv7kIn3I=; b=w/Ju8uhK9iEP2zZ0VYXHkX3JQY0Lwe3rZvmj/N84QhjWaG7061vi0UKbbYKMfkgt3dvI M9WcGy0Alx0uPn5UMLOVWwBWtRAtNKQGizu8HqkZPYA07RPczVqCCTFk+SPtMIBdBE0iZ 9MoV0qBsoderiA7qhoXWsJ4OOTA33ai09kFSEMZCXK9k1+TkU38ffgcABb57L9Oc+4xda QL7MMDFycV0LsRwm4G4coEg24EnBENueMGtIeXKmu6bP57xvdHnXPOkUf7vTDqeuJjjsU b5yEBf5R/Mha0X07MH54rRtBSmjYkdbAGSbxOP+fmLAfJHkjpTj4ULj9QBHSrz6e1kw== X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=EPzxDc45; arc=pass header.oldest-pass=0 smtp.remote-ip=100.103.45.18 X-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 83AE5606A8A4; Sat, 14 Nov 2026 04:14:43 +0000 (UTC) X-Authentication-Results: smtp.kernel.org; arc=none smtp.remote-ip=100.80.115.77 X-ARC-Seal: i=1; d=kernel.org; s=arc20260519; a=rsa-sha256; cv=none; t=1794629683; b=cLSPLILHkA40YqWTIAIZJ1cqCnCYdpqNQTHdKsD64nzb+D0nGBQy6QD6ypZmvuabkXt8 5mWRpSwnPEgsTYE6/5rGGJXACERtyfEoC64KeZjkKIj8G+6zscaauLyCZ5W2g+LRyYbfH YH+dkarZyGoXzxrc7qfFgf4tRT+t7AWNN07vvDu8K0RLTy5D1RBy8dva9XiWJyWoo0gDg G2nTe+lWO11s6ddmXmBsyEJkIuZv5mFas87vMOXIq5j7Eadw7luZINfuicT6T8B8jhfVc Jpee3lo734jK+0ZuAuDWJ1MTBZ3WB1j74XtoRG+KVXQK8BXnGieUqG1D6O6zrGrt/eQ== X-ARC-Message-Signature: i=1; d=kernel.org; s=arc20260519; a=rsa-sha256; c=relaxed/relaxed; t=1794629683; h=DKIM-Signature:Received:From:Date:Subject:MIME-Version:Content-Type: Message-Id:References:In-Reply-To:To:Cc:X-Mailer: X-Developer-Signature:X-Developer-Key:X-Endpoint-Received: X-Original-From:Reply-To:Content-Transfer-Encoding; bh=cO6oAOXIgzMpetBE3e7i5weblbBDQaW8Yu+sv7kIn3I=; b=ZqMq1vP10hUW+Iotni6tjKGzTeQWPKKOccDTnAv92eUwSiUkPzzbEMnBTC3Xp1mg8UaM Vd9RD19Ipr7HC50lNUMCL0cbX9EpL0QN5QLLuHWuLIMA7G5RHAzBaMOEoVJPytYuu35xL 80FXda+5bdZtpp1V+7+/3oZ6aNd81vdSPxpyuvH4ZVwSALy7/RTKf3234VFaZCw/2sh3V 60gOypBmFRTN+pF4g1imekZZSNdoNdP6QKM2TJ9GlSA7qVtKl79HEyrdWgns94APLv67P yWSBOeae7OE7qgTi6Mqyc4s5z6lVE3cuCiC4AsUW63MsJtG2FCwpG3b53ZHaiZtl/cA== X-ARC-Authentication-Results: i=1; smtp.kernel.org; arc=none smtp.remote-ip=100.80.115.77 X-Received: from lkml.kernel.org (nexus.subspace.kernel.org [100.80.115.77]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.kernel.org (Postfix) with ESMTPS id C31001F000C7; Sat, 14 Nov 2026 04:14:41 +0000 (UTC) X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1794629683; bh=cO6oAOXIgzMpetBE3e7i5weblbBDQaW8Yu+sv7kIn3I=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To; b=EPzxDc45vExe9fyNulgEEgJaLgFjaUCVptyzJGfMWRXpitnmIZftrlWLH2o7gk1cn 5To57l0cfihECi786oqxYgAS8BSx58Y2Lhq0lYQd4ELl1Zch9m2rxtLsxj8VQfVhR5 PSH36J+wUzSpP5xHuH1oS44OsiB1a9JFjB9xtGpXmf5QGqwROf0QKcMohmlTD/w1qn sR2NMReqTWLH77SCv8buoYqpFnDQnnvN+W7C+MOIcNh98UofBKAAJrc7cEAaIvySNK YHTJ4d8UpEqpvm7xhwBdY+s8JRqMIvrEf81IlyAUWoDOCVfSF4jtH6gkDcIaBDYqX5 rIAli3nMRuOdg== X-Received: from nexus.subspace.kernel.org (localhost [IPv6:::1]) by lkml.kernel.org (Postfix) with ESMTP id 503BF49C81; Sat, 14 Nov 2026 04:14:41 +0000 (UTC) X-Mailing-List: netdev@vger.kernel.org X-List-Post: <mailto:netdev@vger.kernel.org> X-List-Help: <mailto:netdev+help@vger.kernel.org> X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org> X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org> X-List-Owner: <mailto:netdev+owner@vger.kernel.org> X-Precedence: list X-In-Reply-To: <20261113-b4-disp-1a9ab9b0-v1-0-4a7c8d85d849@proton.me> X-Cc: Guangguan Wang <guangguan.wang@linux.alibaba.com>, Tony Lu <tonylu@linux.alibaba.com>, netdev@vger.kernel.org, Wenjia Zhang <wenjia@linux.ibm.com>, Ursula Braun <ubraun@linux.ibm.com>, Hidayath Khan <hidayath@linux.ibm.com>, linux-s390@vger.kernel.org, linux-kernel@vger.kernel.org, Simon Horman <horms@kernel.org>, Wen Gu <guwen@linux.alibaba.com>, Stefan Raspl <raspl@linux.ibm.com>, linux-rdma@vger.kernel.org X-Mailer: b4 0.15.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1794629679; l=4137; i=hexlabsecurity@proton.me; s=default; h=from:subject:message-id; bh=MVHarJC77cCCLJEzqiGRuVpi6O8XQzj00ArzQHD908I=; b=F74AfkgSmjHIJIkI11G6+klEgg5afXLKUyZ+MgiafeDZN5uFBsKxa2QREh+gp2N2FTyRZcd3/ sEaJOr5FktXDaaM12ytCJMfZ4oOK01LFbHkVs6yBy5KhEbQS6xLAT2A X-Developer-Key: i=hexlabsecurity@proton.me; a=ed25519; pk=xw1AhCtQdvuoQc+bOQIYy9o8G++cp4/VniI2G/tc3G8= X-Endpoint-Received: by B4 Relay for hexlabsecurity@proton.me/default with auth_id=893 X-Original-From: Bryam Vargas <hexlabsecurity@proton.me> X-Reply-To: hexlabsecurity@proton.me