* [PATCH v2] IB/iwpm: fix memory leaks in error paths
@ 2026-06-22 13:45 Wentao Liang
2026-06-28 13:52 ` Leon Romanovsky
0 siblings, 1 reply; 2+ messages in thread
From: Wentao Liang @ 2026-06-22 13:45 UTC (permalink / raw)
To: Jason Gunthorpe, Leon Romanovsky
Cc: Florian Westphal, Kees Cook, linux-rdma, linux-kernel,
Wentao Liang
In iwpm_register_pid(),iwpm_add_mapping() and
iwpm_add_and_query_mapping(), when the send operations fail,
the allocated message buffers are not freed before returning,
causing memory leaks.
Fix this by adding proper error handling with goto labels to
ensure kfree() is called on all error paths in both functions.
Fixes: 30dc5e63d6a5 ("RDMA/core: Add support for iWARP Port Mapper user space service")
Signed-off-by: Wentao Liang <vulab@iscas.ac.cn>
---
drivers/infiniband/core/iwpm_msg.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/drivers/infiniband/core/iwpm_msg.c b/drivers/infiniband/core/iwpm_msg.c
index 4625abd29ac0..bac3d1f321ab 100644
--- a/drivers/infiniband/core/iwpm_msg.c
+++ b/drivers/infiniband/core/iwpm_msg.c
@@ -122,7 +122,7 @@ int iwpm_register_pid(struct iwpm_dev_data *pm_msg, u8 nl_client)
pr_info("%s: %s (client = %u)\n", __func__, err_str, nl_client);
dev_kfree_skb(skb);
if (nlmsg_request)
- iwpm_free_nlmsg_request(&nlmsg_request->kref);
+ kref_put(&nlmsg_request->kref, iwpm_free_nlmsg_request);
return ret;
}
@@ -207,7 +207,7 @@ int iwpm_add_mapping(struct iwpm_sa_data *pm_msg, u8 nl_client)
add_mapping_error_nowarn:
dev_kfree_skb(skb);
if (nlmsg_request)
- iwpm_free_nlmsg_request(&nlmsg_request->kref);
+ kref_put(&nlmsg_request->kref, iwpm_free_nlmsg_request);
return ret;
}
@@ -296,7 +296,7 @@ int iwpm_add_and_query_mapping(struct iwpm_sa_data *pm_msg, u8 nl_client)
query_mapping_error_nowarn:
dev_kfree_skb(skb);
if (nlmsg_request)
- iwpm_free_nlmsg_request(&nlmsg_request->kref);
+ kref_put(&nlmsg_request->kref, iwpm_free_nlmsg_request);
return ret;
}
--
2.39.5 (Apple Git-154)
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH v2] IB/iwpm: fix memory leaks in error paths
2026-06-22 13:45 [PATCH v2] IB/iwpm: fix memory leaks in error paths Wentao Liang
@ 2026-06-28 13:52 ` Leon Romanovsky
0 siblings, 0 replies; 2+ messages in thread
From: Leon Romanovsky @ 2026-06-28 13:52 UTC (permalink / raw)
To: Wentao Liang
Cc: Jason Gunthorpe, Florian Westphal, Kees Cook, linux-rdma,
linux-kernel
On Mon, Jun 22, 2026 at 09:45:53PM +0800, Wentao Liang wrote:
> In iwpm_register_pid(),iwpm_add_mapping() and
> iwpm_add_and_query_mapping(), when the send operations fail,
> the allocated message buffers are not freed before returning,
> causing memory leaks.
>
> Fix this by adding proper error handling with goto labels to
> ensure kfree() is called on all error paths in both functions.
> Fixes: 30dc5e63d6a5 ("RDMA/core: Add support for iWARP Port Mapper user space service")
> Signed-off-by: Wentao Liang <vulab@iscas.ac.cn>
> ---
> drivers/infiniband/core/iwpm_msg.c | 6 +++---
> 1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/infiniband/core/iwpm_msg.c b/drivers/infiniband/core/iwpm_msg.c
> index 4625abd29ac0..bac3d1f321ab 100644
> --- a/drivers/infiniband/core/iwpm_msg.c
> +++ b/drivers/infiniband/core/iwpm_msg.c
> @@ -122,7 +122,7 @@ int iwpm_register_pid(struct iwpm_dev_data *pm_msg, u8 nl_client)
> pr_info("%s: %s (client = %u)\n", __func__, err_str, nl_client);
> dev_kfree_skb(skb);
> if (nlmsg_request)
> - iwpm_free_nlmsg_request(&nlmsg_request->kref);
> + kref_put(&nlmsg_request->kref, iwpm_free_nlmsg_request);
> return ret;
> }
>
> @@ -207,7 +207,7 @@ int iwpm_add_mapping(struct iwpm_sa_data *pm_msg, u8 nl_client)
> add_mapping_error_nowarn:
> dev_kfree_skb(skb);
> if (nlmsg_request)
> - iwpm_free_nlmsg_request(&nlmsg_request->kref);
> + kref_put(&nlmsg_request->kref, iwpm_free_nlmsg_request);
We already discussed this change.
https://lore.kernel.org/linux-rdma/20260608183438.GA95325@nvidia.com/
Thanks
> return ret;
> }
>
> @@ -296,7 +296,7 @@ int iwpm_add_and_query_mapping(struct iwpm_sa_data *pm_msg, u8 nl_client)
> query_mapping_error_nowarn:
> dev_kfree_skb(skb);
> if (nlmsg_request)
> - iwpm_free_nlmsg_request(&nlmsg_request->kref);
> + kref_put(&nlmsg_request->kref, iwpm_free_nlmsg_request);
> return ret;
> }
>
> --
> 2.39.5 (Apple Git-154)
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-06-28 13:53 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-06-22 13:45 [PATCH v2] IB/iwpm: fix memory leaks in error paths Wentao Liang
2026-06-28 13:52 ` Leon Romanovsky
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.