* [PATCH net v2] net/rds: do not leave ic->i_cm_id pointing at a freed cm_id
@ 2026-12-01 12:03 Piyus Kedia
2026-12-05 6:22 ` netdev-bot+sashiko
0 siblings, 1 reply; 2+ messages in thread
From: Piyus Kedia @ 2026-12-01 12:03 UTC (permalink / raw)
To: Allison Henderson, netdev, linux-rdma, rds-devel
Cc: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
Willem de Bruijn, Simon Horman, Santosh Shilimkar, Avinash Repaka,
linux-kernel, Kapil Vaswani
rds_ib_conn_path_shutdown() frees the connection's rdma_cm_id and only
clears ic->i_cm_id afterwards:
rdma_destroy_id(ic->i_cm_id);
if (ic->rds_ibdev)
rds_ib_remove_conn(ic->rds_ibdev, conn);
ic->i_cm_id = NULL;
so between the free and the clear the field points at freed memory. 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_post_inv() from the MR pool flush - and the NULL test in
rds_ib_post_inv() does not help, because the pointer is not NULL, it is
dangling:
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
Allocated by task 37:
__rdma_create_id+0x48/0x4f0
__rdma_create_kernel_id+0x3c/0x80
rds_ib_conn_path_connect+0xfa/0x320
Freed by task 9508:
kfree+0x1c7/0x660
rds_ib_conn_path_shutdown+0xc2b/0xd30
rds_conn_shutdown+0x3ca/0x940
The load and the NULL test that KASAN caught are in rds_ib_post_inv(),
which the compiler inlines into rds_ib_unreg_frmr(), hence the frame.
Clear ic->i_cm_id before destroying it, so a racing reader sees NULL
rather than freed memory, and test the pointer in rds_ib_post_reg_frmr()
the way rds_ib_post_inv() already does - it is the one FRMR site that
dereferenced it without a test, and -ENODEV is what rds_ib_get_mr()
already reports for the same condition, so __rds_rdma_map() starts a
reconnect and rds_sendmsg() returns -EAGAIN.
The readers hold no lock, so the store is WRITE_ONCE() and each reader
takes a single READ_ONCE() snapshot; rds_ib_get_mr() was loading the
field twice. rds_ib_conn_path_connect() frees before clearing on both of
its failure paths and gets the same treatment.
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.
We found this with a syzkaller-based fuzzing harness driven by an AI tool.
Fixes: 1659185fb4d0 ("RDS: IB: Support Fastreg MR (FRMR) memory registration mode")
Cc: stable@vger.kernel.org
Link: https://lore.kernel.org/all/20261128033737.467966-1-piyus@iiitd.ac.in/
Suggested-by: Allison Henderson <achender@kernel.org>
Co-developed-by: Kapil Vaswani <kapil@presceralabs.ai>
Signed-off-by: Kapil Vaswani <kapil@presceralabs.ai>
Signed-off-by: Piyus Kedia <piyus@iiitd.ac.in>
---
Changes in v2, all from Allison Henderson's review of v1
<https://lore.kernel.org/all/20261128033737.467966-1-piyus@iiitd.ac.in/>:
- the claim that the rxe "qp has been destroyed" crash comes from the freed
cm_id is gone from the commit message. The review is right, as is the same
point in the Sashiko review of v1 <sashiko-outbox-239301@kernel.org>:
rdma_destroy_qp() frees the QP inside ib_destroy_qp() and clears id.qp only
afterwards, so that post went through a live cm_id and the new test here does
not close it. It needs its own fix, which I will send separately rather than
keep the claim.
- "rds_ib_remove_conn() can sleep" is gone from the comment and the commit
message. It takes ib_nodev_conns_lock and rds_ibdev->spinlock and does a
kref put; nothing in it sleeps. The reorder stands on the window itself,
however short it is.
- the load and the NULL test are rds_ib_post_inv()'s, not rds_ib_unreg_frmr()'s.
The comment in rds_ib_conn_path_shutdown(), the new comment in
rds_ib_post_reg_frmr() and the commit message all name post_inv now, and the
message says why KASAN prints the other frame.
- WRITE_ONCE() for the store, and a single READ_ONCE() snapshot in each reader.
rds_ib_get_mr() was loading ic->i_cm_id twice; it takes one snapshot now.
- both failure paths of rds_ib_conn_path_connect() clear the field before the
free, the same way the shutdown path now does.
- rds_ib_post_reg_frmr() reports -ENODEV, not v1's -ECONNABORTED, so
__rds_rdma_map() calls rds_conn_connect_if_down() and rds_sendmsg() returns
-EAGAIN and retries once the connection is back.
- Co-developed-by: added ahead of Kapil's Signed-off-by, which otherwise read
as if he had handled the patch before its author.
CONFLICT WITH net-next. This targets net. The CI on v1 reported a conflict
with commit 5b61d9aed8f6 ("net/rds: give cm_id->context a reference on its
connection") in net-next, and v2 still touches the same two regions: both
failure paths of rds_ib_conn_path_connect(). Both should resolve as "keep both
sides" - clear ic->i_cm_id, then rdma_destroy_id(), then whatever that commit
adds to the same path. I do not have net-next here to build that merge, so
the resolution above is its shape and not a tested one; happy to post a
net-next version separately if that is easier to carry.
Compile-tested on the base below with CONFIG_RDS_RDMA=y: net/rds builds clean
and checkpatch --strict is quiet.
Both reproducers are available on request; per security-bugs.rst they are not
posted.
net/rds/ib_cm.c | 27 ++++++++++++++++++++-------
net/rds/ib_frmr.c | 19 +++++++++++++++++--
net/rds/ib_rdma.c | 7 ++++++-
3 files changed, 43 insertions(+), 10 deletions(-)
diff --git a/net/rds/ib_cm.c b/net/rds/ib_cm.c
index 16bfeaaf3b97..1de3866b1ab6 100644
--- a/net/rds/ib_cm.c
+++ b/net/rds/ib_cm.c
@@ -978,6 +978,7 @@ int rds_ib_conn_path_connect(struct rds_conn_path *cp)
struct sockaddr_storage src, dest;
rdma_cm_event_handler handler;
struct rds_ib_connection *ic;
+ struct rdma_cm_id *cm_id;
int ret;
ic = conn->c_transport_data;
@@ -994,7 +995,7 @@ int rds_ib_conn_path_connect(struct rds_conn_path *cp)
RDMA_PS_TCP, IB_QPT_RC);
if (IS_ERR(ic->i_cm_id)) {
ret = PTR_ERR(ic->i_cm_id);
- ic->i_cm_id = NULL;
+ WRITE_ONCE(ic->i_cm_id, NULL);
rdsdebug("rdma_create_id() failed: %d\n", ret);
goto out;
}
@@ -1006,8 +1007,12 @@ int rds_ib_conn_path_connect(struct rds_conn_path *cp)
ret = rdma_restrict_node_type(ic->i_cm_id, RDMA_NODE_IB_CA);
if (ret) {
rdsdebug("rdma_restrict_node_type() failed: %d\n", ret);
- rdma_destroy_id(ic->i_cm_id);
- ic->i_cm_id = NULL;
+ /* Clear it before the free, as rds_ib_conn_path_shutdown()
+ * does: the readers below take no lock.
+ */
+ cm_id = ic->i_cm_id;
+ WRITE_ONCE(ic->i_cm_id, NULL);
+ rdma_destroy_id(cm_id);
goto out;
}
@@ -1047,8 +1052,9 @@ int rds_ib_conn_path_connect(struct rds_conn_path *cp)
if (ret) {
rdsdebug("addr resolve failed for cm id %p: %d\n", ic->i_cm_id,
ret);
- rdma_destroy_id(ic->i_cm_id);
- ic->i_cm_id = NULL;
+ cm_id = ic->i_cm_id;
+ WRITE_ONCE(ic->i_cm_id, NULL);
+ rdma_destroy_id(cm_id);
}
out:
@@ -1077,6 +1083,7 @@ void rds_ib_conn_path_shutdown(struct rds_conn_path *cp)
{
struct rds_connection *conn = cp->cp_conn;
struct rds_ib_connection *ic = conn->c_transport_data;
+ struct rdma_cm_id *cm_id;
int err = 0;
rdsdebug("cm %p pd %p cq %p %p qp %p\n", ic->i_cm_id,
@@ -1178,7 +1185,14 @@ 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, so a
+ * racing reader sees NULL instead of a dangling pointer.
+ * rds_ib_post_inv() and rds_ib_get_mr() read ic->i_cm_id
+ * without holding anything that excludes this teardown.
+ */
+ cm_id = ic->i_cm_id;
+ WRITE_ONCE(ic->i_cm_id, NULL);
+ rdma_destroy_id(cm_id);
/*
* Move connection back to the nodev list.
@@ -1186,7 +1200,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 8397aa4a17ac..1fd7837dd53b 100644
--- a/net/rds/ib_frmr.c
+++ b/net/rds/ib_frmr.c
@@ -123,6 +123,7 @@ static void rds_ib_free_frmr(struct rds_ib_mr *ibmr, bool drop)
static int rds_ib_post_reg_frmr(struct rds_ib_mr *ibmr)
{
struct rds_ib_frmr *frmr = &ibmr->u.frmr;
+ struct rdma_cm_id *i_cm_id;
struct ib_reg_wr reg_wr;
int ret, off = 0;
@@ -164,7 +165,21 @@ 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);
+ /* Test it the way rds_ib_post_inv() does: the teardown clears
+ * ic->i_cm_id and nothing here excludes it. -ENODEV is what
+ * rds_ib_get_mr() reports for the same condition, and
+ * __rds_rdma_map() turns that into rds_conn_connect_if_down() and
+ * rds_sendmsg() into -EAGAIN, so the caller retries once the
+ * connection is back.
+ */
+ i_cm_id = READ_ONCE(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 = -ENODEV;
+ 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);
@@ -270,7 +285,7 @@ static int rds_ib_post_inv(struct rds_ib_mr *ibmr)
{
struct ib_send_wr *s_wr;
struct rds_ib_frmr *frmr = &ibmr->u.frmr;
- struct rdma_cm_id *i_cm_id = ibmr->ic->i_cm_id;
+ struct rdma_cm_id *i_cm_id = READ_ONCE(ibmr->ic->i_cm_id);
int ret = -EINVAL;
if (!i_cm_id || !i_cm_id->qp || !frmr->mr)
diff --git a/net/rds/ib_rdma.c b/net/rds/ib_rdma.c
index db7e92e7bd29..b85486734a4b 100644
--- a/net/rds/ib_rdma.c
+++ b/net/rds/ib_rdma.c
@@ -549,6 +549,7 @@ void *rds_ib_get_mr(struct scatterlist *sg, unsigned long nents,
struct rds_ib_device *rds_ibdev;
struct rds_ib_mr *ibmr = NULL;
struct rds_ib_connection *ic = NULL;
+ struct rdma_cm_id *i_cm_id;
int ret;
rds_ibdev = rds_ib_get_device(rs->rs_bound_addr.s6_addr32[3]);
@@ -604,7 +605,11 @@ void *rds_ib_get_mr(struct scatterlist *sg, unsigned long nents,
if (conn) {
ic = conn->c_transport_data;
- if (!ic || !ic->i_cm_id || !ic->i_cm_id->qp) {
+ /* One snapshot: the teardown can clear ic->i_cm_id between
+ * two loads of it.
+ */
+ i_cm_id = ic ? READ_ONCE(ic->i_cm_id) : NULL;
+ if (!i_cm_id || !i_cm_id->qp) {
ret = -ENODEV;
goto out;
}
base-commit: 639a75a3539f621e4437ffeec7ab51bf8a1fb170
--
2.34.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH net v2] net/rds: do not leave ic->i_cm_id pointing at a freed cm_id
2026-12-01 12:03 [PATCH net v2] net/rds: do not leave ic->i_cm_id pointing at a freed cm_id Piyus Kedia
@ 2026-12-05 6:22 ` netdev-bot+sashiko
0 siblings, 0 replies; 2+ messages in thread
From: netdev-bot+sashiko @ 2026-12-05 6:22 UTC (permalink / raw)
To: piyus
Cc: achender, netdev, linux-rdma, rds-devel, davem, edumazet, kuba,
pabeni, willemb, horms, ssantosh, avinash.repaka, linux-kernel,
kapil
Thank you for your contribution! Sashiko AI review found 4 potential
issue(s) to consider.
Critical: 0 · High: 2 (1) · Medium: 1 · Low: 1
If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).
- [High] The patch shrinks the use-after-free it carries Fixes:/Cc:
stable for, but does not close it.
- [High] The new guard in rds_ib_post_reg_frmr() treats a non-NULL
i_cm_id->qp as a live send queue, but teardown destroys the QP while…
- [Medium] rds_ib_conn_path_connect() still lets lockless readers see an
error pointer in ic->i_cm_id.
- [Low] The new comments describe the lockless readers inconsistently.
Pre-existing issues:
- [High] This problem wasn't introduced by this patch, but
rds_ib_conn_info_visitor() and rds6_ib_conn_info_visitor()…
--
net/rds: do not leave ic->i_cm_id pointing at a freed cm_id
This patch changes the shutdown and connect failure paths so that
ic->i_cm_id is cleared with WRITE_ONCE() before rdma_destroy_id() frees
it. It switches the FRMR readers to a single READ_ONCE() snapshot. It also
adds a NULL check in rds_ib_post_reg_frmr() that returns -ENODEV.
Link: https://lore.kernel.org/all/20261128033737.467966-1-piyus@iiitd.ac.in/
> diff --git a/net/rds/ib_cm.c b/net/rds/ib_cm.c
> index 16bfeaaf3b974..1de3866b1ab62 100644
> --- a/net/rds/ib_cm.c
> +++ b/net/rds/ib_cm.c
[ ... ]
> @@ -994,7 +995,7 @@ int rds_ib_conn_path_connect(struct rds_conn_path *cp)
> RDMA_PS_TCP, IB_QPT_RC);
> if (IS_ERR(ic->i_cm_id)) {
> ret = PTR_ERR(ic->i_cm_id);
> - ic->i_cm_id = NULL;
> + WRITE_ONCE(ic->i_cm_id, NULL);
[Severity: Medium]
Can a lockless reader see an error pointer in ic->i_cm_id here? The
assignment just above this hunk is a plain store of the raw return value
of rdma_create_id(), made before the IS_ERR() test:
ic->i_cm_id = rdma_create_id(&init_net, handler, conn,
RDMA_PS_TCP, IB_QPT_RC);
if (IS_ERR(ic->i_cm_id)) {
Until the WRITE_ONCE(ic->i_cm_id, NULL) runs, the field holds a value such
as ERR_PTR(-ENOMEM).
Every reader this patch touches tests only for NULL before it
dereferences ->qp:
rds_ib_get_mr():
i_cm_id = ic ? READ_ONCE(ic->i_cm_id) : NULL;
if (!i_cm_id || !i_cm_id->qp) {
rds_ib_post_reg_frmr():
i_cm_id = READ_ONCE(ibmr->ic->i_cm_id);
if (!i_cm_id || !i_cm_id->qp) {
rds_ib_post_inv():
if (!i_cm_id || !i_cm_id->qp || !frmr->mr)
__rds_rdma_map() passes cp->cp_conn to rds_ib_get_mr() whatever state the
connection is in. So sendmsg(RDS_CMSG_RDMA_MAP) can run while the connect
worker is inside rds_ib_conn_path_connect().
Suppose rdma_create_id() fails with -ENOMEM in that window. Would the
reader pass the NULL test and then load i_cm_id->qp from
ERR_PTR(-ENOMEM) + 0x10, which is address 0x4?
Could rdma_create_id() be assigned to the local cm_id instead, with
IS_ERR() checked on the local, so that only a valid pointer is ever
published with WRITE_ONCE()?
On the passive side, rds_ib_cm_handle_connect() still publishes the field
with a plain store:
ic->i_cm_id = cm_id;
cm_id->context = conn;
Should that store also be a WRITE_ONCE(), to pair with the new READ_ONCE()
readers?
[ ... ]
> @@ -1006,8 +1007,12 @@ int rds_ib_conn_path_connect(struct rds_conn_path *cp)
> ret = rdma_restrict_node_type(ic->i_cm_id, RDMA_NODE_IB_CA);
> if (ret) {
> rdsdebug("rdma_restrict_node_type() failed: %d\n", ret);
> - rdma_destroy_id(ic->i_cm_id);
> - ic->i_cm_id = NULL;
> + /* Clear it before the free, as rds_ib_conn_path_shutdown()
> + * does: the readers below take no lock.
> + */
[Severity: Low]
This isn't a bug, but which readers does "the readers below" mean? In this
function only rdma_resolve_addr() and rdsdebug() follow. The lockless
readers live in ib_rdma.c and ib_frmr.c.
The comment added in rds_ib_conn_path_shutdown() is also incomplete. It
names only rds_ib_post_inv() and rds_ib_get_mr() as lockless readers. This
same patch makes rds_ib_post_reg_frmr() a READ_ONCE() reader, and the new
comment there says "nothing here excludes it".
[ ... ]
> @@ -1178,7 +1185,14 @@ 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, so a
> + * racing reader sees NULL instead of a dangling pointer.
> + * rds_ib_post_inv() and rds_ib_get_mr() read ic->i_cm_id
> + * without holding anything that excludes this teardown.
> + */
> + cm_id = ic->i_cm_id;
> + WRITE_ONCE(ic->i_cm_id, NULL);
> + rdma_destroy_id(cm_id);
[Severity: High]
Does this close the use-after-free in the KASAN report, or does it only
narrow the window? Nothing here waits for a reader that took its snapshot
of ic->i_cm_id before the WRITE_ONCE().
In rds_ib_post_inv(), the snapshot is followed directly by the ->qp load
that KASAN flagged:
struct rdma_cm_id *i_cm_id = READ_ONCE(ibmr->ic->i_cm_id);
...
if (!i_cm_id || !i_cm_id->qp || !frmr->mr)
That code runs in preemptible process context:
rds_release()->rds_ib_flush_mrs()->rds_ib_flush_mr_pool()->
rds_ib_unreg_frmr()->rds_ib_post_inv()
Suppose the task is preempted between the READ_ONCE() and the ->qp load,
and meanwhile rds_conn_shutdown()->rds_ib_conn_path_shutdown() reaches
rdma_destroy_id(). Would the ->qp read still land on the freed cm_id?
rds_ib_post_reg_frmr() takes its snapshot after
atomic_inc(&ibmr->ic->i_fastreg_inuse_count). That increment can happen
after rds_ib_conn_path_shutdown_check_wait() has already seen
i_fastreg_inuse_count == 0. If so, nothing seems to order the gap between
the snapshot and ib_post_send(i_cm_id->qp, ...) against rdma_destroy_id().
rds_ib_get_mr() follows the same snapshot-then-dereference pattern on the
sendmsg(RDS_CMSG_RDMA_MAP) path.
The commit message acknowledges this:
This does not serialise the two sides: a reader that has already loaded a
non-NULL pointer can still be preempted before using it.
The patch carries Fixes: and Cc: stable tags, and the subject says the
pointer no longer dangles. Should the FRMR paths get real exclusion
against teardown instead of only a reordered clear? Options include a
reference that keeps the cm_id alive across the posts, or quiescing FRMR
users before rdma_destroy_id().
[Severity: High]
This isn't a bug introduced by this patch, but the comment above names
only rds_ib_post_inv() and rds_ib_get_mr(). The info visitors in
net/rds/ib.c also read ic->i_cm_id and ic->rds_ibdev without excluding
this teardown:
net/rds/ib.c:rds_ib_conn_info_visitor() {
...
if (rds_conn_state(conn) == RDS_CONN_UP) {
struct rds_ib_device *rds_ibdev;
rdma_read_gids(ic->i_cm_id, (union ib_gid *)&iinfo->src_gid,
(union ib_gid *)&iinfo->dst_gid);
rds_ibdev = ic->rds_ibdev;
...
iinfo->max_send_sge = rds_ibdev->max_sge;
rds_ib_get_mr_info(rds_ibdev, iinfo);
...
}
rds6_ib_conn_info_visitor() does the same. Both are reached through:
getsockopt(SOL_RDS, RDS_INFO_IB_CONNECTIONS)->rds_info_getsockopt()->
rds_ib_ic_info()->rds_for_each_conn_info()
rds_for_each_conn_info() holds only rcu_read_lock(), and carries the
comment "XXX no c_lock usage..". rdma_destroy_id() frees the cm_id
synchronously, and rds_ib_remove_conn() sets ic->rds_ibdev = NULL.
Suppose a visitor sees RDS_CONN_UP and is then delayed while
rds_conn_shutdown()->rds_ib_conn_path_shutdown() runs. Can rdma_read_gids()
then dereference cm_id->device through a freed or NULL cm_id? Can the
rds_ibdev->max_sge read become a NULL dereference?
[ ... ]
> diff --git a/net/rds/ib_frmr.c b/net/rds/ib_frmr.c
> index 8397aa4a17ac8..1fd7837dd53b0 100644
> --- a/net/rds/ib_frmr.c
> +++ b/net/rds/ib_frmr.c
[ ... ]
> @@ -164,7 +165,21 @@ 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);
> + /* Test it the way rds_ib_post_inv() does: the teardown clears
> + * ic->i_cm_id and nothing here excludes it. -ENODEV is what
> + * rds_ib_get_mr() reports for the same condition, and
> + * __rds_rdma_map() turns that into rds_conn_connect_if_down() and
> + * rds_sendmsg() into -EAGAIN, so the caller retries once the
> + * connection is back.
> + */
> + i_cm_id = READ_ONCE(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 = -ENODEV;
> + goto out_inc;
> + }
> +
> + ret = ib_post_send(i_cm_id->qp, ®_wr.wr, NULL);
[Severity: High]
Can this check pass while the QP is being destroyed?
rds_ib_conn_path_shutdown() destroys the QP long before the new
WRITE_ONCE(ic->i_cm_id, NULL):
if (ic->i_cm_id->qp)
rdma_destroy_qp(ic->i_cm_id);
rdma_destroy_qp() also frees the QP before it clears id.qp:
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);
}
Take a registration that starts after
rds_ib_conn_path_shutdown_check_wait() has passed:
rds_ib_get_mr()->rds_ib_reg_frmr()->rds_ib_map_frmr()->
rds_ib_post_reg_frmr()
It would see a non-NULL i_cm_id and a non-NULL ->qp. It would then call
ib_post_send(), and so qp->device->ops.post_send, on a QP that is being or
has been freed.
->qp is also loaded twice without READ_ONCE(): once for the test and once
for the ib_post_send() argument. If the second load sees the
id.qp = NULL written by rdma_destroy_qp(), does ib_post_send(NULL, ...)
dereference qp->device?
What if the post instead succeeds after
disable_work_sync(&ic->i_send_work) but before the CQs are destroyed? Is
the REG_MR completion ever processed, or does the sender block forever
here:
wait_event(frmr->fr_reg_done, !frmr->fr_reg);
rds_ib_post_inv(), which this check copies, does the same test and later
reload of ->qp across its i_fastreg_wrs spin.
The v2 changelog says the destroyed-QP crash needs its own fix. The new
in-tree comment, though, reads as if this test makes the site safe
against teardown. Should the comment, or the check, reflect that gap?
[ ... ]
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261201120335.3527546-1-piyus%40iiitd.ac.in
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-12-05 6:22 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-01 12:03 [PATCH net v2] net/rds: do not leave ic->i_cm_id pointing at a freed cm_id Piyus Kedia
2026-12-05 6:22 ` netdev-bot+sashiko
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox