Skip to contentSkip to conversation

vfio/pci: Fix a use-after-free issue

PATCH In review Zhenzhong Duan 5 participants 6 messages May 17, 2023 – May 24, 2023

lore
Share & tools
lore
#0 lore raw

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.

Fixes 2dca1b37a7 ("vfio/pci: add support for VF token")

---
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
index bf27a3990564..73874a94de12 100644
@@ -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
Reviewed-by on v2 1/1
#1 lore raw
Quoted 6 lines · Zhenzhong Duan

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 2dca1b37a7 ("vfio/pci: add support for VF token")

Thanks,

C.

Quoted 20 lines

---
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
index bf27a3990564..73874a94de12 100644
@@ -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);
Reviewed-by on v2 1/1
#2 lore raw
In reply to Zhenzhong Duan
Quoted 6 lines · Zhenzhong Duan

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 2dca1b37a7 ("vfio/pci: add support for VF token")

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 change

 hw/vfio/pci.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/vfio/pci.c +1 -1
index bf27a3990564..73874a94de12 100644
@@ -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);
#3 lore raw
Quoted 8 lines · On Tue, 23 May 2023 13:00:53 -0400 Matthew Rosato <[email protected]>…
Quoted 6 lines · Zhenzhong Duan

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 2dca1b37a7 ("vfio/pci: add support for VF token")
Quoted 5 lines

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 change

 hw/vfio/pci.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/vfio/pci.c +1 -1
index bf27a3990564..73874a94de12 100644
@@ -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);  
#4 lore raw
Quoted 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->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 2dca1b37a7 ("vfio/pci: add support for VF token")
Quoted 8 lines
Quoted 5 lines

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 change

 hw/vfio/pci.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/vfio/pci.c +1 -1
index bf27a3990564..73874a94de12 100644
@@ -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);    
Reviewed-by on v2 1/1
#5 lore raw
In reply to Zhenzhong Duan
Quoted 6 lines · Zhenzhong Duan

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 2dca1b37a7 ("vfio/pci: add support for VF token")
Quoted 6 lines

---
v2: "toke" -> "token", Cedric
Update with Alex suggested change

  hw/vfio/pci.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)