Skip to contentSkip to conversation

vfio/pci: Init the count variable in collecting hot-reset devices

PATCH In review Yi Liu 4 participants 4 messages Jul 10, 2024

Subsystems (2)
lore
Share & tools
lore

Yi Liu

author
#0 lore raw

PATCH 1/1 vfio/pci: Init the count variable in collecting hot-reset devices

The count variable is used without initialization, it results in mistakes in the device counting and crashes the userspace if the get hot reset info path is triggered.

Fixes f6944d4a0b87 ("vfio/pci: Collect hot-reset devices to local buffer")
Cc Beld Zhang <[email protected]>
---
 drivers/vfio/pci/vfio_pci_core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/vfio/pci/vfio_pci_core.c +1 -1
index 59af22f6f826..0a7bfdd08bc7 100644
@@ -1260,7 +1260,7 @@ static int vfio_pci_ioctl_get_pci_hot_reset_info(
 	struct vfio_pci_hot_reset_info hdr;
 	struct vfio_pci_fill_info fill = {};
 	bool slot = false;
-	int ret, count;
+	int ret, count = 0;
 
 	if (copy_from_user(&hdr, arg, minsz))
 		return -EFAULT;
Signature · 1 line
2.34.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 7 lines

From: Yi Liu <[email protected]>
Sent: Wednesday, July 10, 2024 8:42 AM

The count variable is used without initialization, it results in mistakes in the device counting and crashes the userspace if the get hot reset info path is triggered.

Quoted 5 lines
Fixes f6944d4a0b87 ("vfio/pci: Collect hot-reset devices to local buffer")
Cc Beld Zhang <[email protected]>
#2 lore raw
In reply to Yi Liu
Quoted 18 lines · On Tue, 9 Jul 2024 17:41:50 -0700 Yi Liu <[email protected]> wrote:

The count variable is used without initialization, it results in mistakes in the device counting and crashes the userspace if the get hot reset info path is triggered.

Fixes f6944d4a0b87 ("vfio/pci: Collect hot-reset devices to local buffer")
Cc Beld Zhang <[email protected]>
---
 drivers/vfio/pci/vfio_pci_core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/vfio/pci/vfio_pci_core.c +0 -0
index 59af22f6f826..0a7bfdd08bc7 100644

drivers/vfio/pci/vfio_pci_core.c static int vfio_pci_ioctl_get_pci_hot_reset_info( · line 1266

Quoted 8 lines
drivers/vfio/pci/vfio_pci_core.c +1 -1
@@ -1260,7 +1260,7 @@ static int vfio_pci_ioctl_get_pci_hot_reset_info(
 	struct vfio_pci_hot_reset_info hdr;
 	struct vfio_pci_fill_info fill = {};
 	bool slot = false;
-	int ret, count;
+	int ret, count = 0;
 
 	if (copy_from_user(&hdr, arg, minsz))
 		return -EFAULT;

Thanks, Yi! I just got back from a long weekend and was planning to debug this. Thanks for finding the bug!

Alex

Reviewed-by on v1 1/1
#3 lore raw
In reply to Yi Liu
Quoted 4 lines · Yi Liu

The count variable is used without initialization, it results in mistakes in the device counting and crashes the userspace if the get hot reset info path is triggered.

Quoted 8 lines
Fixes f6944d4a0b87 ("vfio/pci: Collect hot-reset devices to local buffer")
Cc Beld Zhang <[email protected]>
---
 drivers/vfio/pci/vfio_pci_core.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Jason