🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.netdev
Article #23965

Re: [PATCH net v3] net/smc: drop the connection when the peer's failover cursor is impossible

#23965
From: netdev-bot+sashiko
Date: Sat, 28 Nov 2026 17:53
218 lines
16960 bytes
Thank you for your contribution! Sashiko AI review found 4 potential
issue(s) to consider.

Critical: 0 · High: 1 · Medium: 1 · Low: 2

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).

- [High] In smc_switch_cursor() (net/smc/smc_core.c), the patch's bound
  does not stop the overflow it says it fixes.
- [Medium] The new check in smc_switch_cursor() can abort the connection
  of an honest peer.
- [Low] The new check in smc_switch_cursor() bounds only the single-wrap
  diff, and only against a sndbuf-derived limit, so some impossible peer…
- [Low] The new abort path in smc_switch_cursor() returns after the
  function has already rewound conn->tx_curs_sent to tx_curs_fin and…

--

net/smc: drop the connection when the peer's failover cursor is impossible

This patch adds a check to smc_switch_cursor(). It compares the
peer-reported consumer cursor advance (diff) against
sndbuf_desc->len - sndbuf_space. If diff is larger, the connection is
marked out_of_sync, peer_conn_abort is set and abort_work is queued,
instead of crediting sndbuf_space and advancing the tx cursors.

Link: https://lore.kernel.org/all/20261122053223.2497832-2-piyus@iiitd.ac.in/

> diff --git a/net/smc/smc_core.c b/net/smc/smc_core.c
> index a3164201c1420..ccfc3b1dc8498 100644
> --- a/net/smc/smc_core.c
> +++ b/net/smc/smc_core.c

[ ... ]

> @@ -1069,6 +1070,38 @@ static int smc_switch_cursor(struct smc_sock *smc, struct smc_cdc_tx_pend *pend,
>  		 * fin above, so now prod is smaller than cons. Fix that.
>  		 */
>  		diff = smc_curs_diff(conn->peer_rmbe_size, &fin, &cons);

[ ... ]

> +		unconfirmed = conn->sndbuf_desc->len -
> +			      atomic_read(&conn->sndbuf_space);
> +		if (diff > max_t(int, unconfirmed, 0)) {

[Severity: High]
Can sndbuf_space still end up above sndbuf_desc->len with this bound?

unconfirmed is sndbuf_desc->len - sndbuf_space, which is tx_curs_prep -
tx_curs_fin. That range includes data that was copied into the sndbuf but
never RDMA-written or announced in any CDC message. A forged cons that
passes this check can therefore move tx_curs_fin past the cursor of a CDC
message that is still pending on the old link.

The old QP is still live during the switch.
smc_llc_process_cli_delete_link() only moves it to error afterwards:

	if (smc_link_downing(&lnk_del->state))
		smc_switch_conns(lgr, lnk_del, false);
	smcr_link_clear(lnk_del, true);

So a pending old-link CDC can still complete with wc_status == 0.
smc_cdc_tx_handler() has no link or ordering filter:

		diff = smc_curs_diff(sndbuf_desc->len,
				     &cdcpend->conn->tx_curs_fin,
				     &cdcpend->cursor);
		...
		atomic_add(diff, &cdcpend->conn->sndbuf_space);

When the wraps differ, smc_curs_diff() returns
(size - old->count) + new->count, even if new is behind old.

With len = peer_rmbe_size = 100:

  fin = (0,80), sent = (0,95), prep = (1,10), sndbuf_space = 70
  pending CDC c1 with cursor (0,95)
  peer forges cons = (1,10)

  smc_switch_cursor(): diff = 30, unconfirmed = 30, check passes
    tx_curs_fin = (1,10), sndbuf_space = 100
  late c1 completion in smc_cdc_tx_handler():
    diff = (100 - 10) + 95 = 185, sndbuf_space = 285

smc_tx_sendmsg() then computes copylen = min(send_remaining, 285). The
second memcpy_from_msg() chunk is not bounded, so it writes past the end
of the send buffer.

Isn't that the same out-of-bounds write this commit is meant to close?

A same-wrap variant also over-credits. The late completion credits 0 and
moves tx_curs_fin back to c1's cursor. The switch's own validation CDC
then credits the same range a second time.

The changelog describes the remaining race as one that "needs a completion
to land in the window rather than a hostile cursor". In this case the
completion can land at any point between the switch and smcr_link_clear(),
and the peer chooses the cursor.

Would the bound need to be tied to data that was actually sent, rather
than prepared? Would old-link completions also need to be filtered or
serialised against the switch?

[Severity: Medium]
Could this check also abort a connection with an honest peer?

diff comes from fin, which is snapshotted from local_tx_ctrl_fin at the
top of smc_switch_cursor(). unconfirmed comes from a later atomic_read()
of sndbuf_space.

smc_switch_cursor() runs only under conn->send_lock, which
smc_switch_conns() takes. smc_cdc_tx_handler() runs under bh_lock_sock()
and never takes send_lock. It also credits sndbuf_space before it updates
local_tx_ctrl_fin:

		atomic_add(diff, &cdcpend->conn->sndbuf_space);
		...
		smc_curs_copy(&conn->local_tx_ctrl_fin, &cdcpend->p_cursor,
			      conn);

Take an idle connection where prep == sent, the peer has consumed
everything (cons == prod), and the last CDC completion is still pending
on the old link, so fin < cons. If that completion's atomic_add() lands
between the fin snapshot and the atomic_read(), sndbuf_space becomes len
and unconfirmed becomes 0, while diff = cons - fin is still > 0.

The new branch then sets out_of_sync and peer_conn_abort and queues
abort_work during an ordinary link deletion. Doesn't that contradict "for
a correct peer neither path is reached" in the commit message?

The race between the switch and old-link completions existed before this
patch, where it double-credited sndbuf_space, and the changelog defers it.
Aborting a correct peer's connection is new with this check, though.

[Severity: Low]
Does this check catch every impossible cursor?

smc_cdc_cursor_to_host() accepts any larger wrap and does not check
cons.count against peer_rmbe_size. smc_curs_diff() treats any wrap
mismatch as exactly one wrap.

Take peer_rmbe_size = 100, fin = (0,90) and cons = (2,5). diff is 15,
which passes whenever 15 or more bytes are unconfirmed. Afterwards
prod = (1,5) and cons = (2,5), so smc_write_space() returns 0.
smc_tx_rdma_writes() then returns early on "rmbespace <= 0", and prod
stays a full wrap behind cons. That is the stalled state the commit
message gives as the reason not to cap diff.

diff is also in peer RMB units, but it is compared against a sndbuf
amount. When sndbuf_desc->len > peer_rmbe_size, a diff in
(peer_rmbe_size, unconfirmed] passes. smc_curs_add(conn->peer_rmbe_size,
&conn->local_tx_ctrl.prod, diff) subtracts the size only once, so
prod.count can stay at or above peer_rmbe_size. smc_tx_rdma_writes() then
uses it as the destination offset:

	dst_off = prod.count;
	if (prod.wrap == cons.wrap) {
		dst_len = min_t(size_t,
				conn->peer_rmbe_size - prod.count, len);

Here the subtraction wraps, and the RDMA write goes past the end of the
peer's RMBE.

The local sndbuf cursors stay in range in both cases, so only the
misbehaving peer's own connection is affected. Would also rejecting
cons.wrap > fin.wrap + 1 and diff > peer_rmbe_size make the check match
its stated rationale?

> +			conn->out_of_sync = 1;	/* prevent any further receives */
> +			conn->local_tx_ctrl.conn_state_flags.peer_conn_abort = 1;
> +			smc_wr_tx_put_slot(conn->lnk,
> +					   (struct smc_wr_tx_pend_priv *)pend);
> +			sock_hold(&smc->sk); /* sock_put in abort_work */
> +			if (!queue_work(smc_close_wq, &conn->abort_work))
> +				sock_put(&smc->sk);
> +			return 0;
> +		}

[Severity: Low]
Are the cursors really left alone on this abort path?
smc_switch_cursor() has already rewound them before the check:

	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);

The early return also skips the recalculation:

	atomic_set(&smc->conn.peer_rmbe_space, smc_write_space(conn));

conn->killed is set only later, when smc_conn_abort_work() runs
smc_conn_kill() after lock_sock(). smc_tx_sndbuf_nonempty() checks only:

	if (conn->killed ||
	    conn->local_rx_ctrl.conn_state_flags.peer_conn_abort) {

This path sets neither of those. It sets out_of_sync and the
local_tx_ctrl flag.

Until abort_work runs, could smc_tx_sendmsg(), smc_tx_pending() or the
release_cb path reach smcr_tx_sndbuf_nonempty() on the new link with the
rewound prod and a stale peer_rmbe_space? That would rewrite data that
was already sent at dst_off = fin.count, and send a CDC whose prod is
behind the peer's cons.

This conflicts with "and leave the cursors alone" and "Dropping the
connection has no such state to get wrong" in the commit message. Would
running the check before the cursors are rewound avoid it?

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261124173044.591937-1-piyus%40iiitd.ac.in
Technical Details
Message-ID: <179588838919.3135.9363376589664257773@kernel.org>
Path: mbox-mo1.pugleaf.net!srv.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-373255-linux-kernel-netdev=dewy.ru
References: <20261124173044.591937-1-piyus@iiitd.ac.in>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srv.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-373255-linux-kernel-netdev=dewy.ru
From: netdev-bot+sashiko@kernel.org
Newsgroups: linux.kernel.netdev
Subject: Re: [PATCH net v3] net/smc: drop the connection when the peer's
 failover cursor is impossible
Date: Sat, 28 Nov 2026 17:53:09 +0000
Organization: Usenet Network
Message-ID: <179588838919.3135.9363376589664257773@kernel.org>
References: <20261124173044.591937-1-piyus@iiitd.ac.in>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="1000368"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:AEwjKwHEsk/z7G7ZeDO45NxJrk4= sha256:WbT5SoF+GpV3IibNfQxXvAUOx2GIpprFy/yGk3TW510=
	sha1:XhfZLJr3SJqWh7sY8wCsUbn+mVw= sha256:me/6HXCT7EpCa9+n3RvU+YMEJCxNv8SKEB+w/jL99CY=
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 EE304125F87; Sat, 28 Nov 2026 20:53:33 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -3.4
X-Spam-Status: No, score=-3.4 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, URIBL_BLOCKED=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 sOHQXQuPea2Y;
	Sat, 28 Nov 2026 20:53:30 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-373255-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 sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10])
	by mail.dewy.ru (Postfix) with ESMTPS id C9F17125F84; Sat, 28 Nov 2026 20:53:21 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by sea.lore.kernel.org (Postfix) with ESMTP id E84EE28A2A; Sat, 28 Nov 2026 17:53:12 +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=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass;
	t=1795888391;
	b=yudWMlBdvAA1LtqL8+DoBtyihu79j/GkLuFCkkcjkz+3ml2hDBuEnuEEu0UHRd9SiUyf
	 vxyhiHXnYDYBTdtKmEydSlSAhMvUlsdYv3wxVyIl0UHMMMUf7OAWi35l+GuMw5tBwHWUX
	 //ZXoHLyQqvDC72K6iTV+2pnHNaonE6uV2fV7zGtJkMdZr1yYQljRkh4QO0z170V0/HgL
	 69QpEhHzntv9AlFmCGb2PFY2j58UAP+pF3kLIH91Ak8G3OSszeSc6EkHrm2O1yZt/EFzq
	 vhxNvI3RcNCsRFDPJuWvWYueQruxIe2u7m9r8gy6UmPAzIlcBNb5zYCD9C1R/y25FRA==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1795888391;
	h=X-Original-To:Received:Received:DKIM-Signature:Subject:From:To:Cc:
	 Date:Message-ID:In-Reply-To:References:X-sashiko-severity:
	 Content-Type:Content-Transfer-Encoding:X-Mailing-List:List-Id:
	 List-Post:List-Help:List-Subscribe:List-Unsubscribe:List-Owner:
	 Precedence:MIME-Version;
	bh=t58Hg6B9PUFx2JLjsNx/WVFf2xI3VnErF2dDmvHEpKM=;
	b=frow8RQC3015duaMCiozzlXDMV1RtKj+xQ2UTFkRlIWJRZToejs8RKtAMVtAYT8p/mnM
	 sOJJT/9u9bRiXtv3GkyorWPaaMIgtx4masP8bcvtkBc8HZ9gJJ1+sEssgXtuKk3z8efCY
	 LRRkvZey2DAC74xZPp5VEXIX3AbXoYkAy/8Iqh0QSqmKbqLCUwDqrh+cJ6HjnnjRSR+If
	 3r9krs2IK8N32uWCxH+Oox1wCbTFYNQJ/sN3cwlrXuEuKPO4veR/q1lbxuN7FbG6SQkMI
	 n1AQ5RBpRZIj9l+FSMh2XgT9AyZ2MYoIhgmx2E7/DYacpHFaZW31SJ6xK8QiTskC4Hw==
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="LeYPIL/o";
	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 D768C606A323;
	Sat, 28 Nov 2026 17:53: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=LeYPIL/o
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1795888391;
	b=lOfq+jOiqoP1JZ93VV/XFx/1WNWrof8l3S3gYD7kIuzZ+la5+FYIZu4C1cxSxb+QjWFt
	 07uqFJtvM6epmpeMq4fsMePrpjlmg1DbAqw3DMYssKgSIwT0A4p1yXdhJgCsSnYzMSmGK
	 odWTu/FVCG+BGGWaiX22Rz3uF4Njt5uzuIcE41UIahJmCBBe5pG/62M7vETkOGAFjTYFu
	 jrU/RdTXTMjXFMfJvVYrDMQHhb6nv8+gCZrENN2nkZsH/ivSqUTWwVzDPxjuNX7Ad6uYW
	 Ekp1Wzla7LTJYksRgxBxiTD8gO1Cp2TJOGZBffbXcbzv3htOIqUEhuy3/f2itBzT+Cg==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1795888391;
	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=t58Hg6B9PUFx2JLjsNx/WVFf2xI3VnErF2dDmvHEpKM=;
	b=Lc/Xoje/7bcdZQwq1BQJMsxdew94M3bK2u4a6+Y0UoCx6MH36sVAC5MqbCLcCNfGpmWs
	 KN1TGDKfdxI5qGEQVN/60BDadLb4LUiA3tC04lcyWirEQnwQ6iFjjTWiTGkATw8rQ9Kku
	 V2aW/0V/Vv09LNpWbWfnYHgdWw1FmcCjjdW5KLw4dlDzUh9eZZMcPLrniBq5izST4aCv7
	 gZgETz+JxUapUhw0rFZ/Aw6HdGn0PPNXl1zGcHW7IZWR6hqp3SGfnCEnVG9qCApOuRG11
	 bAnClcFYPyMK9nhBTDVpMv2khPdJAgidLU28svvnsWwgLStV5ZgFb/nfCClmK3PqalQ==
X-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="LeYPIL/o";
	arc=none 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 038DE606A329;
	Sat, 28 Nov 2026 17:53:10 +0000 (UTC)
X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id A6BF21F00923;
	Sat, 28 Nov 2026 17:53:09 +0000 (UTC)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org;
	s=k20260515; t=1795888390;
	bh=t58Hg6B9PUFx2JLjsNx/WVFf2xI3VnErF2dDmvHEpKM=;
	h=Subject:From:To:Cc:Date:In-Reply-To:References;
	b=LeYPIL/o77ze2i2P29FYMhUqZZShFs890EBnpnL+F72vXi+GBBwlRW7W+A/Z/V7+N
	 QJy8N5L/tTpDH+mXkka2x4EgDzCOO8BmQDh+Md18IJBbpq766+zIieKDyAbgQLPaXO
	 qRy+XmLLUlxqz3K5bH6x77rrwfySFdiUQwAtlIL4hqpt9uNjwaqkAOcs/JGSs5W5xJ
	 HBCUq5BEBt4qZeANuvX4jx1hJ8KcySZB5QVijTAMdIvyHXq4gqWkAcyQpewvuTNSm3
	 3mfOGeGGfunIDdQ/1vYjDuC/FrgyHALERgJOMYuWtGJxviiOb9XxUpTfKXyY8KRcOr
	 7T+Sr6MzdP4VQ==
X-Cc: wenjia@linux.ibm.com, jaka@linux.ibm.com, alibuda@linux.alibaba.com,
 tonylu@linux.alibaba.com, guwen@linux.alibaba.com, netdev@vger.kernel.org,
 linux-s390@vger.kernel.org, linux-kernel@vger.kernel.org, davem@davemloft.net,
 edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, horms@kernel.org,
 kapil@presceralabs.ai, stable@vger.kernel.org
X-In-Reply-To: <20261124173044.591937-1-piyus@iiitd.ac.in>
X-sashiko-severity: High
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