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=1796375720; b=4+1Mit/k1EEgBtp5pqrCVvFGOQkFNLiZGMV5kx+/26vJxOzE5H/quqoZ63nkriw+z7ms 5XMf4zZC3PFupcTM+bn+6hcWDb5dGT1Ix2FAHNVkv+b8X1RnlQ3n7ZYomT+UIS19MUJ+3 EMlr1x/LezlxCY+vjh3cSvDpTCfNlHP/z0pXETJjAzSAE7EmSxQxFpvjtSc+hwkMu+qC7 o1gLCkpoe8Zy8nqbWW7sW1Pk2t2ymVWdgpsEv0KUxLmcWHaktA/aECFa6ifd5J1wTQxGS z7xCdjl1ETvsAdZ2F6osOeOiY7i2I4OyL32HVsILew7NIDf1Mz6E3nUs29CoKQ6ZNnA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796375720; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=vOCePhcFBzxFRQa7fpjT/27XLCwgez9PefGX7IgSn3s=; b=yQ13ZFXV+Pyvfh0rkpLramfxnWyUpN3YumR94ujuupYz9ncIPmMMFRV9s/P1OuU/x702 qD/NP9V99P+Q6p5+sdAM3gU/mZa2vVCCZwcSXXkDFbfU07VZhmMxLEwxWDb1jIPQz/1SQ ff37I3wCRl+sUznoXU9SaUwcEE9EgfIKgbM0EBXk3dAnlArwSp8TUSt5C+Ygny/Zt7xox bG3Fr1dTXM8yPRjRGjIJ926u3eCn/7uAXEgK9qqGw7D82U0FUJ8PHc4VZebQmgQCgxf9W NdL+7KcoM8XH2mMMNLM0rm7T3wQErujVgJ6S6XKD5QBHKu56RjCRGharc0dDtaRk88g== 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=K5kB3pfF; 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 2F57C606A32C; Fri, 4 Dec 2026 09:15:19 +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=K5kB3pfF Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0371B1F000CE; Fri, 4 Dec 2026 09:15:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796375719; bh=vOCePhcFBzxFRQa7fpjT/27XLCwgez9PefGX7IgSn3s=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=K5kB3pfFJnl6zT84ldFOd/L59HxWebma0bT/LKX7PLGbZZO0uTf+XuwvNzhVRyOnL dDJ2sry1xeN2qBteyKh8bVU5qC+DxS6KOxD85VA4M4azfDItc0SkLXBZKE5Wyc8Is9 gUXA1YGZwjm4XdLeWOj/8wIE3wvpoyr5n3fc3pERErzF6V/O88UzBBDpwvBYun72kc 6zHTjHaMpDwpAwSDX61oD95OS1cGs09w/z8E32wdUlg/BFV5WOQTQ3vyV0LZNFZX4j +2TFTx0XQwIXqO6Ye8lqnQSg9mH4Zxv+SlaCQ14OYxqTUFcsf2AJl6TUKIvKfTFCmL 9ZK/priIMlDoA== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH net v3 2/7] net/smc: do not credit stale CDC completions after a link switch Reply-To: sashiko-reviews@lists.linux.dev To: "Bryam Vargas" Cc: linux-rdma@vger.kernel.org, linux-s390@vger.kernel.org, "Heiko Carstens" , "Vasily Gorbik" , "Alexander Gordeev" , "Christian Borntraeger" In-Reply-To: <20261203-b4-disp-ba1ad55e-v3-2-6834ff90c5d0@proton.me> References: <20261203-b4-disp-ba1ad55e-v3-0-6834ff90c5d0@proton.me> <20261203-b4-disp-ba1ad55e-v3-2-6834ff90c5d0@proton.me> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Fri, 04 Dec 2026 09:15:17 +0000 X-Mailing-List: linux-rdma@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list 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 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_p= riv *pnd_snd, > sndbuf_desc =3D conn->sndbuf_desc; > smc =3D 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 =3D=3D conn->tx_switch_gen && > + smc_curs_sdiff(sndbuf_desc->len, &conn->tx_curs_fin, > + &cdcpend->cursor) >=3D 0) { > diff =3D 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 >= =3D 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 >=3D 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. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261203-b4-disp-ba= 1ad55e-v3-0-6834ff90c5d0@proton.me?part=3D2