From mboxrd@z Thu Jan 1 00:00:00 1970 From: Kirti Wankhede Subject: Re: [patch 2/3] vfio-mdev: buffer overflow in ioctl() Date: Tue, 10 Jan 2017 00:09:36 +0530 Message-ID: References: <20170107062840.GB26959@elgon.mountain> Mime-Version: 1.0 Content-Type: text/plain; charset="windows-1252" Content-Transfer-Encoding: 7bit Cc: , , Alex Williamson To: Dan Carpenter Return-path: Received: from hqemgate15.nvidia.com ([216.228.121.64]:5587 "EHLO hqemgate15.nvidia.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1423044AbdAISkq (ORCPT ); Mon, 9 Jan 2017 13:40:46 -0500 In-Reply-To: <20170107062840.GB26959@elgon.mountain> Sender: kvm-owner@vger.kernel.org List-ID: CC+= Alex Thanks Dan for fixing. Reviewed by: Kirti Wankhede Thanks, Kirti On 1/7/2017 11:58 AM, Dan Carpenter wrote: > 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 > > diff --git a/samples/vfio-mdev/mtty.c b/samples/vfio-mdev/mtty.c > index d2656ff569c1..353666d68207 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, > { > unsigned int size = 0; > struct mdev_state *mdev_state; > - int bar_index; > + u32 bar_index; > > if (!mdev) > return -EINVAL; > @@ -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: >