From: sashiko-bot@kernel.org
To: "Piyus Kedia" <piyus@iiitd.ac.in>, linux-rdma@vger.kernel.org
Subject: Re: [PATCH net] net/rds: do not leave ic->i_cm_id pointing at a freed cm_id
Date: Sun, 29 Nov 2026 03:37:55 +0000 [thread overview]
Message-ID: <sashiko-outbox-239301@kernel.org> (raw)
In-Reply-To: <20261128033737.467966-1-piyus@iiitd.ac.in>
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 <piyus@iiitd.ac.in>
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_path *cp)
> if (ic->i_recvs)
> rds_ib_recv_clear_ring(ic);
>
> - 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 = ic->i_cm_id;
> + ic->i_cm_id = NULL;
> + rdma_destroy_id(cm_id);
>
> /*
> * 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);
>
> - ic->i_cm_id = NULL;
> ic->i_pd = NULL;
> ic->i_send_cq = NULL;
> ic->i_recv_cq = 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 *ibmr)
> {
> struct rds_ib_frmr *frmr = &ibmr->u.frmr;
> struct ib_reg_wr reg_wr;
> + struct rdma_cm_id *i_cm_id;
> int ret, off = 0;
>
> while (atomic_dec_return(&ibmr->ic->i_fastreg_wrs) <= 0) {
> @@ -164,7 +165,16 @@ static int rds_ib_post_reg_frmr(struct rds_ib_mr *ibmr)
> IB_ACCESS_REMOTE_WRITE;
> reg_wr.wr.send_flags = IB_SEND_SIGNALED;
>
> - ret = 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 = 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 = -ECONNABORTED;
> + goto out_inc;
> + }
> + ret = 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 = 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 = 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 = 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 = NULL;
...
ic->i_cm_id = 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 = 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.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261128033737.467966-1-piyus@iiitd.ac.in?part=1
prev parent reply other threads:[~2026-11-29 3:37 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-28 3:37 [PATCH net] net/rds: do not leave ic->i_cm_id pointing at a freed cm_id Piyus Kedia
2026-11-29 3:37 ` sashiko-bot [this message]
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-239301@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=linux-rdma@vger.kernel.org \
--cc=piyus@iiitd.ac.in \
--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