From: Zhenzhong Duan Date: Wed, 17 May 2023 02:46:51 +0000 (+0800) Subject: vfio/pci: Fix a use-after-free issue X-Git-Url: http://git.maquefel.me/?a=commitdiff_plain;h=b83b40b614846b86e69f1680aec379594dc77d6b;p=qemu.git vfio/pci: Fix a use-after-free issue vbasedev->name is freed wrongly which leads to garbage VFIO trace log. Fix it by allocating a dup of vbasedev->name and then free the dup. Fixes: 2dca1b37a760 ("vfio/pci: add support for VF token") Suggested-by: Alex Williamson Signed-off-by: Zhenzhong Duan Reviewed-by: Cédric Le Goater Reviewed-by: Matthew Rosato Acked-by: Alex Williamson Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Cédric Le Goater --- diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c index bf27a39905..73874a94de 100644 --- a/hw/vfio/pci.c +++ b/hw/vfio/pci.c @@ -2994,7 +2994,7 @@ static void vfio_realize(PCIDevice *pdev, Error **errp) qemu_uuid_unparse(&vdev->vf_token, uuid); name = g_strdup_printf("%s vf_token=%s", vbasedev->name, uuid); } else { - name = vbasedev->name; + name = g_strdup(vbasedev->name); } ret = vfio_get_device(group, name, vbasedev, errp);