Article View: linux.kernel.netdev
Article #20707Re: [PATCH net v2] net/smc: validate the peer's CDC cursors against our own buffers
From: netdev-bot+sashiko
Date: Mon, 23 Nov 2026 04:22
Date: Mon, 23 Nov 2026 04:22
256 lines
17518 bytes
17518 bytes
Thank you for your contribution! Sashiko AI review found 6 potential
issue(s) to consider.
Critical: 0 · High: 1 · Medium: 0 · Low: 5
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] The fix is incomplete.
- [Low] The new validators use `>` and accept count == buffer length.
- [Low] The commit fixes remotely triggerable KASAN-confirmed faults: an
out-of-bounds RMB read whose bytes reach userspace via recvmsg(), plus…
- [Low] The From: author is Piyus Kedia, but the first Signed-off-by is
Kapil Vaswani, with no matching Co-developed-by: tag.
- [Low] smcd_cdc_cursors_invalid() starts with `if (!conn->rmb_desc)
return true;`.
- [Low] The new comment in smcd_cdc_rx_tsklet() says the check guards the
consumer-cursor credit to sndbuf_space under DMB-nocopy.
--
net/smc: validate the peer's CDC cursors against our own buffers
This commit checks the producer and consumer cursors in incoming CDC
messages, in smc_cdc_rx_handler() for SMC-R and smcd_cdc_rx_tsklet() for
SMC-D. A message is dropped if a cursor count is larger than
rmb_desc->len (producer) or peer_rmbe_size (consumer). The goal is to
stop out-of-bounds reads in the urgent data, recvmsg() and splice()
paths.
> Signed-off-by: Kapil Vaswani <kapil@presceralabs.ai>
> Signed-off-by: Piyus Kedia <piyus@iiitd.ac.in>
[Severity: Low]
This patch fixes out-of-bounds reads that a remote peer can trigger on
both SMC-R and SMC-D. There is no Fixes: tag and no Cc: stable.
Could Fixes: tags be added? The SMC-R path probably goes back to the
original CDC receive code. The SMC-D path probably goes back to the
commit that added SMC-D CDC receive. So two tags may be needed.
[Severity: Low]
The author is Piyus Kedia, but the first Signed-off-by is Kapil Vaswani,
and there is no Co-developed-by: tag.
Documentation/process/submitting-patches.rst lists a co-author with
Co-developed-by: immediately followed by their Signed-off-by. Otherwise
the Signed-off-by order should follow how the patch was handled.
Should this be Co-developed-by: plus Signed-off-by? If Kapil reported or
analysed the issue, Reported-by: or Suggested-by: may fit better.
> diff --git a/net/smc/smc_cdc.c b/net/smc/smc_cdc.c
> index 32d6d03df3214..8d24e0c839260 100644
> --- a/net/smc/smc_cdc.c
> +++ b/net/smc/smc_cdc.c
> @@ -433,6 +433,18 @@ static void smc_cdc_msg_recv(struct smc_sock *smc, struct smc_cdc_msg *cdc)
> sock_put(&smc->sk); /* no free sk in softirq-context */
> }
>
> +static bool smcd_cdc_cursors_invalid(struct smc_connection *conn,
> + struct smcd_cdc_msg *cdc)
> +{
> + if (!conn->rmb_desc)
> + return true;
> + if (cdc->prod.count > (u32)conn->rmb_desc->len)
> + return true;
[Severity: High]
Is checking only the count field enough to keep bytes_to_rcv within
rmb_desc->len? Neither this check nor the one in
smcr_cdc_cursors_invalid() looks at wrap. Neither looks at how far the
cursor moved since the previous message.
When the wraps differ, smc_curs_diff() can return up to twice the
buffer size:
net/smc/smc_cdc.h:smc_curs_diff() {
if (old->wrap != new->wrap)
return max_t(int, 0,
((size - old->count) + new->count));
...
}
On SMC-R, smc_cdc_cursor_to_host() rejects only backward wrap moves, and
the peer controls seqno. On SMC-D, smcd_cdc_msg_to_host() has no
ordering check at all.
Take an RMB of length L, with prod starting at {wrap 0, count 0}. A peer
could send:
prod {wrap 1, count L} -> passes, diff_prod = 2L
prod {wrap 2, count L} -> passes, diff_prod = L
smc_cdc_msg_recv_action() then adds both with no cap:
atomic_add(diff_prod, &conn->bytes_to_rcv);
/* guarantee 0 <= bytes_to_rcv <= rmb_desc->len */
That leaves bytes_to_rcv at 3L. In smc_rx_recvmsg(), only the first
chunk is clamped to rmb_desc->len - cons.count. The remainder is used
as-is:
chunk_len = copylen - chunk_len; /* remainder */
chunk_len_sum += chunk_len;
chunk_off = 0; /* modulo offset in recv ring buffer */
The second chunk would then be 2L bytes from offset 0. memcpy_to_msg()
would copy L bytes past the RMB to userspace.
splice() gets the same oversized chunk in smc_rx_splice(). Past the end
of the RMB, vmalloc_to_page() can return NULL, and get_page()
dereferences it.
Using >= instead of > does not change this. {1, L-1} followed by
{2, L-1} still gives 3L-1.
The consumer side looks similar. diff_cons is added to peer_rmbe_space
with no cap. Under DMB-nocopy, diff_tx is added to sndbuf_space with no
cap either.
smc_tx_sendmsg() uses the same unclamped second-chunk pattern. An
inflated sndbuf_space could therefore become a write past
sndbuf_desc->len. smc_tx_rdma_writes() can also size dst_len from an
inflated peer_rmbe_space. DMB-nocopy is only used by loopback-ism today,
which narrows this part.
Given this, does this statement in the commit message hold?
"Validate both cursors where each transport accepts the message, so
that one test per transport covers every consumer."
Would a relational bound work better? For example, reject a prod that is
more than rmb_desc->len ahead of local_tx_ctrl.cons (via
smc_curs_comp()). Or reject when bytes_to_rcv + diff_prod would exceed
rmb_desc->len.
For cons, the new value could be required to lie between the previous
cons and our sent producer cursor. Wrap jumps greater than 1 could also
be rejected. Together these would bound the credit side.
> + if (cdc->cons.count > (u32)conn->peer_rmbe_size)
> + return true;
> + return false;
> +}
> +
[ ... ]
> @@ -452,6 +464,15 @@ static void smcd_cdc_rx_tsklet(struct tasklet_struct *t)
> data_cdc = (struct smcd_cdc_msg *)conn->rmb_desc->cpu_addr;
> smcd_curs_copy(&cdc.prod, &data_cdc->prod, conn);
> smcd_curs_copy(&cdc.cons, &data_cdc->cons, conn);
> + /* This CDC was written by the peer into the DMB we published to it, so
> + * both cursors are peer-supplied and index buffers described on this
> + * side. Nothing else checks them, and smc_cdc_msg_recv_action() uses
> + * the producer cursor as a receive length and the consumer cursor to
> + * credit sndbuf_space - which under DMB-nocopy is the memory the peer
> + * itself owns. Unlike the SMC-R path these values are host order.
> + */
[Severity: Low]
This comment says the check protects the consumer cursor's credit to
sndbuf_space under DMB-nocopy. smc_cdc_msg_recv_action() computes that
credit against sndbuf_desc->len:
diff_tx = smc_curs_diff(conn->sndbuf_desc->len,
&conn->tx_curs_fin,
&conn->local_rx_ctrl.cons);
smcd_cdc_cursors_invalid() bounds cons.count by peer_rmbe_size instead.
The two lengths come from different places. peer_rmbe_size comes from
the DMBE size advertised in CLC. sndbuf_desc->len is set in
smcd_buf_attach() from the dmb_len that attach_dmb returns.
If those two ever differ, could a cons.count that passes this check
exceed sndbuf_desc->len and reach tx_curs_fin and the sndbuf_space
arithmetic?
Conforming in-kernel peers produce equal values, so this is mostly about
the comment. Even when the lengths match, the check does not bound the
accumulated sndbuf_space credit. The comment seems to promise more than
the check does.
> + if (smcd_cdc_cursors_invalid(conn, &cdc))
> + return;
[Severity: Low]
This isn't a functional problem, but the NULL test at the start of
smcd_cdc_cursors_invalid() can never fire on this path:
if (!conn->rmb_desc)
return true;
smcd_cdc_rx_tsklet() has already dereferenced conn->rmb_desc->cpu_addr
and read both cursors from it before it calls the helper.
Should the test be dropped? If rmb_desc really can be NULL here, should
the test move ahead of the dereference?
> smc = container_of(conn, struct smc_sock, conn);
> smc_cdc_msg_recv(smc, (struct smc_cdc_msg *)&cdc);
> }
[ ... ]
> +static bool smcr_cdc_cursors_invalid(struct smc_connection *conn,
> + struct smc_cdc_msg *cdc)
> +{
> + if (!conn->rmb_desc)
> + return true;
> + if (ntohl(cdc->prod.count) > (u32)conn->rmb_desc->len)
> + return true;
[Severity: Low]
The commit message says:
"A cursor equal to the buffer length is legitimate (a full ring), so
only a larger one is rejected."
Is that how cursors are actually encoded? smc_curs_add() normalises
every cursor so that count stays below size:
net/smc/smc_cdc.h:smc_curs_add() {
curs->count += value;
if (curs->count >= size) {
curs->wrap++;
curs->count -= size;
}
}
The senders put that host cursor on the wire unchanged. A conforming
peer therefore always sends a count in [0, size). A full ring shows up
as a wrap difference, not as count == size.
Should this check, the cons check below it, and the two checks in
smcd_cdc_cursors_invalid() use >= instead?
Accepting count == len lets in a value that only a non-conforming peer
can send. It then lands in local_rx_ctrl.prod/cons, urg_curs and, under
DMB-nocopy, tx_curs_fin. It also allows the single-message credit of
2 * size from smc_curs_diff() described above. Changing this alone would
not fix the accumulation problem, though.
> + if (ntohl(cdc->cons.count) > conn->peer_rmbe_size)
> + return true;
> + return false;
> +}
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261122042120.2430434-1-piyus%40iiitd.ac.in
Technical Details
Message-ID:
<179540776852.3135.18298742575411764997@kernel.org>Path:
mbox-mo1.pugleaf.net!news-wdc.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-369022-linux-kernel-netdev=dewy.ruReferences:
<20261122042120.2430434-1-piyus@iiitd.ac.in>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-wdc.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-369022-linux-kernel-netdev=dewy.ru From: netdev-bot+sashiko@kernel.org Newsgroups: linux.kernel.netdev Subject: Re: [PATCH net v2] net/smc: validate the peer's CDC cursors against our own buffers Date: Mon, 23 Nov 2026 04:22:48 +0000 Organization: Usenet Network Message-ID: <179540776852.3135.18298742575411764997@kernel.org> References: <20261122042120.2430434-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="3788786"; mail-complaints-to="abuse@usenet.network" Cancel-Lock: sha1:jMGxrG3UeDbsFQ2vjNK2yOM7TxY= sha256:42FU/Udz/QAu58E8LupHUZmxoSC4FEqAePyJRgBSElg= sha1:hS2igxAT7O42PsqLa4lmBiBTQ9A= sha256:7cTghUCC2hE+nioy7A2Brmib/TMoffYjXOrzBNGqFOU= 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 134A4125D83; Mon, 23 Nov 2026 07:23:12 +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 MkMUPiitZE6n; Mon, 23 Nov 2026 07:23:07 +0300 (MSK) X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-369022-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 2E364125D8C; Mon, 23 Nov 2026 07:22:58 +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 33A1929237; Mon, 23 Nov 2026 04:22:56 +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=1795407776; b=r+FontAnR7W/5FUDxMKVWuIfNE31tqAgNJl1E33sShBgxilEgEXTJbiNLxcmSYamUt0O BgIV3f9NiDaiVnuv2tPrq2Fv1J3EvL77ap7xmr2DS4IGje+wk8AK0D3pU0jXXxorOITKp ULwV3EvS5KuXJyeQ7wCwdmh7ijWt1iO9ISeYHE+t8MejtxaFArluU1Qg4AI9IJF2UPnps 2vkVH+Umu93dV9yzU2Lsy0kYpNWxglivyNnKj7dY6nsqZ8BeBQlpCoLCGCF/OokJNsfCo Xs+Vns1cZsNKhFqyimEIsQFSuNoRfA8f1sZ2ts8ZQSp8xUFvosABRD5lkwc4/XUkl4w== X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795407776; 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=iUaYkVElwHXmOSgYzkznsrZDmTk+0hZ8WoKAJqfKpZw=; b=ZLCdSpCxPHu/0xsENw0gD/OI7THxbMaS7HSBGy6HjxbQTUoVfnhK8ybXxpCZ+AQZnFdG Wnm/6xDEWOo7QyXZP/hHIFgpEdQBU9QlGvXLqWNHxTSd95c/5bJ02sI3NMW2dhW8gl5Mk 6+A6lPnb/+6hd2OoBDOzbpl4JeTUemClTnMQfr7Rs9cuROqwLJakavyHvnmHzq4mKZhOK CO+JsGDChx5VGnjvTDYedxxhHDmPt90pxlSi70ruA7KtZyMXYySc1Qbzra1eA12P4ATEP oSa1QOL/1nQSfEfY2aUq2p+DqVBdXkI8vWWUZuonYG64PFN0KCPKe58zLXS6gd/RH6g== 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=oY7e1YEi; 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 0B4E2606A32E; Mon, 23 Nov 2026 04:22:56 +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=oY7e1YEi 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=1795407770; b=mdGRVrfeLjJI2LcJ39wVgL1nJVW8JTwkkumFBzn6FuTnMqGULY06eOWFzS/oXOVwnwWP 0Z1ufc3KDzSjiGvuwJHUhEb0n72/UkD8RiBQDqb0STly5vyTAFD2aXc1surE5q0Ml1vpP M1TfoEJJeBriobkDs8t5IGsx4Bonqui3D1a39f8kYcvJzM8ui4Oe9DrdQOe8luNZWCmlO OSaqtQ4GemTmLSy1aUzjeV7vS3B5kA+2sCwTkXHNFbg20VMs1rs1lC71vMhA2FyxVCiTe cec6MGSjBuPe+KVcV19AYvcK+KwMQQzFfOfu5lRoQOgg6kh7lMkcRMEmOKhewji7U0g== X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795407770; 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=iUaYkVElwHXmOSgYzkznsrZDmTk+0hZ8WoKAJqfKpZw=; b=s6cv0IevklkhKL2dEC7RZgRyUB7xjxz2npVh/mzK6gfk08HVepsl11C1kQ085wluI+/g Drrqn4HwJlxfiLIgUq8AQtQePkXwIt8cTBYHfnirOdYozCq7gHKaLHma4JCi/4pxxBmTj ekoH+VZnXpZHF2pq2cSwg46du78JBcHR+nl8PpQtMoKH2p6RlbWfObtOJzsL20stWLpZS NS4Z0o2X4pU03q6/SDPHN9+5Jr091k1U2LKSQqawqakne/rY+7snu1O8zKTXR7TY9BRKI ZwKMClJmNp0doAKM/DZM+aYswGLsJDyVOShZLNQ3SdAkAYuojaiowYoTvXotU3EzlCQ== 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=oY7e1YEi; 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 271B1606A31A; Mon, 23 Nov 2026 04:22:49 +0000 (UTC) X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0CD371F000C6; Mon, 23 Nov 2026 04:22:48 +0000 (UTC) X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1795407769; bh=iUaYkVElwHXmOSgYzkznsrZDmTk+0hZ8WoKAJqfKpZw=; h=Subject:From:To:Cc:Date:In-Reply-To:References; b=oY7e1YEihc8egQNKXPT3/Igp5Siys9HKKhLv2PGAi5SdqdkkhJ/XM59sfO5ETNoBB UjrntvtSorg+k6TzuKWkuk3a9IPfdR88EcJ8tVWsyK6O86xaKmbtmxeZry/u8tD39R mrR+OsKgdrNG2aBiCP0ABZhlV17pX2JPMZfp8LEyDBj8QshaFv0JilCAlMxppj6RAl 10rYQLKKbzDYxr4Gyn0bzTf2f2G/HTcdXMx/5fYHeuTlPfnLstyLPLw/EeCSRAQNgb RG6IMoky67K/qWCX/v9CQMlDQA2/OgVedooifPRTNa5OSwEbeCneriSRE2XIOnnCqw 412xiWrB/cmmw== X-Cc: alibuda@linux.alibaba.com, dust.li@linux.alibaba.com, sidraya@linux.ibm.com, mjambigi@linux.ibm.com, netdev@vger.kernel.org, tonylu@linux.alibaba.com, guwen@linux.alibaba.com, linux-rdma@vger.kernel.org, linux-s390@vger.kernel.org, linux-kernel@vger.kernel.org, kapil@presceralabs.ai, kuba@kernel.org X-In-Reply-To: <20261122042120.2430434-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