* [PATCH] RDMA/mlx5: Fix memory leak in GET_DATA_DIRECT_SYSFS_PATH handler
@ 2026-01-26 7:48 Zilin Guan
2026-01-26 9:30 ` Markus Elfring
2026-01-27 14:20 ` Leon Romanovsky
0 siblings, 2 replies; 4+ messages in thread
From: Zilin Guan @ 2026-01-26 7:48 UTC (permalink / raw)
To: leon; +Cc: jgg, yishaih, linux-rdma, linux-kernel, jianhao.xu, Zilin Guan
The UVERBS_HANDLER(MLX5_IB_METHOD_GET_DATA_DIRECT_SYSFS_PATH) function
allocates memory for the device path using kobject_get_path(). If the
length of the device path exceeds the output buffer length, the function
returns -ENOSPC but does not free the allocated memory, resulting in a
memory leak.
Add a kfree() call to the error path to ensure the allocated memory is
properly freed.
Compile tested only. Issue found using a prototype static analysis tool
and code review.
Fixes: ec7ad6530909 ("RDMA/mlx5: Introduce GET_DATA_DIRECT_SYSFS_PATH ioctl")
Signed-off-by: Zilin Guan <zilin@seu.edu.cn>
---
drivers/infiniband/hw/mlx5/std_types.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/drivers/infiniband/hw/mlx5/std_types.c b/drivers/infiniband/hw/mlx5/std_types.c
index 2fcf553044e1..ed4f5abb63c8 100644
--- a/drivers/infiniband/hw/mlx5/std_types.c
+++ b/drivers/infiniband/hw/mlx5/std_types.c
@@ -218,6 +218,7 @@ static int UVERBS_HANDLER(MLX5_IB_METHOD_GET_DATA_DIRECT_SYSFS_PATH)(
dev_path_len = strlen(dev_path) + 1;
if (dev_path_len > out_len) {
ret = -ENOSPC;
+ kfree(dev_path);
goto end;
}
--
2.34.1
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] RDMA/mlx5: Fix memory leak in GET_DATA_DIRECT_SYSFS_PATH handler
2026-01-26 7:48 [PATCH] RDMA/mlx5: Fix memory leak in GET_DATA_DIRECT_SYSFS_PATH handler Zilin Guan
@ 2026-01-26 9:30 ` Markus Elfring
2026-01-27 14:20 ` Leon Romanovsky
1 sibling, 0 replies; 4+ messages in thread
From: Markus Elfring @ 2026-01-26 9:30 UTC (permalink / raw)
To: Zilin Guan, linux-rdma, Leon Romanovsky
Cc: LKML, Jason Gunthorpe, Jianhao Xu, Yishai Hadas
…
> Add a kfree() call to the error path to ensure the allocated memory is
> properly freed.
…
How do you think about to use an additional label in the affected if branch instead?
https://elixir.bootlin.com/linux/v6.19-rc5/source/drivers/infiniband/hw/mlx5/std_types.c#L189-L231
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/coding-style.rst?h=v6.19-rc7#n526
See also once more:
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/stable-kernel-rules.rst?h=v6.19-rc7#n34
Regards,
Markus
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] RDMA/mlx5: Fix memory leak in GET_DATA_DIRECT_SYSFS_PATH handler
2026-01-26 7:48 [PATCH] RDMA/mlx5: Fix memory leak in GET_DATA_DIRECT_SYSFS_PATH handler Zilin Guan
2026-01-26 9:30 ` Markus Elfring
@ 2026-01-27 14:20 ` Leon Romanovsky
2026-02-27 7:32 ` Markus Elfring
1 sibling, 1 reply; 4+ messages in thread
From: Leon Romanovsky @ 2026-01-27 14:20 UTC (permalink / raw)
To: Zilin Guan; +Cc: jgg, yishaih, linux-rdma, linux-kernel, jianhao.xu
On Mon, 26 Jan 2026 07:48:01 +0000, Zilin Guan wrote:
> The UVERBS_HANDLER(MLX5_IB_METHOD_GET_DATA_DIRECT_SYSFS_PATH) function
> allocates memory for the device path using kobject_get_path(). If the
> length of the device path exceeds the output buffer length, the function
> returns -ENOSPC but does not free the allocated memory, resulting in a
> memory leak.
>
> Add a kfree() call to the error path to ensure the allocated memory is
> properly freed.
>
> [...]
Applied, thanks!
[1/1] RDMA/mlx5: Fix memory leak in GET_DATA_DIRECT_SYSFS_PATH handler
(no commit info)
Best regards,
--
Leon Romanovsky <leon@kernel.org>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: RDMA/mlx5: Fix memory leak in GET_DATA_DIRECT_SYSFS_PATH handler
2026-01-27 14:20 ` Leon Romanovsky
@ 2026-02-27 7:32 ` Markus Elfring
0 siblings, 0 replies; 4+ messages in thread
From: Markus Elfring @ 2026-02-27 7:32 UTC (permalink / raw)
To: Leon Romanovsky, Zilin Guan, linux-rdma
Cc: Leon Romanovsky, LKML, Jason Gunthorpe, Jianhao Xu, Yishai Hadas
…
> > Add a kfree() call to the error path to ensure the allocated memory is
> > properly freed.
…
> Applied, thanks!
>
> [1/1] RDMA/mlx5: Fix memory leak in GET_DATA_DIRECT_SYSFS_PATH handler
…
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?h=v7.0-rc1&id=9b9d253908478f504297ac283c514e5953ddafa6
I find that an other change description would fit better to the performed
source code adjustment.
Will further collateral evolution become more helpful accordingly?
https://elixir.bootlin.com/linux/v6.19.3/source/include/linux/cleanup.h#L157-L161
Regards,
Markus
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-02-27 7:32 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-01-26 7:48 [PATCH] RDMA/mlx5: Fix memory leak in GET_DATA_DIRECT_SYSFS_PATH handler Zilin Guan
2026-01-26 9:30 ` Markus Elfring
2026-01-27 14:20 ` Leon Romanovsky
2026-02-27 7:32 ` Markus Elfring
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®