vfio/pci: Fix a use-after-free issue
PATCH v2 1/1 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.
---
v2: "toke" -> "token", Cedric
Update with Alex suggested change
hw/vfio/pci.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
hw/vfio/pci.c +1 -1
@@ -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);
Signature · 1 line
2.34.1
Quoted 6 lines · Zhenzhong Duan
vbasedev->nameis freed wrongly which leads to garbage VFIO trace log. Fix it by allocating a dup ofvbasedev->nameand then free the dup.Fixes 2dca1b37a7 ("vfio/pci: add support for VF token")Suggested-by Alex Williamson <[email protected]>Signed-off-by Zhenzhong Duan <[email protected]>
Thanks,
C.
Quoted 20 lines
---
v2: "toke" -> "token", Cedric
Update with Alex suggested changehw/vfio/pci.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)hw/vfio/pci.c +1
-1@@ -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);
Quoted 6 lines · Zhenzhong Duan
vbasedev->nameis freed wrongly which leads to garbage VFIO trace log. Fix it by allocating a dup ofvbasedev->nameand then free the dup.Fixes 2dca1b37a7 ("vfio/pci: add support for VF token")Suggested-by Alex Williamson <[email protected]>Signed-off-by Zhenzhong Duan <[email protected]>
Also verified that this resolves an issue seen on s390, as we were seeing not just garbage logs but QEMU crashes in certain cases e.g. during device unplug. Thanks!
Quoted 20 lines
---
v2: "toke" -> "token", Cedric
Update with Alex suggested changehw/vfio/pci.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)hw/vfio/pci.c +1
-1@@ -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);
Quoted 8 lines · On Tue, 23 May 2023 13:00:53 -0400 Matthew Rosato <[email protected]>…
Quoted 6 lines · Zhenzhong Duan
vbasedev->nameis freed wrongly which leads to garbage VFIO trace log. Fix it by allocating a dup ofvbasedev->nameand then free the dup.Fixes 2dca1b37a7 ("vfio/pci: add support for VF token")Suggested-by Alex Williamson <[email protected]>Signed-off-by Zhenzhong Duan <[email protected]>
Quoted 5 lines
Reviewed-by Matthew Rosato <[email protected]>Also verified that this resolves an issue seen on s390, as we were seeing not just garbage logs but QEMU crashes in certain cases e.g. during device unplug. Thanks!
Thanks for the testing and reminder, I'll get a pull request out for this. Thanks,
Alex
Quoted 21 lines
Quoted 20 lines
---
v2: "toke" -> "token", Cedric
Update with Alex suggested changehw/vfio/pci.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)hw/vfio/pci.c +1
-1@@ -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);
Alex Williamson
Acked-byQuoted 11 lines · On Tue, 23 May 2023 11:17:47 -0600 Alex Williamson…
Quoted 8 lines · On Tue, 23 May 2023 13:00:53 -0400 Matthew Rosato <[email protected]>…
Quoted 6 lines · Zhenzhong Duan
vbasedev->nameis freed wrongly which leads to garbage VFIO trace log. Fix it by allocating a dup ofvbasedev->nameand then free the dup.Fixes 2dca1b37a7 ("vfio/pci: add support for VF token")Suggested-by Alex Williamson <[email protected]>Signed-off-by Zhenzhong Duan <[email protected]>
Quoted 8 lines
Quoted 5 lines
Reviewed-by Matthew Rosato <[email protected]>Also verified that this resolves an issue seen on s390, as we were seeing not just garbage logs but QEMU crashes in certain cases e.g. during device unplug. Thanks!
Thanks for the testing and reminder, I'll get a pull request out for this. Thanks,
Actually Cedric volunteered to bundle this with some pending patches, so...
Quoted 22 lines
Quoted 21 lines
Quoted 20 lines
---
v2: "toke" -> "token", Cedric
Update with Alex suggested changehw/vfio/pci.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)hw/vfio/pci.c +1
-1@@ -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);
Quoted 6 lines · Zhenzhong Duan
vbasedev->nameis freed wrongly which leads to garbage VFIO trace log. Fix it by allocating a dup ofvbasedev->nameand then free the dup.Fixes 2dca1b37a7 ("vfio/pci: add support for VF token")Suggested-by Alex Williamson <[email protected]>Signed-off-by Zhenzhong Duan <[email protected]>
Quoted 6 lines
---
v2: "toke" -> "token", Cedric
Update with Alex suggested changehw/vfio/pci.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)