[PATCH] vfio-user: avoid leaking duplicate device name

zhaoguohan@kylinos.cn posted 1 patch 1 month ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/20260424032209.297458-1-zhaoguohan@kylinos.cn
Maintainers: John Levon <john.levon@nutanix.com>, Thanos Makatos <thanos.makatos@nutanix.com>, "Cédric Le Goater" <clg@redhat.com>
hw/vfio-user/pci.c | 2 --
1 file changed, 2 deletions(-)
[PATCH] vfio-user: avoid leaking duplicate device name
Posted by zhaoguohan@kylinos.cn 1 month ago
From: GuoHan Zhao <zhaoguohan@kylinos.cn>

vfio_user_pci_realize() assigns vbasedev->name before connecting to the
server, then assigns the same name again after installing the request
handler.  The second assignment overwrites the first allocation, so only
the second string can be freed later by vfio_device_free_name().

Drop the duplicate assignment and keep the first name allocation, which is
also available on connection failures for error reporting.

Fixes: 36227628d824 ("vfio-user: implement message send infrastructure")
Signed-off-by: GuoHan Zhao <zhaoguohan@kylinos.cn>
---
 hw/vfio-user/pci.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/hw/vfio-user/pci.c b/hw/vfio-user/pci.c
index facc79727acb..e7573d4a9f08 100644
--- a/hw/vfio-user/pci.c
+++ b/hw/vfio-user/pci.c
@@ -280,8 +280,6 @@ static void vfio_user_pci_realize(PCIDevice *pdev, Error **errp)
     vbasedev->proxy = proxy;
     vfio_user_set_handler(vbasedev, vfio_user_pci_process_req, vdev);
 
-    vbasedev->name = g_strdup_printf("vfio-user:%s", sock_name);
-
     if (udev->send_queued) {
         proxy->flags |= VFIO_PROXY_FORCE_QUEUED;
     }
-- 
2.43.0
Re: [PATCH] vfio-user: avoid leaking duplicate device name
Posted by Cédric Le Goater 3 weeks, 5 days ago
On 4/24/26 05:22, zhaoguohan@kylinos.cn wrote:
> From: GuoHan Zhao <zhaoguohan@kylinos.cn>
> 
> vfio_user_pci_realize() assigns vbasedev->name before connecting to the
> server, then assigns the same name again after installing the request
> handler.  The second assignment overwrites the first allocation, so only
> the second string can be freed later by vfio_device_free_name().
> 
> Drop the duplicate assignment and keep the first name allocation, which is
> also available on connection failures for error reporting.
> 
> Fixes: 36227628d824 ("vfio-user: implement message send infrastructure")
> Signed-off-by: GuoHan Zhao <zhaoguohan@kylinos.cn>
> ---
>   hw/vfio-user/pci.c | 2 --
>   1 file changed, 2 deletions(-)
> 
> diff --git a/hw/vfio-user/pci.c b/hw/vfio-user/pci.c
> index facc79727acb..e7573d4a9f08 100644
> --- a/hw/vfio-user/pci.c
> +++ b/hw/vfio-user/pci.c
> @@ -280,8 +280,6 @@ static void vfio_user_pci_realize(PCIDevice *pdev, Error **errp)
>       vbasedev->proxy = proxy;
>       vfio_user_set_handler(vbasedev, vfio_user_pci_process_req, vdev);
>   
> -    vbasedev->name = g_strdup_printf("vfio-user:%s", sock_name);
> -
>       if (udev->send_queued) {
>           proxy->flags |= VFIO_PROXY_FORCE_QUEUED;
>       }


Applied to

     https://github.com/legoater/qemu vfio-next

Please base future contributions on this branch.

Thanks,

C.
Re: [PATCH] vfio-user: avoid leaking duplicate device name
Posted by John Levon 1 month ago
On Fri, Apr 24, 2026 at 11:22:09AM +0800, zhaoguohan@kylinos.cn wrote:

> vfio_user_pci_realize() assigns vbasedev->name before connecting to the
> server, then assigns the same name again after installing the request
> handler.  The second assignment overwrites the first allocation, so only
> the second string can be freed later by vfio_device_free_name().
> 
> Drop the duplicate assignment and keep the first name allocation, which is
> also available on connection failures for error reporting.
> 
> Fixes: 36227628d824 ("vfio-user: implement message send infrastructure")
> Signed-off-by: GuoHan Zhao <zhaoguohan@kylinos.cn>

Reviewed-by: John Levon <john.levon@nutanix.com>

regards
john