Skip to contentSkip to conversation

RDMA/uverbs: fix umem release in UVERBS_METHOD_CQ_CREATE

PATCH Superseded Shuhao Fu 2 participants 3 messages Oct 9, 2025 – Oct 10, 2025 InfiniBand

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Shuhao Fu

author
#0 lore raw

PATCH 1/1 RDMA/uverbs: fix umem release in UVERBS_METHOD_CQ_CREATE

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")
---
 drivers/infiniband/core/uverbs_std_types_cq.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/infiniband/core/uverbs_std_types_cq.c +3 -1
index 37cd37556510..9344020dede1 100644
@@ -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;
Signature · 1 line
2.39.5
#1 lore raw
Quoted 3 lines · Shuhao Fu

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.

Quoted 27 lines
Fixes 1a40c362ae26 ("RDMA/uverbs: Add a common way to create CQ with umem")
---
 drivers/infiniband/core/uverbs_std_types_cq.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/infiniband/core/uverbs_std_types_cq.c +3 -1
index 37cd37556510..9344020dede1 100644
@@ -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;
Signature · 1 line
2.39.5
author
#2 lore raw
Quoted 9 lines · Leon Romanovsky
Quoted 3 lines · Shuhao Fu

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/[email protected]/

Quoted 27 lines
Quoted 27 lines
Fixes 1a40c362ae26 ("RDMA/uverbs: Add a common way to create CQ with umem")
---
 drivers/infiniband/core/uverbs_std_types_cq.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/infiniband/core/uverbs_std_types_cq.c +3 -1
index 37cd37556510..9344020dede1 100644
@@ -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;
Signature · 1 line
2.39.5