Skip to content

Commit

Permalink
vfio-mdev: buffer overflow in ioctl()
Browse files Browse the repository at this point in the history
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 <[email protected]>
Reviewed-by: Kirti Wankhede <[email protected]>
Signed-off-by: Alex Williamson <[email protected]>
  • Loading branch information
Dan Carpenter authored and awilliam committed Jan 11, 2017
1 parent 6ed0993 commit 5c67786
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions samples/vfio-mdev/mtty.c
Original file line number Diff line number Diff line change
Expand Up @@ -1073,7 +1073,7 @@ int mtty_get_region_info(struct mdev_device *mdev,
{
unsigned int size = 0;
struct mdev_state *mdev_state;
int bar_index;
u32 bar_index;

if (!mdev)
return -EINVAL;
Expand All @@ -1082,8 +1082,11 @@ int mtty_get_region_info(struct mdev_device *mdev,
if (!mdev_state)
return -EINVAL;

mutex_lock(&mdev_state->ops_lock);
bar_index = region_info->index;
if (bar_index >= VFIO_PCI_NUM_REGIONS)
return -EINVAL;

mutex_lock(&mdev_state->ops_lock);

switch (bar_index) {
case VFIO_PCI_CONFIG_REGION_INDEX:
Expand Down

0 comments on commit 5c67786

Please sign in to comment.