Skip to contentSkip to conversation

RDMA/core: Fix FRMR handle leak on push_handle_to_queue_locked failure

PATCH In review Tao Cui 2 participants 3 messages Jun 8 – Jun 11 InfiniBand

lore
Share & tools
lore

Tao Cui

author
#0 lore raw

PATCH 1/1 RDMA/core: Fix FRMR handle leak on push_handle_to_queue_locked failure

From: Tao Cui <[email protected]>

In ib_frmr_pools_set_pinned(), after create_frmrs() successfully allocates handles, the push loop may fail partway through due to -ENOMEM from kzalloc in push_handle_to_queue_locked(). The remaining created-but-unpushed handles are silently leaked as they are never destroyed.

Call destroy_frmrs() for the remaining unpushed handles before returning the error.

Fixes ce5df0b891ed ("IB/core: Introduce FRMR pools")
---
 drivers/infiniband/core/frmr_pools.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/infiniband/core/frmr_pools.c +3 -0
index 5e992ff3d7cf..d7906fab033f 100644
@@ -443,6 +443,9 @@ int ib_frmr_pools_set_pinned(struct ib_device *device, struct ib_frmr_key *key,
 
 end:
 	spin_unlock(&pool->lock);
+	if (ret && i < needed_handles)
+		pools->pool_ops->destroy_frmrs(device, &handles[i],
+					       needed_handles - i);
 	kfree(handles);
 
 schedule_aging:
Signature · 1 line
2.43.0
#1 lore raw
Quoted 22 lines · Tao Cui

From: Tao Cui <[email protected]>

In ib_frmr_pools_set_pinned(), after create_frmrs() successfully allocates handles, the push loop may fail partway through due to -ENOMEM from kzalloc in push_handle_to_queue_locked(). The remaining created-but-unpushed handles are silently leaked as they are never destroyed.

Call destroy_frmrs() for the remaining unpushed handles before returning the error.

Fixes ce5df0b891ed ("IB/core: Introduce FRMR pools")
---
  drivers/infiniband/core/frmr_pools.c | 3 +++
  1 file changed, 3 insertions(+)
drivers/infiniband/core/frmr_pools.c +0 -0
index 5e992ff3d7cf..d7906fab033f 100644

drivers/infiniband/core/frmr_pools.c int ib_frmr_pools_set_pinned(struct ib_device *device, struct ib_frmr_key *key, · line 448

Quoted 6 lines
drivers/infiniband/core/frmr_pools.c +3 -0
@@ -443,6 +443,9 @@ int ib_frmr_pools_set_pinned(struct ib_device *device, struct ib_frmr_key *key,
 
  end:
  	spin_unlock(&pool->lock);
+	if (ret && i < needed_handles)
+		pools->pool_ops->destroy_frmrs(device, &handles[i],
+					       needed_handles - i);

The second condition is redundant, only failure to reach this point is push() failure.

I've sent a similar fix in a series of fixes for frmr pools. Please take a look.
https://lore.kernel.org/linux-rdma/[email protected]/T/#m34f6910f8b8e998b079fcf5f468cb3c5056f78b9

Michael

Quoted 3 lines
drivers/infiniband/core/frmr_pools.c +0 -0
  	kfree(handles);
 
  schedule_aging:
author
#2 lore raw

Hi Michael,

Thanks for the review and the pointer to your series.

You're right — the i < needed_handles check is redundant since ret != 0 already implies we broke out of the loop before completion. Your approach of using break instead of goto end is also cleaner.

Thanks,
--
Tao

Quoted 39 lines · Michael Gur
Quoted 22 lines · Tao Cui

From: Tao Cui <[email protected]>

In ib_frmr_pools_set_pinned(), after create_frmrs() successfully allocates handles, the push loop may fail partway through due to -ENOMEM from kzalloc in push_handle_to_queue_locked(). The remaining created-but-unpushed handles are silently leaked as they are never destroyed.

Call destroy_frmrs() for the remaining unpushed handles before returning the error.

Fixes ce5df0b891ed ("IB/core: Introduce FRMR pools")

---
  drivers/infiniband/core/frmr_pools.c | 3 +++

  1 file changed, 3 insertions(+)
drivers/infiniband/core/frmr_pools.c +0 -0
index 5e992ff3d7cf..d7906fab033f 100644
@@ -443,6 +443,9 @@ int ib_frmr_pools_set_pinned(struct ib_device *device, struct ib_frmr_key *key,
Quoted 5 lines

    end:
      spin_unlock(&pool->lock);
+    if (ret && i < needed_handles)
+        pools->pool_ops->destroy_frmrs(device, &handles[i], +                           needed_handles - i);

The second condition is redundant, only failure to reach this point is push() failure.

I've sent a similar fix in a series of fixes for frmr pools. Please take a look.
https://lore.kernel.org/linux-rdma/[email protected]/T/#m34f6910f8b8e998b079fcf5f468cb3c5056f78b9

Michael

Quoted 2 lines

      kfree(handles);
    schedule_aging: