Commit cdfea88d authored by Xiaoguang Wang's avatar Xiaoguang Wang Committed by liukai
Browse files

vp_vdpa: fix id_table array not null terminated error

stable inclusion
from stable-v6.1.119
commit 870d68fe17b5d9032049dcad98b5781a344a8657
category: bugfix
bugzilla: https://gitee.com/src-openeuler/kernel/issues/IB8IUJ
CVE: CVE-2024-53110

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=870d68fe17b5d9032049dcad98b5781a344a8657



--------------------------------

commit 4e39ecadf1d2a08187139619f1f314b64ba7d947 upstream.

Allocate one extra virtio_device_id as null terminator, otherwise
vdpa_mgmtdev_get_classes() may iterate multiple times and visit
undefined memory.

Fixes: ffbda8e9 ("vdpa/vp_vdpa : add vdpa tool support in vp_vdpa")
Cc: stable@vger.kernel.org
Suggested-by: default avatarParav Pandit <parav@nvidia.com>
Signed-off-by: default avatarAngus Chen <angus.chen@jaguarmicro.com>
Signed-off-by: default avatarXiaoguang Wang <lege.wang@jaguarmicro.com>
Message-Id: <20241105133518.1494-1-lege.wang@jaguarmicro.com>
Signed-off-by: default avatarMichael S. Tsirkin <mst@redhat.com>
Reviewed-by: default avatarParav Pandit <parav@nvidia.com>
Acked-by: default avatarJason Wang <jasowang@redhat.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: default avatarLiu Kai <liukai284@huawei.com>
parent b71af6f0
Loading
Loading
Loading
Loading
+7 −3
Original line number Diff line number Diff line
@@ -574,7 +574,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;
@@ -594,8 +598,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);