Linux RDMA and InfiniBand development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Bryam Vargas" <hexlabsecurity@proton.me>
Cc: linux-s390@vger.kernel.org, linux-rdma@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/2] net/smc: do not reuse the DMB of a nocopy device
Date: Sun, 29 Nov 2026 15:05:27 +0000	[thread overview]
Message-ID: <sashiko-outbox-239731@kernel.org> (raw)
In-Reply-To: <20261128-b4-disp-2c190c90-v3-2-c566f64196c8@proton.me>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [High] net/smc: stale rmb_desc and sndbuf_desc in smc_buf_unuse() and
  smc_conn_free()
--

commit 983dbaf62d65e0621212eee027d711a6e8acfec1
Author: Bryam Vargas <hexlabsecurity@proton.me>

net/smc: do not reuse the DMB of a nocopy device

This commit unregisters and frees the RMB descriptor on DMB-nocopy SMC-D
devices when a connection ends instead of returning it to the link group
pool, and clears conn->rmb_desc when the link group is off its list.

> diff --git a/net/smc/smc_core.c b/net/smc/smc_core.c
> index a3164201c1420..509fc4c17bb8a 100644
> --- a/net/smc/smc_core.c
> +++ b/net/smc/smc_core.c
> @@ -1243,6 +1243,22 @@ static void smcd_buf_detach(struct smc_connection *conn)
>  	kfree(buf_desc);
>  }
>  
> +/* With DMB nocopy the peer writes into the RMB through its own
> + * attachment, which can outlive this connection: unregister the DMB
> + * instead of pooling it, so the next connection gets a new one.
> + */
> +static void smcd_rmb_drop(struct smc_connection *conn,
> +			  struct smc_link_group *lgr)
> +{
> +	struct smc_buf_desc *rmb_desc = conn->rmb_desc;
> +
> +	down_write(&lgr->rmbs_lock);
> +	smc_lgr_buf_list_del(lgr, true, rmb_desc);
> +	up_write(&lgr->rmbs_lock);
> +	WRITE_ONCE(conn->rmb_desc, NULL);
> +	smc_buf_free(lgr, true, rmb_desc);
> +}
> +
>  static void smc_buf_unuse(struct smc_connection *conn,
>  			  struct smc_link_group *lgr)
>  {
> @@ -1266,8 +1282,13 @@ static void smc_buf_unuse(struct smc_connection *conn,
>  			smcr_buf_unuse(conn->rmb_desc, true, lgr);
>  		} else {
>  			bufsize += sizeof(struct smcd_cdc_msg);
> -			memzero_explicit(conn->rmb_desc->cpu_addr, bufsize);
> -			WRITE_ONCE(conn->rmb_desc->used, 0);
> +			if (smc_ism_support_dmb_nocopy(lgr->smcd)) {
> +				smcd_rmb_drop(conn, lgr);
> +			} else {
> +				memzero_explicit(conn->rmb_desc->cpu_addr,
> +						 bufsize);
> +				WRITE_ONCE(conn->rmb_desc->used, 0);
> +			}
>  		}
>  		SMC_STAT_RMB_SIZE(smc, is_smcd, true, false, bufsize);
>  	}
> @@ -1306,6 +1327,8 @@ void smc_conn_free(struct smc_connection *conn)
>  	 */
>  	if (!list_empty(&lgr->list))
>  		smc_buf_unuse(conn, lgr); /* allow buffer reuse */
> +	else if (lgr->is_smcd && smc_ism_support_dmb_nocopy(lgr->smcd))
> +		WRITE_ONCE(conn->rmb_desc, NULL); /* freed with the lgr */

[Severity: High]
Can leaving conn->rmb_desc and conn->sndbuf_desc set when a non-nocopy link
group is unused or freed cause a use-after-free or double free if a retried
handshake switches to a DMB-nocopy link group?

If a first handshake attempt on a non-nocopy SMC-R or SMC-D link group
allocates conn->sndbuf_desc and conn->rmb_desc in smc_buf_create() and then
aborts via smc_conn_abort() -> smc_conn_free(), both pointers remain set
after the buffers are returned to the first link group or freed with it.
When connect() is retried on the same socket and selects a DMB-nocopy
device, smc_buf_create() skips allocating sndbuf_desc:

net/smc/smc_core.c:smc_buf_create() {
	/* create send buffer */
	if (is_smcd &&
	    smc_ism_support_dmb_nocopy(smc->conn.lgr->smcd))
		goto create_rmb;
...
create_rmb:
	/* create rmb */
	rc = __smc_buf_create(smc, is_smcd, true);
	if (rc && smc->conn.sndbuf_desc) {
		down_write(&smc->conn.lgr->sndbufs_lock);
		smc_lgr_buf_list_del(smc->conn.lgr, false,
				     smc->conn.sndbuf_desc);
		up_write(&smc->conn.lgr->sndbufs_lock);
		smc_buf_free(smc->conn.lgr, false, smc->conn.sndbuf_desc);
		smc->conn.sndbuf_desc = NULL;
	}
}

If __smc_buf_create() for the RMB fails on the new link group,
smc_buf_create() unlinks and frees the stale conn->sndbuf_desc against the
new link group, and the subsequent smc_conn_abort() -> smc_conn_free() ->
smc_buf_unuse() -> smcd_rmb_drop() unlinks and frees the stale
conn->rmb_desc as well.  Even if RMB creation succeeds, a later failure in
smcd_buf_attach() will cause smcd_buf_detach() to kfree() the stale
conn->sndbuf_desc.

Should smc_buf_unuse() and the list_empty(&lgr->list) path in
smc_conn_free() clear both conn->rmb_desc and conn->sndbuf_desc
unconditionally?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261128-b4-disp-2c190c90-v3-0-c566f64196c8@proton.me?part=2

  reply	other threads:[~2026-11-29 15:05 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-28 15:05 [PATCH net v3 0/2] net/smc: do not reuse the DMB of a nocopy device Bryam Vargas via B4 Relay
2026-11-28 15:05 ` [PATCH net v3 1/2] dibs: loopback: reset the client id when the owner unregisters a DMB Bryam Vargas via B4 Relay
2026-11-28 15:05 ` [PATCH net v3 2/2] net/smc: do not reuse the DMB of a nocopy device Bryam Vargas via B4 Relay
2026-11-29 15:05   ` sashiko-bot [this message]
2026-11-29 15:05 ` [PATCH net v3 0/2] " 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-239731@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox