Skip to contentSkip to conversation

vfio: fix potential memory leak in vfio_msi_cap_len

PATCH In review Li Qiang 4 participants 4 messages Aug 27, 2018 – Sep 4, 2018

Subsystems (2)
lore
Share & tools
lore

Li Qiang

author
#0 lore raw

PATCH 1/1 vfio: fix potential memory leak in vfio_msi_cap_len

Free the vdev->msi_perm in error path.

---
 drivers/vfio/pci/vfio_pci_config.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/vfio/pci/vfio_pci_config.c +3 -1
index 115a36f6f403..62023b4a373b 100644
@@ -1180,8 +1180,10 @@ static int vfio_msi_cap_len(struct vfio_pci_device *vdev, u8 pos)
 		return -ENOMEM;
 
 	ret = init_pci_cap_msi_perm(vdev->msi_perm, len, flags);
-	if (ret)
+	if (ret) {
+		kfree(vdev->msi_perm);
 		return ret;
+	}
 
 	return len;
 }
Signature · 1 line
2.11.0
#1 lore raw
Quoted 14 lines · Li Qiang

Free the vdev->msi_perm in error path.

---
 drivers/vfio/pci/vfio_pci_config.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/vfio/pci/vfio_pci_config.c +0 -0
index 115a36f6f403..62023b4a373b 100644
@@ -1180,8 +1180,10 @@ static int vfio_msi_cap_len(struct vfio_pci_device *vdev, u8 pos)
 		return -ENOMEM;

drivers/vfio/pci/vfio_pci_config.c static int vfio_msi_cap_len(struct vfio_pci_device *vdev, u8 pos) · line 1189

Quoted 10 lines
drivers/vfio/pci/vfio_pci_config.c +3 -1
 
 	ret = init_pci_cap_msi_perm(vdev->msi_perm, len, flags);
-	if (ret)
+	if (ret) {
+		kfree(vdev->msi_perm);
 		return ret;
+	}
 
 	return len;
 }

Doesn't vfio_config_free() take care of that in all cases?

Signature · 3 lines
Thanks,

David / dhildenb
Reviewed-by
#2 lore raw

Hi Li, David,

Quoted 22 lines · David Hildenbrand
Quoted 21 lines · Li Qiang

Free the vdev->msi_perm in error path.

---
 drivers/vfio/pci/vfio_pci_config.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/vfio/pci/vfio_pci_config.c +3 -1
index 115a36f6f403..62023b4a373b 100644
@@ -1180,8 +1180,10 @@ static int vfio_msi_cap_len(struct vfio_pci_device *vdev, u8 pos)
 		return -ENOMEM;
 
 	ret = init_pci_cap_msi_perm(vdev->msi_perm, len, flags);
-	if (ret)
+	if (ret) {
+		kfree(vdev->msi_perm);
 		return ret;
+	}
 
Quoted 5 lines

drivers/vfio/pci/vfio_pci_config.c static int vfio_msi_cap_len(struct vfio_pci_device *vdev, u8 pos) · line 1189

Quoted 3 lines
drivers/vfio/pci/vfio_pci_config.c +0 -0
 	return len;
 }

Doesn't vfio_config_free() take care of that in all cases?

Looks OK to me.

Looks vfio_config_free is called on vfio_pci_release whereas vfio_msi_cap_len can fail in vfio_pci_open path.

Thanks

Eric

Quoted 1 line
#3 lore raw
In reply to Li Qiang
Quoted 13 lines · On Mon, 27 Aug 2018 05:47:21 -0700 Li Qiang <[email protected]> wrote:

Free the vdev->msi_perm in error path.

---
 drivers/vfio/pci/vfio_pci_config.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/vfio/pci/vfio_pci_config.c +0 -0
index 115a36f6f403..62023b4a373b 100644
@@ -1180,8 +1180,10 @@ static int vfio_msi_cap_len(struct vfio_pci_device *vdev, u8 pos)
 		return -ENOMEM;

drivers/vfio/pci/vfio_pci_config.c static int vfio_msi_cap_len(struct vfio_pci_device *vdev, u8 pos) · line 1189

Quoted 10 lines
drivers/vfio/pci/vfio_pci_config.c +3 -1
 
 	ret = init_pci_cap_msi_perm(vdev->msi_perm, len, flags);
-	if (ret)
+	if (ret) {
+		kfree(vdev->msi_perm);
 		return ret;
+	}
 
 	return len;
 }

Fix looks correct to me, I'll queue this for v4.20 with Eric's R-b. Thanks,

Alex