RDMA/uverbs: fix umem release in UVERBS_METHOD_CQ_CREATE
Subsystems (2)
PATCH v2 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.
In this patch, we release umem at UVERBS_METHOD_CQ_CREATE, the driver should not release umem if it returns an error code.
---
Change to v1: [1]
- do not let driver free umem
[1] https://lore.kernel.org/linux-rdma/aOflenF0XHtm80G9@homelab/
--- drivers/infiniband/core/uverbs_std_types_cq.c | 4 +++- drivers/infiniband/hw/efa/efa_verbs.c | 12 +++++------- 2 files changed, 8 insertions(+), 8 deletions(-)
drivers/infiniband/core/uverbs_std_types_cq.c +3 -1
@@ -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;
drivers/infiniband/hw/efa/efa_verbs.c +5 -7
@@ -1216,13 +1216,13 @@ int efa_create_cq_umem(struct ib_cq *ibcq, const struct ib_cq_init_attr *attr,if (umem->length < cq->size) {ibdev_dbg (&dev->ibdev,"External memory too small\n" ); err = -EINVAL ; - goto err_free_mem; + goto err_out; }if (!ib_umem_is_contiguous (umem)) {ibdev_dbg (&dev->ibdev,"Non contiguous CQ unsupported\n" ); err = -EINVAL ; - goto err_free_mem; + goto err_out; } cq->cpu_addr =NULL ;
@@ -1251,7 +1251,7 @@ int efa_create_cq_umem(struct ib_cq *ibcq, const struct ib_cq_init_attr *attr, err =efa_com_create_cq (&dev->edev, ¶ms, &result);if (err) - goto err_free_mem; + goto err_free_mapped; resp.db_off = result.db_off; resp.cq_idx = result.cq_idx;
@@ -1299,10 +1299,8 @@ int efa_create_cq_umem(struct ib_cq *ibcq, const struct ib_cq_init_attr *attr,efa_cq_user_mmap_entries_remove (cq); err_destroy_cq:efa_destroy_cq_idx (dev, cq->cq_idx); -err_free_mem: -if (umem) -ib_umem_release (umem); -else +err_free_mapped: +if (!umem)efa_free_mapped (dev, cq->cpu_addr, cq->dma_addr, cq->size,DMA_FROM_DEVICE ); err_out:
Signature · 1 line
2.39.5 (Apple Git-154)
Leon Romanovsky
AppliedQuoted 8 lines · Shuhao Fu
In
UVERBS_METHOD_CQ_CREATE, umem should be released if anything goes wrong. Currently, ifcreate_cq_umemfails, umem would not be released or referenced, causing a possible leak.In this patch, we release umem at
UVERBS_METHOD_CQ_CREATE, the driver should not release umem if it returns an error code.[...]
Applied, thanks!
[1/1] RDMA/uverbs: fix umem release in UVERBS_METHOD_CQ_CREATE
https://git.kernel.org/rdma/rdma/c/d8713158faad0f
Best regards,
Signature · 1 line
Leon Romanovsky <[email protected]>