* [PATCH] RDMA/uverbs: fix umem release in UVERBS_METHOD_CQ_CREATE
@ 2025-10-09 16:40 Shuhao Fu
2025-10-09 18:48 ` Leon Romanovsky
0 siblings, 1 reply; 3+ messages in thread
From: Shuhao Fu @ 2025-10-09 16:40 UTC (permalink / raw)
To: Jason Gunthorpe, Leon Romanovsky; +Cc: linux-rdma, linux-kernel
In `UVERBS_METHOD_CQ_CREATE`, umem should be released if anything goes
wrong. Currently, if `create_cq_umem` fails, umem would not be
released or referenced, causing a possible leak.
Fixes: 1a40c362ae26 ("RDMA/uverbs: Add a common way to create CQ with umem")
Signed-off-by: Shuhao Fu <sfual@cse.ust.hk>
---
drivers/infiniband/core/uverbs_std_types_cq.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/drivers/infiniband/core/uverbs_std_types_cq.c b/drivers/infiniband/core/uverbs_std_types_cq.c
index 37cd37556510..9344020dede1 100644
--- a/drivers/infiniband/core/uverbs_std_types_cq.c
+++ b/drivers/infiniband/core/uverbs_std_types_cq.c
@@ -193,8 +193,10 @@ static int UVERBS_HANDLER(UVERBS_METHOD_CQ_CREATE)(
ret = umem ? ib_dev->ops.create_cq_umem(cq, &attr, umem, attrs) :
ib_dev->ops.create_cq(cq, &attr, attrs);
- if (ret)
+ if (ret) {
+ ib_umem_release(umem);
goto err_free;
+ }
obj->uevent.uobject.object = cq;
obj->uevent.uobject.user_handle = user_handle;
--
2.39.5
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] RDMA/uverbs: fix umem release in UVERBS_METHOD_CQ_CREATE
2025-10-09 16:40 [PATCH] RDMA/uverbs: fix umem release in UVERBS_METHOD_CQ_CREATE Shuhao Fu
@ 2025-10-09 18:48 ` Leon Romanovsky
2025-10-10 7:37 ` Shuhao Fu
0 siblings, 1 reply; 3+ messages in thread
From: Leon Romanovsky @ 2025-10-09 18:48 UTC (permalink / raw)
To: Shuhao Fu; +Cc: Jason Gunthorpe, linux-rdma, linux-kernel
On Fri, Oct 10, 2025 at 12:40:26AM +0800, Shuhao Fu wrote:
> In `UVERBS_METHOD_CQ_CREATE`, umem should be released if anything goes
> wrong. Currently, if `create_cq_umem` fails, umem would not be
> released or referenced, causing a possible leak.
It is only partially true. UMEM is released inside .create_cq_umem()
implementation. However there is an issue there that it doesn't release
in all flows. You need to change efa_create_cq_umem() too.
>
> Fixes: 1a40c362ae26 ("RDMA/uverbs: Add a common way to create CQ with umem")
> Signed-off-by: Shuhao Fu <sfual@cse.ust.hk>
> ---
> drivers/infiniband/core/uverbs_std_types_cq.c | 4 +++-
> 1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/infiniband/core/uverbs_std_types_cq.c b/drivers/infiniband/core/uverbs_std_types_cq.c
> index 37cd37556510..9344020dede1 100644
> --- a/drivers/infiniband/core/uverbs_std_types_cq.c
> +++ b/drivers/infiniband/core/uverbs_std_types_cq.c
> @@ -193,8 +193,10 @@ static int UVERBS_HANDLER(UVERBS_METHOD_CQ_CREATE)(
>
> ret = umem ? ib_dev->ops.create_cq_umem(cq, &attr, umem, attrs) :
> ib_dev->ops.create_cq(cq, &attr, attrs);
> - if (ret)
> + if (ret) {
> + ib_umem_release(umem);
> goto err_free;
> + }
>
> obj->uevent.uobject.object = cq;
> obj->uevent.uobject.user_handle = user_handle;
> --
> 2.39.5
>
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] RDMA/uverbs: fix umem release in UVERBS_METHOD_CQ_CREATE
2025-10-09 18:48 ` Leon Romanovsky
@ 2025-10-10 7:37 ` Shuhao Fu
0 siblings, 0 replies; 3+ messages in thread
From: Shuhao Fu @ 2025-10-10 7:37 UTC (permalink / raw)
To: Leon Romanovsky; +Cc: Jason Gunthorpe, linux-rdma, linux-kernel
On Thu, Oct 09, 2025 at 09:48:54PM +0300, Leon Romanovsky wrote:
> On Fri, Oct 10, 2025 at 12:40:26AM +0800, Shuhao Fu wrote:
> > In `UVERBS_METHOD_CQ_CREATE`, umem should be released if anything goes
> > wrong. Currently, if `create_cq_umem` fails, umem would not be
> > released or referenced, causing a possible leak.
>
> It is only partially true. UMEM is released inside .create_cq_umem()
> implementation. However there is an issue there that it doesn't release
> in all flows. You need to change efa_create_cq_umem() too.
>
My apologies for overlooking the umem release in `.create_cq_umem`. I have
sent out patch v2 [1] for this issue. In v2, the driver should not release
umem on failure, avoiding possible double free here.
[1] https://lore.kernel.org/linux-rdma/aOh1le4YqtYwj-hH@osx.local/
> >
> > Fixes: 1a40c362ae26 ("RDMA/uverbs: Add a common way to create CQ with umem")
> > Signed-off-by: Shuhao Fu <sfual@cse.ust.hk>
> > ---
> > drivers/infiniband/core/uverbs_std_types_cq.c | 4 +++-
> > 1 file changed, 3 insertions(+), 1 deletion(-)
> >
> > diff --git a/drivers/infiniband/core/uverbs_std_types_cq.c b/drivers/infiniband/core/uverbs_std_types_cq.c
> > index 37cd37556510..9344020dede1 100644
> > --- a/drivers/infiniband/core/uverbs_std_types_cq.c
> > +++ b/drivers/infiniband/core/uverbs_std_types_cq.c
> > @@ -193,8 +193,10 @@ static int UVERBS_HANDLER(UVERBS_METHOD_CQ_CREATE)(
> >
> > ret = umem ? ib_dev->ops.create_cq_umem(cq, &attr, umem, attrs) :
> > ib_dev->ops.create_cq(cq, &attr, attrs);
> > - if (ret)
> > + if (ret) {
> > + ib_umem_release(umem);
> > goto err_free;
> > + }
> >
> > obj->uevent.uobject.object = cq;
> > obj->uevent.uobject.user_handle = user_handle;
> > --
> > 2.39.5
> >
> >
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-10-10 7:38 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-10-09 16:40 [PATCH] RDMA/uverbs: fix umem release in UVERBS_METHOD_CQ_CREATE Shuhao Fu
2025-10-09 18:48 ` Leon Romanovsky
2025-10-10 7:37 ` Shuhao Fu
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).