From: sashiko-bot@kernel.org
To: "Bryam Vargas" <hexlabsecurity@proton.me>
Cc: "Alexander Gordeev" <agordeev@linux.ibm.com>,
"Vasily Gorbik" <gor@linux.ibm.com>,
linux-s390@vger.kernel.org, "Heiko Carstens" <hca@linux.ibm.com>
Subject: Re: [PATCH net v4 1/3] net/smc: bound the wire-controlled producer cursor to the RMB
Date: Mon, 06 Jul 2026 07:54:16 +0000 [thread overview]
Message-ID: <20260706075417.5A03E1F00A3D@smtp.kernel.org> (raw)
In-Reply-To: <20260705-b4-disp-28a1bbca-v4-1-be089b98acc6@proton.me>
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
Pre-existing issues:
- [Critical] The SMC connection creation path publishes the connection to the link group tree before allocating its receive buffer (`rmb_desc`), creating a race condition where an incoming CDC message can cause a NULL pointer dereference (kernel panic) when accessing `conn->rmb_desc->len`.
- [Critical] The SMC-R asynchronous CDC receive handler looks up a connection from the link group tree but drops the lock without taking a reference, leading to a Use-After-Free if the socket is closed concurrently.
--
commit 16f4df4f224b2fdaeabbac3f231259cdff8766a6
Author: Bryam Vargas <hexlabsecurity@proton.me>
net/smc: bound the wire-controlled producer cursor to the RMB
This commit bounds the producer cursor count to the receive buffer length
at the wire-to-host conversion for SMC-R and SMC-D. This prevents
out-of-bounds reads during urgent data handling.
> diff --git a/net/smc/smc_cdc.h b/net/smc/smc_cdc.h
> index 696cc11f2303b..ca76ef6303566 100644
> --- a/net/smc/smc_cdc.h
> +++ b/net/smc/smc_cdc.h
[ ... ]
> @@ -246,8 +256,13 @@ static inline void smcr_cdc_msg_to_host(struct smc_host_cdc_msg *local,
> local->len = peer->len;
> local->seqno = ntohs(peer->seqno);
> local->token = ntohl(peer->token);
> - smc_cdc_cursor_to_host(&local->prod, &peer->prod, conn);
> - smc_cdc_cursor_to_host(&local->cons, &peer->cons, conn);
> + /* bound the wire-controlled producer cursor to our RMB (used as a raw
> + * index by the urgent path); leave the consumer cursor unbounded -- it
> + * indexes the peer's RMB and is bounded by peer_rmbe_size.
> + */
> + smc_cdc_cursor_to_host(&local->prod, &peer->prod, conn,
> + conn->rmb_desc->len);
[Severity: Critical]
This isn't a bug introduced by this patch, but does this create a risk of a
NULL pointer dereference if the connection receives a CDC message before the
buffer is allocated?
Looking at the connection creation path, the connection is published to the
link group tree before allocating its receive buffer:
net/smc/smc_core.c:smc_conn_create() {
...
rc = smc_lgr_register_conn(conn, true);
...
}
If a remote peer sends a CDC message to this connection's token before
smc_buf_create() completes, could the asynchronous handler process it and
dereference conn->rmb_desc->len while conn->rmb_desc is still NULL?
The pre-existing code also unconditionally dereferences this in
smc_cdc_msg_recv_action() via:
diff_prod = smc_curs_diff(conn->rmb_desc->len, &prod_old, ...);
Could we safely ensure rmb_desc is allocated before it gets accessed in
these paths?
> + smc_cdc_cursor_to_host(&local->cons, &peer->cons, conn, 0);
> local->prod_flags = peer->prod_flags;
> local->conn_state_flags = peer->conn_state_flags;
> }
[Severity: Critical]
This is a pre-existing issue, but looking at the surrounding CDC receive
path, is there a potential use-after-free when handling asynchronous
messages?
In the receive handler, the connection is retrieved using smc_lgr_find_conn()
under a read lock, but the lock is dropped without taking a reference on
the socket:
net/smc/smc_cdc.c:smc_cdc_rx_handler() {
...
read_unlock_bh(&lgr->conns_lock);
if (!conn || conn->out_of_sync)
return;
smc = container_of(conn, struct smc_sock, conn);
...
smc_cdc_msg_recv(smc, cdc);
}
If a local process concurrently closes the socket via smc_conn_free(), which
removes the connection and drops the final reference, could the socket be
freed before smc_cdc_msg_recv() executes and calls sock_hold()?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260705-b4-disp-28a1bbca-v4-0-be089b98acc6@proton.me?part=1
next prev parent reply other threads:[~2026-07-06 7:54 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-05 7:54 [PATCH net v4 0/3] net/smc: bound wire-controlled CDC cursors against the local buffers Bryam Vargas via B4 Relay
2026-07-05 7:54 ` [PATCH net v4 1/3] net/smc: bound the wire-controlled producer cursor to the RMB Bryam Vargas via B4 Relay
2026-07-06 7:54 ` sashiko-bot [this message]
2026-07-05 7:54 ` [PATCH net v4 2/3] net/smc: bound the receive length to the RMB in smc_rx_recvmsg() Bryam Vargas via B4 Relay
2026-07-06 7:54 ` sashiko-bot
2026-07-05 7:54 ` [PATCH net v4 3/3] net/smc: bound the send length to the send buffer in smc_tx_sendmsg() Bryam Vargas via B4 Relay
2026-07-06 7:54 ` sashiko-bot
2026-07-07 9:29 ` [PATCH net v4 0/3] net/smc: bound wire-controlled CDC cursors against the local buffers Dust Li
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=20260706075417.5A03E1F00A3D@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=agordeev@linux.ibm.com \
--cc=gor@linux.ibm.com \
--cc=hca@linux.ibm.com \
--cc=hexlabsecurity@proton.me \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox