vfio/pci: Fix a use-after-free issue
PATCH 1/1 vfio/pci: Fix a use-after-free issue
We should free the duplicated variant of vbasedev->name plus uuid rather than vbasedev->name itself.
--- hw/vfio/pci.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
hw/vfio/pci.c +3 -1
@@ -2998,7 +2998,9 @@ static void vfio_realize(PCIDevice *pdev, Error **errp) } ret =vfio_get_device (group, name, vbasedev, errp); -g_free (name); +if (name != vbasedev->name) { +g_free (name); + }if (ret) {vfio_put_group (group); goto error;
Signature · 1 line
2.34.1
Quoted 4 lines · Zhenzhong Duan
We should free the duplicated variant of
vbasedev->nameplus uuid rather thanvbasedev->nameitself.Fixes 2dca1b37a7 ("vfio/pci: add support for VF toke")
"toke" -> "token"
Quoted 10 lines
Signed-off-by Zhenzhong Duan <[email protected]>--- hw/vfio/pci.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)hw/vfio/pci.c +0
-0
hw/vfio/pci.c static void vfio_realize(PCIDevice *pdev, Error **errp) · line 3001
Quoted 5 lines
hw/vfio/pci.c +1
-1@@ -2998,7 +2998,9 @@ static void vfio_realize(PCIDevice *pdev, Error **errp) } ret =vfio_get_device (group, name, vbasedev, errp); -g_free (name); +if (name != vbasedev->name) {
yes. I wonder if we shouldn't use the same test with which 'name' was allocated instead :
if (!qemu_uuid_is_null(&vdev->vf_token)) {Thanks,
C.
Quoted 5 lines
hw/vfio/pci.c +2
-0+g_free (name); + }if (ret) {vfio_put_group (group); goto error;
Quoted 11 lines
-----Original Message-----
From: Cédric Le Goater <[email protected]>
Sent: Tuesday, May 16, 2023 4:58 PM
To: Duan, Zhenzhong <[email protected]>; qemu- [email protected]
Cc: [email protected]; [email protected]; Peng, Chao P <[email protected]>
Subject: Re: [PATCH] vfio/pci: Fix a use-after-free issue
Quoted 7 lines
Quoted 4 lines · Zhenzhong Duan
We should free the duplicated variant of
vbasedev->nameplus uuid rather thanvbasedev->nameitself.Fixes 2dca1b37a7 ("vfio/pci: add support for VF toke")"toke" -> "token"
Will fix, thanks
Quoted 19 lines
hw/vfio/pci.c static void vfio_realize(PCIDevice *pdev, Error
Quoted 11 lines
Signed-off-by Zhenzhong Duan <[email protected]>--- hw/vfio/pci.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)hw/vfio/pci.c index renamed from hw/vfio/pci.c +0
-0
bf27a3990564..d2593681e000100644hw/vfio/pci.c +0
-0@@ -2998,7 +2998,9 @@ static void vfio_realize(PCIDevice *pdev, Error**errp)
hw/vfio/pci.c static void vfio_realize(PCIDevice *pdev, Error **errp) · line 3001
Quoted 5 lines
hw/vfio/pci.c +1
-1} ret =vfio_get_device (group, name, vbasedev, errp); -g_free (name); +if (name != vbasedev->name) {
Quoted 4 lines
yes. I wonder if we shouldn't use the same test with which 'name' was allocated instead :
if (!qemu_uuid_is_null(&vdev->vf_token)) {
I think they are same effect and " if (name != vbasedev->name) {" is a bit more optimal. If you prefer " if (!qemu_uuid_is_null(&vdev->vf_token)) {", let me know and I'll update in v2.
Thanks
Zhenzhong
Quoted 37 lines · Zhenzhong
Quoted 9 lines
-----Original Message-----
From: Cédric Le Goater <[email protected]>
Sent: Tuesday, May 16, 2023 4:58 PM
To: Duan, Zhenzhong <[email protected]>; qemu- [email protected]
Cc: [email protected]; [email protected]; Peng, Chao P <[email protected]>
Subject: Re: [PATCH] vfio/pci: Fix a use-after-free issueQuoted 7 lines
Quoted 4 lines · Zhenzhong Duan
We should free the duplicated variant of
vbasedev->nameplus uuid rather thanvbasedev->nameitself.Fixes 2dca1b37a7 ("vfio/pci: add support for VF toke")"toke" -> "token"
Will fix, thanks
Quoted 19 lines
hw/vfio/pci.c static void vfio_realize(PCIDevice *pdev, Error
Quoted 11 lines
Signed-off-by Zhenzhong Duan <[email protected]>--- hw/vfio/pci.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)hw/vfio/pci.c index renamed from hw/vfio/pci.c +0
-0
bf27a3990564..d2593681e000100644hw/vfio/pci.c +0
-0@@ -2998,7 +2998,9 @@ static void vfio_realize(PCIDevice *pdev, Error**errp)
Quoted 5 lines
hw/vfio/pci.c +1
-1} ret =vfio_get_device (group, name, vbasedev, errp); -g_free (name); +if (name != vbasedev->name) {
Quoted 8 lines
Quoted 4 lines
yes. I wonder if we shouldn't use the same test with which 'name' was allocated instead :
if (!qemu_uuid_is_null(&vdev->vf_token)) {I think they are same effect and " if (name !=
vbasedev->name) {" is a bit more optimal. If you prefer " if (!qemu_uuid_is_null(&vdev->vf_token)) {", let me know and I'll update in v2.
My preference would be that both paths allocate name so that we don't need to conditionalize the free. For example:
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);
Thanks,
Alex