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=1795964728; b=jitbUvvieNFBFX4x7vTsUvT4+6VdqvC/HIDtSGg2jwiHp8yJ2Cq6886mzrBhpf4wqaEB jMX90FMwutJazliEoYROS/+nLSMyYLMsGl2tgnMn1Rd2uScWKgdqz9OzHuCNpdqc2a9Jf BVpVCyQ0VzkYlgs+0EvhNgt98fuj9/0ik1To416PAQeE3oifOtjEFRY8GlSq+a0d2WTjQ N5bbkrc1/mOcbEfw2lSl8GkNUC4bxiOdt9YBhrTrErdP90J6WvFXT+u9CpRqeWzUcaXK5 gIBppe85BeYRAECcAo2IrAITk1uYLfGoc+x55Lxi5XVmFgGanmlpjXgzbVKH7ghqf5Q== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795964728; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=FR9dk7pcMf90aqxd7OBAaD3gMR16vC5OOGbk4iggohY=; b=fBa4dWXgRAJoysb2aTtf3dmVmLYBQNznoqX6pnAg0D2EphFV6Sh6RADMESUcWfVsNh69 vV3ujrzck0vpiBQeiOLtiuR53HhN6a12NwtXf0N6ktGceXgQX2BbwaH4DhjRCsSaH9zCZ nJ2cNp6NMu5xpuW11IBckrD19Iz2bmcKN3lEiVERuQW6F6vRmBgBHL1HD/RjPkJ7KDHd2 URyTIBWhZe2X55YUuzIlyqlivrfqH2sef4rJIvE8h6zsBi53YPSV1Zcdskg9PurHyzWUy T9ybE2x6+yZF/V1kdBVAGdpcbHZagI6YLZINcZUdfcjcCKa+rVDQRL2ORHYKe47nDGw== 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=luZ5TX23; 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 BFCA0606A31C; Sun, 29 Nov 2026 15:05:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=luZ5TX23 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0B3BB1F00897; Sun, 29 Nov 2026 15:05:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1795964728; bh=FR9dk7pcMf90aqxd7OBAaD3gMR16vC5OOGbk4iggohY=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=luZ5TX23oaTm0YzpwSinEXqlgiBT9XslHHK2G8Nk9AdMThkEjRBDllj2tz4Q6Gzfe s3b6dgfw+wydqvRhr6qKXrmtfBviAvLYDItkxyRb3AzXFngNPLXXGI65h+XxtzN1bS MHhN5HAculvjVhkhIQtOP8fdw3XiTiyB9EN14kIUY+dCualgL74RaaUdQgm+KjodSZ dFWrQxqdLlk+qXuay9L+Cxhe8WXFU/UeUYucpSNjtTqCEUCucQt22f2zsBui8HRcCt bvxje7MQZv6hKXIQ8s0KjabE1SbomrmjOSXCeNTE2HLTXeeE0zyve24D3O3KCpvalq CIdMAsE9Apn3w== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH net v3 2/2] net/smc: do not reuse the DMB of a nocopy device Reply-To: sashiko-reviews@lists.linux.dev To: "Bryam Vargas" Cc: linux-s390@vger.kernel.org, linux-rdma@vger.kernel.org, "Heiko Carstens" , "Vasily Gorbik" , "Alexander Gordeev" , "Christian Borntraeger" In-Reply-To: <20261128-b4-disp-2c190c90-v3-2-c566f64196c8@proton.me> References: <20261128-b4-disp-2c190c90-v3-0-c566f64196c8@proton.me> <20261128-b4-disp-2c190c90-v3-2-c566f64196c8@proton.me> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Sun, 29 Nov 2026 15:05:27 +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: - [High] net/smc: stale rmb_desc and sndbuf_desc in smc_buf_unuse() and smc_conn_free() -- commit 983dbaf62d65e0621212eee027d711a6e8acfec1 Author: Bryam Vargas 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); > } > =20 > +/* 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 =3D 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 *c= onn, > smcr_buf_unuse(conn->rmb_desc, true, lgr); > } else { > bufsize +=3D 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 =3D __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 =3D 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? --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261128-b4-disp-2c= 190c90-v3-0-c566f64196c8@proton.me?part=3D2