From: Jason Gunthorpe <jgg@ziepe.ca>
To: Shin'ichiro Kawasaki <shinichiro.kawasaki@wdc.com>
Cc: linux-rdma@vger.kernel.org, Leon Romanovsky <leon@kernel.org>,
linux-nvme@lists.infradead.org,
Damien Le Moal <dlemoal@kernel.org>
Subject: Re: [PATCH v2] RDMA/cma: prevent rdma id destroy during cma_iw_handler
Date: Mon, 12 Jun 2023 11:18:05 -0300 [thread overview]
Message-ID: <ZIcpHbV3oqsjuwfz@ziepe.ca> (raw)
In-Reply-To: <20230612054237.1855292-1-shinichiro.kawasaki@wdc.com>
On Mon, Jun 12, 2023 at 02:42:37PM +0900, Shin'ichiro Kawasaki wrote:
> When rdma_destroy_id() and cma_iw_handler() race, struct rdma_id_private
> *id_priv can be destroyed during cma_iw_handler call. This causes "BUG:
> KASAN: slab-use-after-free" at mutex_lock() in cma_iw_handler() [1].
> To prevent the destroy of id_priv, keep its reference count by calling
> cma_id_get() and cma_id_put() at start and end of cma_iw_handler().
>
> [1]
>
> ==================================================================
> BUG: KASAN: slab-use-after-free in __mutex_lock+0x1324/0x18f0
> Read of size 8 at addr ffff888197b37418 by task kworker/u8:0/9
>
> CPU: 0 PID: 9 Comm: kworker/u8:0 Not tainted 6.3.0 #62
> Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.16.2-1.fc38 04/01/2014
> Workqueue: iw_cm_wq cm_work_handler [iw_cm]
> Call Trace:
> <TASK>
> dump_stack_lvl+0x57/0x90
> print_report+0xcf/0x660
> ? __mutex_lock+0x1324/0x18f0
> kasan_report+0xa4/0xe0
> ? __mutex_lock+0x1324/0x18f0
> __mutex_lock+0x1324/0x18f0
> ? cma_iw_handler+0xac/0x4f0 [rdma_cm]
> ? _raw_spin_unlock_irqrestore+0x30/0x60
> ? rcu_is_watching+0x11/0xb0
> ? _raw_spin_unlock_irqrestore+0x30/0x60
> ? trace_hardirqs_on+0x12/0x100
> ? __pfx___mutex_lock+0x10/0x10
> ? __percpu_counter_sum+0x147/0x1e0
> ? domain_dirty_limits+0x246/0x390
> ? wb_over_bg_thresh+0x4d5/0x610
> ? rcu_is_watching+0x11/0xb0
> ? cma_iw_handler+0xac/0x4f0 [rdma_cm]
> cma_iw_handler+0xac/0x4f0 [rdma_cm]
What is the full call chain here, eg with the static functions
un-inlined?
>
> drivers/infiniband/core/cma.c | 3 +++
> 1 file changed, 3 insertions(+)
>
> diff --git a/drivers/infiniband/core/cma.c b/drivers/infiniband/core/cma.c
> index 93a1c48d0c32..c5267d9bb184 100644
> --- a/drivers/infiniband/core/cma.c
> +++ b/drivers/infiniband/core/cma.c
> @@ -2477,6 +2477,7 @@ static int cma_iw_handler(struct iw_cm_id *iw_id, struct iw_cm_event *iw_event)
> struct sockaddr *laddr = (struct sockaddr *)&iw_event->local_addr;
> struct sockaddr *raddr = (struct sockaddr *)&iw_event->remote_addr;
>
> + cma_id_get(id_priv);
> mutex_lock(&id_priv->handler_mutex);
> if (READ_ONCE(id_priv->state) != RDMA_CM_CONNECT)
> goto out;
> @@ -2524,12 +2525,14 @@ static int cma_iw_handler(struct iw_cm_id *iw_id, struct iw_cm_event *iw_event)
> if (ret) {
> /* Destroy the CM ID by returning a non-zero value. */
> id_priv->cm_id.iw = NULL;
> + cma_id_put(id_priv);
> destroy_id_handler_unlock(id_priv);
> return ret;
> }
>
> out:
> mutex_unlock(&id_priv->handler_mutex);
> + cma_id_put(id_priv);
> return ret;
> }
cm_work_handler already has a ref on the iwcm_id_private
I think there is likely some much larger issue with the IW CM if the
cm_id can be destroyed while the iwcm_id is in use? It is weird that
there are two id memories for this :\
Jason
next prev parent reply other threads:[~2023-06-12 14:18 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-06-12 5:42 [PATCH v2] RDMA/cma: prevent rdma id destroy during cma_iw_handler Shin'ichiro Kawasaki
2023-06-12 7:13 ` Leon Romanovsky
2023-06-12 14:18 ` Jason Gunthorpe [this message]
2023-06-13 1:43 ` Shinichiro Kawasaki
2023-06-13 6:47 ` Shinichiro Kawasaki
2023-06-13 13:30 ` Jason Gunthorpe
2023-06-13 18:07 ` Leon Romanovsky
2023-06-14 7:53 ` Shinichiro Kawasaki
2023-06-14 17:36 ` Jason Gunthorpe
2023-06-15 0:45 ` Shinichiro Kawasaki
2023-09-05 0:39 ` Shinichiro Kawasaki
2023-09-06 8:54 ` Daniel Wagner
2023-09-06 11:31 ` Shinichiro Kawasaki
2023-09-07 7:47 ` Yi Zhang
2023-09-07 16:17 ` Jason Gunthorpe
2023-09-08 7:18 ` Hannes Reinecke
2023-09-08 8:33 ` Yi Zhang
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=ZIcpHbV3oqsjuwfz@ziepe.ca \
--to=jgg@ziepe.ca \
--cc=dlemoal@kernel.org \
--cc=leon@kernel.org \
--cc=linux-nvme@lists.infradead.org \
--cc=linux-rdma@vger.kernel.org \
--cc=shinichiro.kawasaki@wdc.com \
/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