Skip to content

Commit 4e39eca

Browse files
Xiaoguang Wangmstsirkin
authored andcommitted
vp_vdpa: fix id_table array not null terminated error
Allocate one extra virtio_device_id as null terminator, otherwise vdpa_mgmtdev_get_classes() may iterate multiple times and visit undefined memory. Fixes: ffbda8e ("vdpa/vp_vdpa : add vdpa tool support in vp_vdpa") Cc: [email protected] Suggested-by: Parav Pandit <[email protected]> Signed-off-by: Angus Chen <[email protected]> Signed-off-by: Xiaoguang Wang <[email protected]> Message-Id: <[email protected]> Signed-off-by: Michael S. Tsirkin <[email protected]> Reviewed-by: Parav Pandit <[email protected]> Acked-by: Jason Wang <[email protected]>
1 parent 97ee04f commit 4e39eca

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

drivers/vdpa/virtio_pci/vp_vdpa.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -612,7 +612,11 @@ static int vp_vdpa_probe(struct pci_dev *pdev, const struct pci_device_id *id)
612612
goto mdev_err;
613613
}
614614

615-
mdev_id = kzalloc(sizeof(struct virtio_device_id), GFP_KERNEL);
615+
/*
616+
* id_table should be a null terminated array, so allocate one additional
617+
* entry here, see vdpa_mgmtdev_get_classes().
618+
*/
619+
mdev_id = kcalloc(2, sizeof(struct virtio_device_id), GFP_KERNEL);
616620
if (!mdev_id) {
617621
err = -ENOMEM;
618622
goto mdev_id_err;
@@ -632,8 +636,8 @@ static int vp_vdpa_probe(struct pci_dev *pdev, const struct pci_device_id *id)
632636
goto probe_err;
633637
}
634638

635-
mdev_id->device = mdev->id.device;
636-
mdev_id->vendor = mdev->id.vendor;
639+
mdev_id[0].device = mdev->id.device;
640+
mdev_id[0].vendor = mdev->id.vendor;
637641
mgtdev->id_table = mdev_id;
638642
mgtdev->max_supported_vqs = vp_modern_get_num_queues(mdev);
639643
mgtdev->supported_features = vp_modern_get_features(mdev);

0 commit comments

Comments
 (0)