All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Bryam Vargas" <hexlabsecurity@proton.me>
Cc: linux-rdma@vger.kernel.org, linux-s390@vger.kernel.org,
	"Heiko Carstens" <hca@linux.ibm.com>,
	"Vasily Gorbik" <gor@linux.ibm.com>,
	"Alexander Gordeev" <agordeev@linux.ibm.com>,
	"Christian Borntraeger" <borntraeger@linux.ibm.com>
Subject: Re: [PATCH net v3 2/7] net/smc: do not credit stale CDC completions after a link switch
Date: Fri, 04 Dec 2026 09:15:17 +0000	[thread overview]
Message-ID: <sashiko-outbox-249474@kernel.org> (raw)
In-Reply-To: <20261203-b4-disp-ba1ad55e-v3-2-6834ff90c5d0@proton.me>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Critical] net/smc: stale CDC completion wraparound overflows
  sndbuf_space
--

commit 9ac2c46d0b76eff999e2445956bc66d5ca01126d
Author: Bryam Vargas <hexlabsecurity@proton.me>

net/smc: do not credit stale CDC completions after a link switch

This commit adds a tx_switch_gen counter to struct smc_connection that
smc_switch_cursor() increments, and checks both the generation and a signed
cursor difference in smc_cdc_tx_handler() before crediting sndbuf_space.

> 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 on the old link still wrap smc_curs_sdiff() and
overflow conn->sndbuf_space for an SMC_APPCLOSEWAIT1 socket?

In smc_switch_conns(), an SMC_APPCLOSEWAIT1 socket is moved to the new link
without calling smc_switch_cursor(), so conn->tx_switch_gen is not bumped.
Unlike the other closing states, smc_sendmsg() still permits unlimited local
sends in SMC_APPCLOSEWAIT1.

A remote peer can half-close its write side, withhold receive WQEs on the
old link (where SMC-R QPs use infinite RNR retries while link deletion waits
in smc_wr_tx_wait_no_pending_sends()), and trigger a link switch. Once 32768
send-buffer rings complete on the new link (512 MiB for a 16 KiB buffer),
tx_curs_fin.wrap is 32768 ahead of the stale cdcpend->cursor.wrap.

When that stale completion arrives, switch_gen still matches and the s16
cast in smc_curs_sdiff() flips the wrap difference to positive, passing >= 0
with no upper bound. smc_curs_diff() then adds up to 2 * sndbuf_desc->len - 1
bytes to conn->sndbuf_space and rewinds tx_curs_fin.

On the next smc_tx_sendmsg(), writespace exceeds sndbuf_desc->len, so the
second chunk's memcpy_from_msg() writes past the end of
sndbuf_desc->cpu_addr and causes a kernel out-of-bounds write, while
smc_curs_add() leaves tx_curs_prep.count >= sndbuf_desc->len.

An upper bound check on smc_curs_sdiff() alone would still be bypassed after
65536 rings when the u16 wrap counter aliases back to 0; bumping
tx_switch_gen (or rejecting completions from the old link) for
SMC_APPCLOSEWAIT1 switches would invalidate prior-link completions.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261203-b4-disp-ba1ad55e-v3-0-6834ff90c5d0@proton.me?part=2

  reply	other threads:[~2026-12-04  9:15 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-03  9:15 [PATCH net v3 0/7] net/smc: fix the failover cursor switch and wrap rollover Bryam Vargas via B4 Relay
2026-12-03  9:15 ` Bryam Vargas
2026-12-03  9:15 ` [PATCH net v3 1/7] net/smc: take the socket spinlock across the failover cursor switch Bryam Vargas via B4 Relay
2026-12-03  9:15   ` Bryam Vargas
2026-12-03  9:15 ` [PATCH net v3 2/7] net/smc: do not credit stale CDC completions after a link switch Bryam Vargas via B4 Relay
2026-12-03  9:15   ` Bryam Vargas
2026-12-04  9:15   ` sashiko-bot [this message]
2026-12-04  9:49   ` netdev-bot+sashiko
2026-12-03  9:15 ` [PATCH net v3 3/7] net/smc: store each cursor once in smc_switch_cursor() Bryam Vargas via B4 Relay
2026-12-03  9:15   ` Bryam Vargas
2026-12-04  9:15   ` sashiko-bot
2026-12-03  9:15 ` [PATCH net v3 4/7] net/smc: fix the failover catch-up across the cursor wrap rollover Bryam Vargas via B4 Relay
2026-12-03  9:15   ` Bryam Vargas
2026-12-04  9:15   ` sashiko-bot
2026-12-03  9:15 ` [PATCH net v3 5/7] net/smc: order the urgent mark " Bryam Vargas via B4 Relay
2026-12-03  9:15   ` Bryam Vargas
2026-12-04  9:15   ` sashiko-bot
2026-12-03  9:15 ` [PATCH net v3 6/7] net/smc: update the urgent state under the socket spinlock Bryam Vargas via B4 Relay
2026-12-03  9:15   ` Bryam Vargas
2026-12-04  9:15   ` sashiko-bot
2026-12-04  9:49   ` netdev-bot+sashiko
2026-12-03  9:15 ` [PATCH net v3 7/7] net/smc: skip the urgent byte when it is the next unread byte Bryam Vargas via B4 Relay
2026-12-03  9:15   ` Bryam Vargas
2026-12-04  9:49   ` netdev-bot+sashiko
2026-12-04  9:15 ` [PATCH net v3 0/7] net/smc: fix the failover cursor switch and wrap rollover sashiko-bot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=sashiko-outbox-249474@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=agordeev@linux.ibm.com \
    --cc=borntraeger@linux.ibm.com \
    --cc=gor@linux.ibm.com \
    --cc=hca@linux.ibm.com \
    --cc=hexlabsecurity@proton.me \
    --cc=linux-rdma@vger.kernel.org \
    --cc=linux-s390@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.