Re: [PATCH] RDMA/core: fix refcount leak in __ib_alloc_pd()
From: Jason Gunthorpe
Date: Mon Jun 08 2026 - 14:38:43 EST
On Mon, Jun 08, 2026 at 08:56:25AM +0000, Wentao Liang wrote:
> The error handling in __ib_alloc_pd() has a refcount leak.
No it doesn't, the error handling is as designed.
> When get_dma_mr() fails it calls ib_dealloc_pd() which invokes
> ib_dealloc_pd_user(). If the driver's dealloc_pd operation returns
> an error, ib_dealloc_pd_user() returns early and skips both
> rdma_restrack_del() and kfree(pd). This leaves the resource
> tracking kref held and the pd memory unfreed. Because
> ib_dealloc_pd() has a void return, __ib_alloc_pd() cannot detect the
> failure, so the leak persists.
Yes, we can't handle failures on this path, the kernel verb
ib_dealloc_pd() could gain a WARN_ON to make these clearer, but the
correct thing for the user facing API is to just leave it as is
untouched.
If you mess with this you break the uverbs stuff pretty badly.
Jason