From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:49654) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UWN9v-0007DU-Oe for qemu-devel@nongnu.org; Sun, 28 Apr 2013 04:40:36 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UWN9u-0000mS-Ro for qemu-devel@nongnu.org; Sun, 28 Apr 2013 04:40:35 -0400 Received: from mx1.redhat.com ([209.132.183.28]:31253) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UWN9u-0000mN-JH for qemu-devel@nongnu.org; Sun, 28 Apr 2013 04:40:34 -0400 Message-ID: <517CE073.1090506@redhat.com> Date: Sun, 28 Apr 2013 16:40:19 +0800 From: Jason Wang MIME-Version: 1.0 References: <1366965244-20542-1-git-send-email-jasowang@redhat.com> <1366965244-20542-2-git-send-email-jasowang@redhat.com> <20130428083239.GD7106@redhat.com> In-Reply-To: <20130428083239.GD7106@redhat.com> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH 2/3] virtio-ccw: check config length before accessing it List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: "Michael S. Tsirkin" Cc: aliguori@us.ibm.com, pmatouse@redhat.com, Alexander Graf , qemu-devel@nongnu.org, Cornelia Huck , Richard Henderson On 04/28/2013 04:32 PM, Michael S. Tsirkin wrote: > On Fri, Apr 26, 2013 at 04:34:03PM +0800, Jason Wang wrote: >> virtio-rng-ccw has zero config length, so we need validate the config length >> before trying to access it. Otherwise we may crash since vdev->config is NULL. >> >> Cc: Cornelia Huck >> Cc: Richard Henderson >> Cc: Alexander Graf >> Signed-off-by: Jason Wang > The real problem is dev->vdev->get_config being NULL, > isn't it? So why not validate it and be done with it? Ok, this looks more clear. Will do it in V2. >> --- >> hw/s390x/virtio-ccw.c | 4 ++-- >> 1 files changed, 2 insertions(+), 2 deletions(-) >> >> diff --git a/hw/s390x/virtio-ccw.c b/hw/s390x/virtio-ccw.c >> index 56539d3..8d0dff5 100644 >> --- a/hw/s390x/virtio-ccw.c >> +++ b/hw/s390x/virtio-ccw.c >> @@ -260,7 +260,7 @@ static int virtio_ccw_cb(SubchDev *sch, CCW1 ccw) >> } >> } >> len = MIN(ccw.count, dev->vdev->config_len); >> - if (!ccw.cda) { >> + if (!ccw.cda || !len) { >> ret = -EFAULT; >> } else { >> dev->vdev->get_config(dev->vdev, dev->vdev->config); >> @@ -279,7 +279,7 @@ static int virtio_ccw_cb(SubchDev *sch, CCW1 ccw) >> } >> len = MIN(ccw.count, dev->vdev->config_len); >> hw_len = len; >> - if (!ccw.cda) { >> + if (!ccw.cda || !len) { >> ret = -EFAULT; >> } else { >> config = cpu_physical_memory_map(ccw.cda, &hw_len, 0); >> -- >> 1.7.1