RE: [PATCH V3] vp_vdpa: fix id_table array not null terminated error

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




> From: Xiaoguang Wang <lege.wang@xxxxxxxxxxxxxxx>
> Sent: Tuesday, November 5, 2024 7:05 PM
> 
> 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@xxxxxxxxxxxxxxx
> Suggested-by: Parav Pandit <parav@xxxxxxxxxx>
> Signed-off-by: Angus Chen <angus.chen@xxxxxxxxxxxxxxx>
> Signed-off-by: Xiaoguang Wang <lege.wang@xxxxxxxxxxxxxxx>
> ---
> V3:
>  Use array assignment style for mdev_id.
> V2:
>   Use kcalloc() api.
> ---
>  drivers/vdpa/virtio_pci/vp_vdpa.c | 10 +++++++---
>  1 file changed, 7 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/vdpa/virtio_pci/vp_vdpa.c
> b/drivers/vdpa/virtio_pci/vp_vdpa.c
> index ac4ab22f7d8b..16380764275e 100644
> --- a/drivers/vdpa/virtio_pci/vp_vdpa.c
> +++ b/drivers/vdpa/virtio_pci/vp_vdpa.c
> @@ -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;
> @@ -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);
> --
> 2.40.1

Reviewed-by: Parav Pandit <parav@xxxxxxxxxx>






[Index of Archives]     [Linux Kernel]     [Kernel Development Newbies]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite Hiking]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux