Netdev List
 help / color / mirror / Atom feed
From: netdev-bot+sashiko@kernel.org
To: piyus@iiitd.ac.in
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
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	[thread overview]
Message-ID: <179540776852.3135.18298742575411764997@kernel.org> (raw)
In-Reply-To: <20261122042120.2430434-1-piyus@iiitd.ac.in>

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

      parent reply	other threads:[~2026-11-23  4:22 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-22  4:21 [PATCH net v2] net/smc: validate the peer's CDC cursors against our own buffers Piyus Kedia
2026-11-22 13:39 ` Dust Li
2026-11-22 14:06   ` Piyus Kedia
2026-11-23  4:22 ` netdev-bot+sashiko [this message]

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=179540776852.3135.18298742575411764997@kernel.org \
    --to=netdev-bot+sashiko@kernel.org \
    --cc=alibuda@linux.alibaba.com \
    --cc=dust.li@linux.alibaba.com \
    --cc=guwen@linux.alibaba.com \
    --cc=kapil@presceralabs.ai \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-rdma@vger.kernel.org \
    --cc=linux-s390@vger.kernel.org \
    --cc=mjambigi@linux.ibm.com \
    --cc=netdev@vger.kernel.org \
    --cc=piyus@iiitd.ac.in \
    --cc=sidraya@linux.ibm.com \
    --cc=tonylu@linux.alibaba.com \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox