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=1796019591; b=j4WkXjRAJRLGLs0yUvW/gmZNjRsdH+csZgo3eQsDHtG/CA1WnkhPqocBuAsEuSEWDEgw d/jHab1oJRUD+0AUnT1chP6RKL6nTUO+Vg5Zz1SQBeTYslUv/SqSiYBOjODInxez17nsN pZlNKt8pU9uXdujSbP6j8jZhpG9OG6S1NucCt2zf8EkAjUSHJ4/64gbnsqb6uqezz7V2d euBiGZ1hinHaIe35gYExFk39moE2+g5jM8aVOxbkyNwckoecjNqCo9cYOHDOK4TbD/nuu CkOih/EHd8rPax8vutqMDX1tUgfPNan7hXhPEqsGdKLQJYduWdQiAOTAgMnODiQ5jvg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796019591; h=Received:DKIM-Signature:Message-ID:Subject:From:To:Cc:Date: In-Reply-To:References:Content-Type:Content-Transfer-Encoding: User-Agent:MIME-Version; bh=u1DliAavYkWNNLJqfDO0jweTADhKcCl1/Xud9q1+Ias=; b=1vhFPQ4jcT6URGhDnotxvwGvql+NVWjAF1tb4ONXB4bUJizL/odEaapjmARPV+fYkqhB ZI0tzO4NqMn8SuncDYfSe98WJUfj1QCqLkXkoqcB65dT0wEkjfhQz7ognRxtNV6Ud3AgW Dz5mYzGMLsjJZg4pVDRKOUzfdtroSPI9W0DINlhLMZgD/UBqUO49IbBtECXfA0p9jV0bz E17vsT7fua/AtbFtA1MaktPAybsWG005cnjKgd6BCx0iFTBwkR5g06XhdcLY+o3CmPMj4 1qidWbznEyPetz8qXnjKPWyzG8afDGL5nEGCb89WOBct98hybUClbGUt2qopiTvbqcw== 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=YrHfkxAE; 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 A228F606A31C; Mon, 30 Nov 2026 06:19:51 +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=YrHfkxAE Received: by smtp.kernel.org (Postfix) with ESMTPSA id C895D1F00897; Mon, 30 Nov 2026 06:19:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796019591; bh=u1DliAavYkWNNLJqfDO0jweTADhKcCl1/Xud9q1+Ias=; h=Subject:From:To:Cc:Date:In-Reply-To:References; b=YrHfkxAEFZg4oDIyN387LbY+bukbCAKhXk25LayrSb1QdVzUFYZBvnBqCvotI31lP p7z65Qhq2YKmLWwdng3TKJY8BoaPd6JMc7+LG+G62OAWMQqmz3NpX6xwxaF4RdwmNQ jJY75pBeD0DB+4Y6GUgNaTsk3BOsBZ0mDIvajljaiblh1F537qVvFDLBpr9wu0BI80 /4DHcxjPoBDCs8Gi+d8BVeFRDiRJkvRiS/yQo44uiuxD+X36nkgB4dpo2Wed9/Iy+0 ySprIbTmE7tu38cdu7ad16G3P7FbTd8svH+I+4ZQJibG6zh9PoHa48IrfKFP959F9L drR9O1ofUQgog== Message-ID: <044db48c2f9bcea1d814e72ed1a771ad86b28cb1.camel@kernel.org> Subject: Re: [PATCH net] net/rds: do not leave ic->i_cm_id pointing at a freed cm_id From: Allison Henderson To: Piyus Kedia , netdev@vger.kernel.org, linux-rdma@vger.kernel.org Cc: "David S . Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman , linux-kernel@vger.kernel.org, Kapil Vaswani Date: Sun, 29 Nov 2026 23:19:49 -0700 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 User-Agent: Evolution 3.52.3-0ubuntu1.1 X-Mailing-List: netdev@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Hi Piyus, Thanks for the patch. The Sashiko review for this one didn't get mailed out= , so you may not have seen it: https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261128033737.467966-1= -piyus%40iiitd.ac.in Comments below: On Sat, 2026-11-28 at 09:07 +0530, Piyus Kedia wrote: > rds_ib_conn_path_shutdown() frees the connection's rdma_cm_id and only > clears ic->i_cm_id afterwards: >=20 > rdma_destroy_id(ic->i_cm_id); > if (ic->rds_ibdev) > rds_ib_remove_conn(ic->rds_ibdev, conn); > ic->i_cm_id =3D NULL; >=20 > rds_ib_remove_conn() takes locks and can sleep, so the pointer is left > pointing at freed memory for a while. Both FRMR paths read it with > nothing that excludes this teardown - rds_ib_get_mr() from sendmsg()'s > RDS_CMSG_RDMA_MAP handling, and rds_ib_unreg_frmr() from the MR pool > flush - and the NULL test in rds_ib_unreg_frmr() does not help, because > the pointer is not NULL, it is dangling: >=20 > BUG: KASAN: slab-use-after-free in rds_ib_unreg_frmr+0x119/0x860 > Read of size 8 at addr ffff888022d67010 > rds_ib_unreg_frmr+0x119/0x860 > rds_ib_flush_mr_pool+0x685/0x9f0 > rds_ib_flush_mrs+0x57/0xc0 > rds_release+0xc9/0x220 > __sock_release+0x65/0x160 >=20 > Allocated by task 37: > __rdma_create_id+0x48/0x4f0 > __rdma_create_kernel_id+0x3c/0x80 > rds_ib_conn_path_connect+0xfa/0x320 >=20 > Freed by task 9508: > kfree+0x1c7/0x660 > rds_ib_conn_path_shutdown+0xc2b/0xd30 > rds_conn_shutdown+0x3ca/0x940 >=20 > The same dangling pointer reaches the registration side, where a fuzzer > found it posting a work request to the QP of a cm_id already destroyed - > rxe reports that as "qp has been destroyed" from its own > WARN_ON_ONCE(!qp->valid) and then faults on qp->state_lock. The rxe "qp has been destroyed" crash doesn't look like it comes from the freed cm_id. rdma_destroy_qp() frees the QP and clears id->qp well before= =C2=A0 rdma_destroy_id(), so that post went through a live cm_id. The new check in rds_ib_post_reg_frmr() doesn't close that. So please either drop that claim from the commit message or fix it separately. >=20 > Clear ic->i_cm_id before destroying it, so a racing reader sees NULL > rather than freed memory, and check the pointer in rds_ib_post_reg_frmr() > the way rds_ib_unreg_frmr() already does - it is the one FRMR site that > dereferenced it without a test. >=20 > This does not serialise the two sides: a reader that has already loaded a > non-NULL pointer can still be preempted before using it. Closing that > would mean giving the registration path the exclusion the other users of > ic->i_cm_id have, which is a larger change than this one. >=20 > We found this with a syzkaller-based fuzzing harness driven by an AI tool= . >=20 > Fixes: 1659185fb4d0 ("RDS: IB: Support Fastreg MR (FRMR) memory registrat= ion mode") > Cc: stable@vger.kernel.org > Signed-off-by: Kapil Vaswani > Signed-off-by: Piyus Kedia Nit: as written, the sob chain says Kapil handled the patch before its auth= or did. If Kapil co-developed this, his Signed-off-by needs a Co-developed-by ahead of= it. > --- > net/rds/ib_cm.c | 12 ++++++++++-- > net/rds/ib_frmr.c | 12 +++++++++++- > 2 files changed, 21 insertions(+), 3 deletions(-) >=20 > diff --git a/net/rds/ib_cm.c b/net/rds/ib_cm.c > index 16bfeaaf3b97..17d748f08607 100644 > --- a/net/rds/ib_cm.c > +++ b/net/rds/ib_cm.c > @@ -1077,6 +1077,7 @@ void rds_ib_conn_path_shutdown(struct rds_conn_path= *cp) > { > struct rds_connection *conn =3D cp->cp_conn; > struct rds_ib_connection *ic =3D conn->c_transport_data; > + struct rdma_cm_id *cm_id; > int err =3D 0; > =20 > rdsdebug("cm %p pd %p cq %p %p qp %p\n", ic->i_cm_id, > @@ -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. rds_ib_remove_conn() doesn't sleep, it only takes spinlocks, so the "can sl= eep" part should be reworded here and in the commit message. Also, the load and = NULL check are in rds_ib_post_inv(), not rds_ib_unreg_frmr(), so this comment, t= he one in rds_ib_post_reg_frmr() and the commit message should refer to that inste= ad. > + */ > + cm_id =3D ic->i_cm_id; > + ic->i_cm_id =3D NULL; Since the readers are lockless, please use WRITE_ONCE() for the store and a single READ_ONCE() snapshot in the readers (rds_ib_get_mr() currently loads ic->i_cm_id twice). Also, the same free-then-clear ordering appears on both error paths in rds_ib_conn_path_connect(), so please apply the same change there. > + 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 8397aa4a17ac..09e732ac2324 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; This should return -ENODEV like rds_ib_get_mr() does, so that sendmsg() get= s -EAGAIN and a reconnect is started. > + 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); Lastly, the CI shows a conflict with commit 5b61d9aed8f6 ("net/rds: give cm_id->context a reference on its connection") in net-next. This patch tar= gets net, but we should mention the conflict below the --- in v2 so the maintain= ers know to expect it. Thanks for working on this! Allison