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=1795923476; b=zvl3lRL4hPJhX+lCodXrMcnVVorr34TAFxWDVVPgoL+arhns1mEHnCh37rJIeLQvms/r n8oAaGiCPrCEfo1ybPjWCwt1GvrZWzTFoqDeoFYyqBKZsy1wonrfVgOu+xbZU7ILRATj2 bZMl/XQ7krOoqAmGLPtXg/DOQcBv5tzD1n2WJgN9EgDe3ItclrI/oL/hVkN/Ed1MR+ZIi fMEYF4qSWC9cZ/aSoyhjuLFC6dxPHmapX1QpXg7ktTTspgUCRMJhuqecFSpv8IlrBnBkl 73Z+Twpvp3mXNMsAgEOrZx8EmHGsoqTn0RbPeka3GrBa5XsmjYDhkZX6A0AB8gOy0kw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795923476; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=nwtcC3kUy02odefl1fK4D5DE/UXVI8XG9LwJK18y13g=; b=XKKB4JTEGyK7H8KDLYSRRaLDhD5x3qBPK+thWBeSNSUynN0a4KJRPFlAy3/l0jbtrj7e nHMBYtxPuCxGQZuNWkTDKNjTJxswr/RWnQeI9GUo0CfKYpepO29n9RhE+/8h93nEoZC7r xpQCX39JqagOk4Y615RpYd4jQIVT2vA95jiY6XBvUt2UJzA0/ADG2ovL9Y1q4ta0vIv2q 3JyJbB/Z0Wn8wLvOdo4zAFZ3eUVsEatixeNomRlKN1xYecs1YIGCka/u5XWp0u6Dqb0DY iBeGdt05NqQlfrFKplX19vJ+dMfM9HRHTA4H3ZeUWI3og+pm1nZMX9JNlXLHA8wrLtA== 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=gi6cPKSo; 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 0AE7C606A31C for ; Sun, 29 Nov 2026 03:37:56 +0000 (UTC) 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=gi6cPKSo Received: by smtp.kernel.org (Postfix) with ESMTPSA id C5DA51F000C1; Sun, 29 Nov 2026 03:37:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1795923475; bh=nwtcC3kUy02odefl1fK4D5DE/UXVI8XG9LwJK18y13g=; h=From:Subject:Reply-To:To:In-Reply-To:References:Date; b=gi6cPKSoicZfOhtHjw/5q9ifclgBqtNbMV2tBtpJm5af2pLUzxk+SMpptWJg7DWOL FHSouiMpdKHPQjfc9msrdSjP1DAV265KFz8u3o55qCH6X4ZYO0ga2c/dgWE6ZfsySp i/Pde4nz9uQypEFJTWrnU/Pwp+HE5kRbDb4qDIGjpzwcyxXYft5saSaluBkpMO//Wp Bv4G1cRp6O81YLbXv11i/bZyjsdeva++0IFVdw9JlKbzku57WFb9fAyiAS93o1Y1ol Lfe2zvXvkKHJ2q0jJKZKGhihS6wNzLkqMmYwBT4SJJ05vcvP1m4HuxOHtutUMZ3f2b UTulqo33Zk1Ew== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH net] net/rds: do not leave ic->i_cm_id pointing at a freed cm_id Reply-To: sashiko-reviews@lists.linux.dev To: "Piyus Kedia" , linux-rdma@vger.kernel.org In-Reply-To: <20261128033737.467966-1-piyus@iiitd.ac.in> References: <20261128033737.467966-1-piyus@iiitd.ac.in> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Sun, 29 Nov 2026 03:37:55 +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/rds: QP use-after-free and NULL deref in rds_ib_post_reg_frmr() -- commit b01d67e9312d5821512773afb6e27ad4f563c07e Author: Piyus Kedia net/rds: do not leave ic->i_cm_id pointing at a freed cm_id This commit clears ic->i_cm_id before calling rdma_destroy_id() in rds_ib_conn_path_shutdown() and checks i_cm_id and i_cm_id->qp for NULL before posting the registration work request in rds_ib_post_reg_frmr(). > diff --git a/net/rds/ib_cm.c b/net/rds/ib_cm.c > index 16bfeaaf3b974..17d748f086071 100644 > --- a/net/rds/ib_cm.c > +++ b/net/rds/ib_cm.c [ ... ] > @@ -1178,7 +1179,15 @@ void rds_ib_conn_path_shutdown(struct rds_conn_pat= h *cp) > if (ic->i_recvs) > rds_ib_recv_clear_ring(ic); > =20 > - rdma_destroy_id(ic->i_cm_id); > + /* Clear the pointer before freeing what it points at. > + * rds_ib_unreg_frmr() and rds_ib_get_mr() read ic->i_cm_id > + * without holding anything that excludes this teardown, and > + * rds_ib_remove_conn() below can sleep, so a pointer left > + * behind here is one they dereference after the free. > + */ > + cm_id =3D ic->i_cm_id; > + ic->i_cm_id =3D NULL; > + rdma_destroy_id(cm_id); > =20 > /* > * Move connection back to the nodev list. > @@ -1186,7 +1195,6 @@ void rds_ib_conn_path_shutdown(struct rds_conn_path= *cp) > if (ic->rds_ibdev) > rds_ib_remove_conn(ic->rds_ibdev, conn); > =20 > - ic->i_cm_id =3D NULL; > ic->i_pd =3D NULL; > ic->i_send_cq =3D NULL; > ic->i_recv_cq =3D NULL; > diff --git a/net/rds/ib_frmr.c b/net/rds/ib_frmr.c > index 8397aa4a17ac8..09e732ac23240 100644 > --- a/net/rds/ib_frmr.c > +++ b/net/rds/ib_frmr.c > @@ -124,6 +124,7 @@ static int rds_ib_post_reg_frmr(struct rds_ib_mr *ibm= r) > { > struct rds_ib_frmr *frmr =3D &ibmr->u.frmr; > struct ib_reg_wr reg_wr; > + struct rdma_cm_id *i_cm_id; > int ret, off =3D 0; > =20 > while (atomic_dec_return(&ibmr->ic->i_fastreg_wrs) <=3D 0) { > @@ -164,7 +165,16 @@ static int rds_ib_post_reg_frmr(struct rds_ib_mr *ib= mr) > IB_ACCESS_REMOTE_WRITE; > reg_wr.wr.send_flags =3D IB_SEND_SIGNALED; > =20 > - ret =3D ib_post_send(ibmr->ic->i_cm_id->qp, ®_wr.wr, NULL); > + /* Check it the way rds_ib_unreg_frmr() does: the teardown clears > + * ic->i_cm_id, and nothing here excludes it. > + */ > + i_cm_id =3D ibmr->ic->i_cm_id; > + if (!i_cm_id || !i_cm_id->qp) { > + rds_transition_frwr_state(ibmr, FRMR_IS_INUSE, FRMR_IS_STALE); > + ret =3D -ECONNABORTED; > + goto out_inc; > + } > + ret =3D ib_post_send(i_cm_id->qp, ®_wr.wr, NULL); > if (unlikely(ret)) { > /* Failure here can be because of -ENOMEM as well */ > rds_transition_frwr_state(ibmr, FRMR_IS_INUSE, FRMR_IS_STALE); [Severity: High] Can rds_ib_post_reg_frmr() still call ib_post_send() on a destroyed or NULL i_cm_id->qp? rds_ib_conn_path_shutdown() destroys the QP much earlier than it clears ic->i_cm_id, and rdma_destroy_qp() frees id.qp inside ib_destroy_qp() before setting id.qp =3D NULL: drivers/infiniband/core/cma.c:rdma_destroy_qp() { mutex_lock(&id_priv->qp_mutex); ib_destroy_qp(id_priv->id.qp); id_priv->id.qp =3D NULL; mutex_unlock(&id_priv->qp_mutex); } When sendmsg() with RDS_CMSG_RDMA_MAP races with connection shutdown, both ic->i_cm_id and i_cm_id->qp remain non-NULL throughout ib_destroy_qp(): CPU0 CPU1 rds_ib_conn_path_shutdown() rdma_destroy_qp(ic->i_cm_id) ib_destroy_qp(id_priv->id.qp) rxe_destroy_qp() ... kfree(qp) rds_ib_post_reg_frmr() i_cm_id =3D ibmr->ic->i_cm_id; if (!i_cm_id || !i_cm_id->qp) ib_post_send(i_cm_id->qp, ...) <-- use-after-free on qp id_priv->id.qp =3D NULL; ... ic->i_cm_id =3D NULL; rdma_destroy_id(cm_id); This leaves the rxe "qp has been destroyed" warning and qp->state_lock use-after-free reachable. In addition, rds_ib_post_reg_frmr() re-reads i_cm_id->qp in the ib_post_send() call instead of using a local pointer, so if CPU0 sets id_priv->id.qp =3D NULL between the !i_cm_id->qp check and ib_post_send(), ib_post_send() dereferences a NULL qp pointer. And because nothing serializes the reader against teardown, a thread preempted after loading i_cm_id can still dereference i_cm_id after rdma_destroy_id() frees it. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261128033737.4679= 66-1-piyus@iiitd.ac.in?part=3D1