Skip to content

Commit 5c67786

Browse files
Dan CarpenterAlex Williamson
authored andcommitted
vfio-mdev: buffer overflow in ioctl()
This is a sample driver for documentation so the impact is probably pretty low. But we should check that bar_index is valid so we don't write beyond the end of the mdev_state->region_info[] array. Fixes: 9d1a546 ("docs: Sample driver to demonstrate how to use Mediated device framework.") Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com> Reviewed-by: Kirti Wankhede <kwankhede@nvidia.com> Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
1 parent 6ed0993 commit 5c67786

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

‎samples/vfio-mdev/mtty.c‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1073,7 +1073,7 @@ int mtty_get_region_info(struct mdev_device *mdev,
10731073
{
10741074
unsigned int size = 0;
10751075
struct mdev_state *mdev_state;
1076-
int bar_index;
1076+
u32 bar_index;
10771077

10781078
if (!mdev)
10791079
return -EINVAL;
@@ -1082,8 +1082,11 @@ int mtty_get_region_info(struct mdev_device *mdev,
10821082
if (!mdev_state)
10831083
return -EINVAL;
10841084

1085-
mutex_lock(&mdev_state->ops_lock);
10861085
bar_index = region_info->index;
1086+
if (bar_index >= VFIO_PCI_NUM_REGIONS)
1087+
return -EINVAL;
1088+
1089+
mutex_lock(&mdev_state->ops_lock);
10871090

10881091
switch (bar_index) {
10891092
case VFIO_PCI_CONFIG_REGION_INDEX:

0 commit comments

Comments
 (0)