diff options
author | Dan Carpenter <dan.carpenter@oracle.com> | 2017-01-07 01:28:40 -0500 |
---|---|---|
committer | Alex Williamson <alex.williamson@redhat.com> | 2017-01-11 14:12:29 -0500 |
commit | 5c677869e0abbffbade2cfd82d46d0eebe823f34 (patch) | |
tree | 7f4659715113784f3c88cd1dc61414b0fcecf37e | |
parent | 6ed0993a0b859ce62edf2930ded683e452286d39 (diff) |
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: 9d1a546c53b4 ("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>
-rw-r--r-- | samples/vfio-mdev/mtty.c | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/samples/vfio-mdev/mtty.c b/samples/vfio-mdev/mtty.c index 975af5bbf28d..382f4797428f 100644 --- a/samples/vfio-mdev/mtty.c +++ b/samples/vfio-mdev/mtty.c | |||
@@ -1073,7 +1073,7 @@ int mtty_get_region_info(struct mdev_device *mdev, | |||
1073 | { | 1073 | { |
1074 | unsigned int size = 0; | 1074 | unsigned int size = 0; |
1075 | struct mdev_state *mdev_state; | 1075 | struct mdev_state *mdev_state; |
1076 | int bar_index; | 1076 | u32 bar_index; |
1077 | 1077 | ||
1078 | if (!mdev) | 1078 | if (!mdev) |
1079 | return -EINVAL; | 1079 | return -EINVAL; |
@@ -1082,8 +1082,11 @@ int mtty_get_region_info(struct mdev_device *mdev, | |||
1082 | if (!mdev_state) | 1082 | if (!mdev_state) |
1083 | return -EINVAL; | 1083 | return -EINVAL; |
1084 | 1084 | ||
1085 | mutex_lock(&mdev_state->ops_lock); | ||
1086 | bar_index = region_info->index; | 1085 | bar_index = region_info->index; |
1086 | if (bar_index >= VFIO_PCI_NUM_REGIONS) | ||
1087 | return -EINVAL; | ||
1088 | |||
1089 | mutex_lock(&mdev_state->ops_lock); | ||
1087 | 1090 | ||
1088 | switch (bar_index) { | 1091 | switch (bar_index) { |
1089 | case VFIO_PCI_CONFIG_REGION_INDEX: | 1092 | case VFIO_PCI_CONFIG_REGION_INDEX: |