Article View: linux.kernel.netdev
Article #26234[PATCH net v3 4/7] net/smc: fix the failover catch-up across the cursor wrap rollover
From: Bryam Vargas via B4 Relay
Date: Thu, 03 Dec 2026 09:15
Date: Thu, 03 Dec 2026 09:15
94 lines
14752 bytes
14752 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 that is 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 that is 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 tx_curs_prep: a conforming
peer has read no further, and unlike tx_curs_sent no failover rewinds
it. The bound also caps what a forged consumer cursor, which is taken
off the wire unchecked, can add to sndbuf_space.
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
Reviewed-by: Sidraya Jayagond <sidraya@linux.ibm.com>
Signed-off-by: Bryam Vargas <hexlabsecurity@proton.me>
---
net/smc/smc_cdc.h | 10 ++++++++++
net/smc/smc_core.c | 16 +++++++++++-----
2 files changed, 21 insertions(+), 5 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 4ee9e6f0d659..22a9a818a046 100644
--- a/net/smc/smc_core.c
+++ b/net/smc/smc_core.c
@@ -1054,9 +1054,9 @@ 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, prod, sent;
+ union smc_host_cursor cons, prep, prod, sent;
int rc = 0;
- int diff;
+ s64 diff;
conn->tx_switch_gen++; /* completions of earlier sends: no credit */
/* The cursors of the connection have readers outside send_lock and
@@ -1065,14 +1065,20 @@ static int smc_switch_cursor(struct smc_sock *smc, struct smc_cdc_tx_pend *pend,
smc_curs_copy(&sent, &conn->tx_curs_fin, conn);
smc_curs_copy(&prod, &conn->local_tx_ctrl_fin, conn);
smc_curs_copy(&cons, &conn->local_rx_ctrl.cons, conn);
+ smc_curs_copy(&prep, &conn->tx_curs_prep, conn);
- if (smc_curs_comp(conn->peer_rmbe_size, &cons, &prod) < 0) {
+ /* cons comes off the wire: go no further than tx_curs_prep, which
+ * a conforming peer has not read past and no failover rewinds. That
+ * also keeps diff within one send buffer for smc_curs_add().
+ */
+ diff = min(smc_curs_sdiff(conn->peer_rmbe_size, &prod, &cons),
+ smc_curs_sdiff(conn->sndbuf_desc->len, &sent, &prep));
+ if (diff > 0) {
/* cons cursor advanced more than fin: the peer has read
* that far, so resend from there and count it as confirmed.
*/
- diff = smc_curs_diff(conn->peer_rmbe_size, &prod, &cons);
smc_curs_add(conn->sndbuf_desc->len, &sent, diff);
- smc_curs_add(conn->peer_rmbe_size, &prod, diff);
+ smc_curs_advance(conn->peer_rmbe_size, &prod, diff);
smc_curs_copy(&conn->tx_curs_fin, &sent, conn);
smc_curs_copy(&conn->local_tx_ctrl_fin, &prod, conn);
--
2.56.1
Technical Details
Message-ID:
<20261203-b4-disp-ba1ad55e-v3-4-6834ff90c5d0@proton.me>Path:
mbox-mo1.pugleaf.net!srl.newsdeef.eu.MISMATCH!feed-eu-txt.newsdeef.eu!feed-eu-ch.newsdeef.eu!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-376431-linux-kernel-netdev=dewy.ruReferences:
<20261203-b4-disp-ba1ad55e-v3-0-6834ff90c5d0@proton.me>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srl.newsdeef.eu.MISMATCH!feed-eu-txt.newsdeef.eu!feed-eu-ch.newsdeef.eu!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-376431-linux-kernel-netdev=dewy.ru From: devnull+hexlabsecurity.proton.me@kernel.org (Bryam Vargas via B4 Relay) Newsgroups: linux.kernel.netdev Subject: [PATCH net v3 4/7] net/smc: fix the failover catch-up across the cursor wrap rollover Date: Thu, 03 Dec 2026 04:15:06 -0500 Organization: Usenet Network Message-ID: <20261203-b4-disp-ba1ad55e-v3-4-6834ff90c5d0@proton.me> References: <20261203-b4-disp-ba1ad55e-v3-0-6834ff90c5d0@proton.me> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Injection-Info: usenet.network; logging-data="2445577"; mail-complaints-to="abuse@usenet.network" Cancel-Lock: sha1:JfeTsMXVm05bIeXrtSE6Kw4LaM8= sha256:4SMc1KYoUkyycP8EuF+nR8UK1kZgHi/vy07frEhL5t4= sha1:w1ekm1siqoRtKNoWqeuJ3La2qj4= sha256:Oim1yCngvAH4yqzyqy/WIvJFJuOmBfUXZ57WozPZIU4= 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 6C855117899; Thu, 3 Dec 2026 12:15:50 +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 WL1N7D2oYBjh; Thu, 3 Dec 2026 12:15:47 +0300 (MSK) X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=104.64.211.4; helo=sin.lore.kernel.org; envelope-from=netdev+bounces-376431-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 sin.lore.kernel.org (sin.lore.kernel.org [104.64.211.4]) by mail.dewy.ru (Postfix) with ESMTPS id 9CA7411786F; Thu, 3 Dec 2026 12:15:38 +0300 (MSK) X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92]) by sin.lore.kernel.org (Postfix) with ESMTP id 9A1A92684A; Thu, 3 Dec 2026 09:15:36 +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=1796289311; b=gwHg4sg1lwtA44sETcFXEwMkXmP77yzOyMEN9Mda4euV+ZxpEQ4YE3agiUSWjrdkoDRQ w6MCJLwBWH0aDT1hLmRPB82R2OI0OoxZL5C3q52iD9fUu0TVJIBaheNL/Durfksz4DAqh H3jU1x7h7HovQvixw55YnXbR5eI0rTtlRxe/F07yDNkpf8CEclnepPFcki2FYOZjAzLB/ LLZYk18J+MAd1EQFwCCUI0myaHqxOEoaxKdpIVHwsomBvMAXKBai4e/T2bbawGTRF7Czz r3ebAIV7oCNIz7a68DK+vtvUTvEjpKImzNosZ/TievjZ45I+WQOjTib8bc2yFuQNgyg== X-ARC-Message-Signature: i=3; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796289311; 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=tgen5dKQJS4KdowBUVB+OZXlL6uOURCZJIVamuQVyKA=; b=E09aPy3U+IBfIE0Kg58UbDWpvWKBhC1jRQEOr9MR2xDJ82kMdxG16IAW/714MuoqAf/E BBdps3gPLGYF1eVRYQeo1kcqp1sarCxCtgnXKOm/RttXP28+VTljY8dzDOPGuKD8cZgCP H8sK5yQYjPEeGIV0vv8KdGuY2SjeO6ZM3WwDYKyWXfo0+3J7zAem8Ih+lVX5vakPD0MEQ tAAVyZ6EyJOUeInV2kai2ePU8mNfsQN7re6pCRp37FnWtJWL8kUQXnV8ce+4IV6spvoxS fo6sGxfFgesTB+aEPwHldhPEPqkOyzfU5kctAnJy7bsbwJ6L3cOxQ+dcO9dFJu7U5IQ== 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=TJpmIqwW; 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 B852960A6F75; Thu, 3 Dec 2026 09:15:11 +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=TJpmIqwW 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=1796289305; b=qEeIbZtkbhGXHwWQoTUnTewQhweMUAwj9z/h94yETe//n9BBALhSdjc3HVWGAVFnMK/Y SuvAXNgWqLvyizEslwi3RVVysYIlEjo6K9Pnzzep72NH/maE1SxYITplN7yAMnfbO2+Vz WcK1ZtcQOdngbmCepZNrEGGhzdEEaH4QHkPYcIjDfmYO+BwbK8TTzCkvNT0VQi2qHuKQc CIm6kCgnF1TKlnZtBulZWELBEoj92KffbgBdu1bC7Z8pkO7d87U/s7TUsTBej56yrj/Qv v9+61jz8jiIndujxHLJVxtiSltlp9Ab5RhSiGaioj9xjNM7nwpPmXvZUdb8u947sE1A== X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796289305; 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=tgen5dKQJS4KdowBUVB+OZXlL6uOURCZJIVamuQVyKA=; b=1y9s0KUMdlRQQSsZQ2994iFAaWKkghvxjr11/1q5nziECTPjiR588uTksv+Ry3QH6g5A ktt3h4o6+NTXBA8vIRQcTq3ue1kQGhLxRTRp335UZWLAbVaYqcbYlvHz8Unde4qG1esku eet25KbdJGmpvCNKqsPsivT8jIOAGDEO8fNFPZ5DBJjQLlGhKiF5zKhuvGNaeVoRy9/W5 9wTzsdUsT60JAyBwHZl+ZsOeLhpFf90DshJA5fiZLdjs8Kys+KZnKVQCROydcj7fHomrH QZY59vKaEPzHCljBP8Qs0PISkpS9KebbtrA922mgimLcYge1M5bAng+8pg+op+LW+Rw== 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=TJpmIqwW; 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 CCEF0606A695; Thu, 3 Dec 2026 09:15:05 +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=1796289305; b=z4xDAiDUl1OU5FASJ3fHzJnMT2XSWh/Pq04pVrCzmNOQxAQlvZZfj42A5FbiWR8+25V6 AUf4CBky1vIgJUUdMJAPNBmS0ZGqEqYaepzHoIIT+rgr3ems4/AA3UX5KjN3DTYzNe98t DiklhYRltVPUGmzD/cimro0FyLAhu9llrlHyTbblCJHRIlG0M/6hpwwGjZ+X9gyJot+sY ITnFQVAkKUn4NGu2s/EKPI4QwNjbJ65PBJUh2dzLxFpenQhVvGTiEfspTKGyfH4uBIXb1 TYAd4w/2GUOX2HQ6MrjD5dSvLeyUbjouzbgielOZ/AIKt3i5+D9dhycrF3uHaEjmFlA== X-ARC-Message-Signature: i=1; d=kernel.org; s=arc20260519; a=rsa-sha256; c=relaxed/relaxed; t=1796289305; 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=tgen5dKQJS4KdowBUVB+OZXlL6uOURCZJIVamuQVyKA=; b=Meod+hFeGpHl7Jk3V/Yr7BEHP2+OQXCJ3FhfC0JfJdAjLip1yOo60n9lj7c+phuNpRbN rRNeB43t6m3tagxTrKiAJJd3y+KEfuvXsyACCMccGZ2yix4pERPD/FgiODrgGZsReu4B1 yj6K2Mea+JyygBdMkQZpDB4HaqHaZgDvEIwn7/8k/blqzJWe8lJvhjtYDBH83IQrzzqIX lCA9iT08IbQnFAG2gz5JZ2TaNm6dcPP3Hr5QQCQoDJCl5Hn4Tp92cL+hdkcwkswqk22WP xFyAfoF45PrEy7BY17eXgQQ8xVP57vyMBnw0PfOi9OrPSk3KD3T4RhXUJKzNkCOTjcg== 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 7D40F1F0089A; Thu, 3 Dec 2026 09:15:04 +0000 (UTC) X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796289305; bh=tgen5dKQJS4KdowBUVB+OZXlL6uOURCZJIVamuQVyKA=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To; b=TJpmIqwWWiVPlptoHXGXOA7yldgPVe3S9a2Xi8+QLT6eysTgYazaG6i3oABYQ6rfk ZY7b2JSfgryzo5sIWAXB+eryPNSsGwLnffDDgoDcZ+60tBeKvv+5XaS5oK8UpijDC5 /3uTLI01rBoRfAeeIJGgzWfVPIYewLVqhtA9zovKqp4E+1oFfyUutlQma9KzWYW41L HDHe3cGZ7RMIhriEHhF/8kFJCjdqTBfKegMu2TbqxxrhUJWWiyCaGBZXLppKO9a2be EhqPwt/bddD+QVpr4CQLU402HNFAHi5G1sLYkFKM/loK3mjtI8tZAk4INvODuiMTgq oQ/ZylpCjgvVA== X-Received: from nexus.subspace.kernel.org (localhost [IPv6:::1]) by lkml.kernel.org (Postfix) with ESMTP id 095F24F8B7; Thu, 3 Dec 2026 09:15:04 +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: <20261203-b4-disp-ba1ad55e-v3-0-6834ff90c5d0@proton.me> X-Cc: Wen Gu <guwen@linux.alibaba.com>, Guangguan Wang <guangguan.wang@linux.alibaba.com>, Tony Lu <tonylu@linux.alibaba.com>, Ursula Braun <ubraun@linux.ibm.com>, linux-rdma@vger.kernel.org, linux-s390@vger.kernel.org, Hidayath Khan <hidayath@linux.ibm.com>, Simon Horman <horms@kernel.org>, Wenjia Zhang <wenjia@linux.ibm.com>, linux-kernel@vger.kernel.org, Stefan Raspl <raspl@linux.ibm.com>, netdev@vger.kernel.org X-Mailer: b4 0.15.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1796289302; l=3995; i=hexlabsecurity@proton.me; s=default; h=from:subject:message-id; bh=ARWPX/r+aDzxGrIrLR9DE1bphxYWzzgMFfJioYJJ7a8=; b=1obo2mZ6ipjnaUc8WOGc4GQKyHbteo0WOVlFT59/sm0ayFUPZA0AjXQzDWE+4y/dxxxaB9LKk FmFvjV+EvQUAP2HbmCc27DKXFKmoSOV8KyQ3yTRHZNoVFdLy/N36ycJ 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