From: Leon Romanovsky <leon@kernel.org>
To: Jason Gunthorpe <jgg@nvidia.com>
Cc: Patrisious Haddad <phaddad@nvidia.com>,
Artemy Kovalyov <artemyko@mellanox.com>,
linux-rdma@vger.kernel.org
Subject: Re: [PATCH rdma-next v1] RDMA/mlx5: Fix implicit ODP use after free
Date: Tue, 21 Jan 2025 10:39:19 +0200 [thread overview]
Message-ID: <20250121083919.GB10702@unreal> (raw)
In-Reply-To: <20250120184922.GS5556@nvidia.com>
On Mon, Jan 20, 2025 at 02:49:22PM -0400, Jason Gunthorpe wrote:
> On Sun, Jan 19, 2025 at 10:21:41AM +0200, Leon Romanovsky wrote:
>
> > Fixes: 5256edcb98a1 ("RDMA/mlx5: Rework implicit ODP destroy")
>
> Cc: stable
>
> Fixes a user triggerable oops
> > - if (!refcount_inc_not_zero(&imr->mmkey.usecount))
> > + xa_lock(&imr->implicit_children);
> > + if (__xa_cmpxchg(&imr->implicit_children, idx, mr, NULL, GFP_KERNEL) !=
> > + mr) {
> > + xa_unlock(&imr->implicit_children);
> > return;
> > + }
> >
> > - xa_erase(&imr->implicit_children, idx);
> > if (MLX5_CAP_ODP(mr_to_mdev(mr)->mdev, mem_page_fault))
> > - xa_erase(&mr_to_mdev(mr)->odp_mkeys,
> > - mlx5_base_mkey(mr->mmkey.key));
> > + __xa_erase(&mr_to_mdev(mr)->odp_mkeys,
> > + mlx5_base_mkey(mr->mmkey.key));
> > + xa_unlock(&imr->implicit_children);
> > +
> > + if (!refcount_inc_not_zero(&imr->mmkey.usecount))
> > + return;
>
> It seems the refcount must be done first:
>
> /*
> * If userspace is racing freeing the parent implicit ODP MR
> * then we can loose the race with parent destruction. In this
> * case mlx5_ib_free_odp_mr() will free everything in the
> * implicit_children xarray so NOP is fine. This child MR
> * cannot be destroyed here because we are under its umem_mutex.
> */
> if (!refcount_inc_not_zero(&imr->mmkey.usecount))
> return;
>
> What we must not do is remove something from the xarray and then fail
> to free it.
Yes, like it was before.
>
> Jason
next prev parent reply other threads:[~2025-01-21 8:39 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-01-19 8:21 [PATCH rdma-next v1] RDMA/mlx5: Fix implicit ODP use after free Leon Romanovsky
2025-01-20 18:49 ` Jason Gunthorpe
2025-01-21 8:39 ` Leon Romanovsky [this message]
2025-01-21 18:14 ` Jason Gunthorpe
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=20250121083919.GB10702@unreal \
--to=leon@kernel.org \
--cc=artemyko@mellanox.com \
--cc=jgg@nvidia.com \
--cc=linux-rdma@vger.kernel.org \
--cc=phaddad@nvidia.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