Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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: ffbda8e9df10 ("vdpa/vp_vdpa : add vdpa tool support in vp_vdpa")
Cc: stable@vger.kernel.org
Suggested-by: Parav Pandit <parav@nvidia.com>
Signed-off-by: Angus Chen <angus.chen@jaguarmicro.com>
Signed-off-by: Xiaoguang Wang <lege.wang@jaguarmicro.com>
Message-Id: <20241105133518.1494-1-lege.wang@jaguarmicro.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Reviewed-by: Parav Pandit <parav@nvidia.com>
Acked-by: Jason Wang <jasowang@redhat.com>

authored by

Xiaoguang Wang and committed by
Michael S. Tsirkin
4e39ecad 97ee04fe

+7 -3
+7 -3
drivers/vdpa/virtio_pci/vp_vdpa.c
··· 612 612 goto mdev_err; 613 613 } 614 614 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); 616 620 if (!mdev_id) { 617 621 err = -ENOMEM; 618 622 goto mdev_id_err; ··· 636 632 goto probe_err; 637 633 } 638 634 639 - mdev_id->device = mdev->id.device; 640 - mdev_id->vendor = mdev->id.vendor; 635 + mdev_id[0].device = mdev->id.device; 636 + mdev_id[0].vendor = mdev->id.vendor; 641 637 mgtdev->id_table = mdev_id; 642 638 mgtdev->max_supported_vqs = vp_modern_get_num_queues(mdev); 643 639 mgtdev->supported_features = vp_modern_get_features(mdev);