Article View: linux.kernel.netdev
Article #24423Re: [PATCH net] net/rds: do not leave ic->i_cm_id pointing at a freed cm_id
From: Allison Henderson
Date: Mon, 30 Nov 2026 06:19
Date: Mon, 30 Nov 2026 06:19
194 lines
14872 bytes
14872 bytes
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:
>
> rdma_destroy_id(ic->i_cm_id);
> if (ic->rds_ibdev)
> rds_ib_remove_conn(ic->rds_ibdev, conn);
> ic->i_cm_id = NULL;
>
> 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:
>
> 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 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ย
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.
>
> 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.
>
> 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
> Signed-off-by: Kapil Vaswani <kapil@presceralabs.ai>
> Signed-off-by: Piyus Kedia <piyus@iiitd.ac.in>
Nit: as written, the sob chain says Kapil handled the patch before its author 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(-)
>
> 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 = 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 +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.
rds_ib_remove_conn() doesn't sleep, it only takes spinlocks, so the "can sleep"
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, the one
in rds_ib_post_reg_frmr() and the commit message should refer to that instead.
> + */
> + cm_id = ic->i_cm_id;
> + ic->i_cm_id = 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);
>
> /*
> * 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 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 *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;
This should return -ENODEV like rds_ib_get_mr() does, so that sendmsg() gets
-EAGAIN and a reconnect is started.
> + 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);
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 targets
net, but we should mention the conflict below the --- in v2 so the maintainers
know to expect it.
Thanks for working on this!
Allison
Technical Details
Message-ID:
<044db48c2f9bcea1d814e72ed1a771ad86b28cb1.camel@kernel.org>Path:
mbox-mo1.pugleaf.net!srv.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-373911-linux-kernel-netdev=dewy.ruReferences:
<20261128033737.467966-1-piyus@iiitd.ac.in>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!netdev+bounces-373911-linux-kernel-netdev=dewy.ru From: achender@kernel.org (Allison Henderson) Newsgroups: linux.kernel.netdev Subject: Re: [PATCH net] net/rds: do not leave ic->i_cm_id pointing at a freed cm_id Date: Sun, 29 Nov 2026 23:19:49 -0700 Organization: Usenet Network Message-ID: <044db48c2f9bcea1d814e72ed1a771ad86b28cb1.camel@kernel.org> References: <20261128033737.467966-1-piyus@iiitd.ac.in> MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Injection-Info: usenet.network; logging-data="1352467"; mail-complaints-to="abuse@usenet.network" Cancel-Lock: sha1:m85uPjaQA9vkUSbIW2/j1Ko0p4I= sha256:+JUcsHX0XwCTl4gBraUJDDXSQKtN6t/7X4qLxVq2zaQ= sha1:w5wYKYHfwyRTZK/HiLJcnHm0Zxs= sha256:4b0zUsVnj04iTFI8DlhK7LyDCzMxoeSfNhWE65KPrlM= List-ID: <netdev.vger.kernel.org> X-Mailpost-Empty-Hdrs: X-Spam-Level X-Received: from localhost (localhost [127.0.0.1]) by mail.dewy.ru (Postfix) with ESMTP id 11663125FC6; Mon, 30 Nov 2026 09:20:18 +0300 (MSK) X-Virus-Scanned: Debian amavisd-new at usenet.network X-Spam-Flag: NO X-Spam-Score: -3.401 X-Spam-Status: No, score=-3.401 tagged_above=-9999 required=6.31 tests=[DCC_REPUT_70_89=0.1, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001, SPF_PASS=-0.001] autolearn=ham autolearn_force=no X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key) header.d=kernel.org X-Received: from mail.dewy.ru ([127.0.0.1]) by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id NAMw3OhJrVU2; Mon, 30 Nov 2026 09:20:13 +0300 (MSK) X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=netdev+bounces-373911-linux-kernel-netdev=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> X-Authentication-Results: OpenDMARC; dmarc=pass (p=quarantine dis=none) header.from=kernel.org X-Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10]) by mail.dewy.ru (Postfix) with ESMTPS id 65A13125FC4; Mon, 30 Nov 2026 09:20:04 +0300 (MSK) X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92]) by sea.lore.kernel.org (Postfix) with ESMTP id ADC632A3BE; Mon, 30 Nov 2026 06:20:02 +0000 (UTC) X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1796019602; b=mbvzYdS0pnZZyKA3hVuntNrbi2n693/jkl9rMiFvYBYw6K/vO4ZTLVwGjg6KdzET6JVJ OYXMQxudAAFyQ2dkFvw7W8Sw6Vt3r7nbpebNK89ueRh7aXB4AhPYI0+4LKR9pRDWCbW9N rgpof1xMcas2uqsLgAlb45Gy2MCj3oUT3OUMAX5QOE+5s3tQD15mygKDoLHm7/zQgYKFB EEk7/Hlh/Ig+J5Hnxb1itjD+H0opn5DnxS/gE4k60bXZkqOZaJuS2br+uTZys6Sh+7F2E X/yU20/kC0ftIHYTsZ1G0evug6KTU7h0wMdX1mNOxI3xwBfcA0h5LX2vyDk7cXz2kMQ== X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796019602; h=X-Original-To:Received:Received:DKIM-Signature:Message-ID:Subject: From:To:Cc:Date:In-Reply-To:References:Content-Type: Content-Transfer-Encoding:User-Agent:X-Mailing-List:List-Id:List-Post: List-Help:List-Subscribe:List-Unsubscribe:List-Owner:Precedence: MIME-Version; bh=u1DliAavYkWNNLJqfDO0jweTADhKcCl1/Xud9q1+Ias=; b=uBhQqr1vOT1+5YSrDzOaPSb/PR9mK6V5Ou1Aq84AnZiQVcm0BiNoHT5EaKjHynMbmdYi 1pHSgsN2ek2WXuty1pHfATLTe9TisOjj0ZFYCmp3DBe/7rAVjuDITnXBcB77Ou0IRwB9b sUcb9VmAiqTLTN+3wtp7/L8YBtfohyuElb6S3QANcItpo6ZrLS0acLXlBV0XakuTUWsUd Wvi31fcUxAzleWDnm7O2Iaf14lAwu5TczWZQF88v9LP7L2fwR3zSUXB8fHedL1IAkyUWp hwObqmu4Q1DD/jC6447dJiNF2cfWYJJaa7871CEbALWixHWo8OzCxvZJqB5KDWdNkWQ== X-ARC-Authentication-Results: i=2; 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=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1 X-Received: from localhost.localdomain (localhost [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 86CD0606A32F; Mon, 30 Nov 2026 06:20:02 +0000 (UTC) X-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 X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 X-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== X-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== X-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 X-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) X-Received: by smtp.kernel.org (Postfix) with ESMTPSA id C895D1F00897; Mon, 30 Nov 2026 06:19:50 +0000 (UTC) X-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== X-Cc: "David S . Miller" <davem@davemloft.net>, Eric Dumazet <edumazet@kernel.org>, Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>, Simon Horman <horms@kernel.org>, linux-kernel@vger.kernel.org, Kapil Vaswani <kapil@presceralabs.ai> X-In-Reply-To: <20261128033737.467966-1-piyus@iiitd.ac.in> X-User-Agent: Evolution 3.52.3-0ubuntu1.1 X-Mailing-List: netdev@vger.kernel.org X-List-Post: <mailto:netdev@vger.kernel.org> X-List-Help: <mailto:netdev+help@vger.kernel.org> X-List-Subscribe: <mailto:netdev+subscribe@vger.kernel.org> X-List-Unsubscribe: <mailto:netdev+unsubscribe@vger.kernel.org> X-List-Owner: <mailto:netdev+owner@vger.kernel.org> X-Precedence: list