Skip to content

Commit

Permalink
vp_vdpa: fix id_table array not null terminated error
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
Xiaoguang Wang authored and mstsirkin committed Nov 6, 2024
1 parent 97ee04f commit 4e39eca
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions drivers/vdpa/virtio_pci/vp_vdpa.c
Original file line number Diff line number Diff line change
Expand Up @@ -612,7 +612,11 @@ static int vp_vdpa_probe(struct pci_dev *pdev, const struct pci_device_id *id)
goto mdev_err;
}

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

mdev_id->device = mdev->id.device;
mdev_id->vendor = mdev->id.vendor;
mdev_id[0].device = mdev->id.device;
mdev_id[0].vendor = mdev->id.vendor;
mgtdev->id_table = mdev_id;
mgtdev->max_supported_vqs = vp_modern_get_num_queues(mdev);
mgtdev->supported_features = vp_modern_get_features(mdev);
Expand Down

0 comments on commit 4e39eca

Please sign in to comment.