From patchwork Fri Apr 26 08:34:03 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Wang X-Patchwork-Id: 239761 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 9DEC92C0112 for ; Fri, 26 Apr 2013 18:44:23 +1000 (EST) Received: from localhost ([::1]:41492 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UVeGR-0005WI-O4 for incoming@patchwork.ozlabs.org; Fri, 26 Apr 2013 04:44:19 -0400 Received: from eggs.gnu.org ([208.118.235.92]:60637) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UVeG1-0005QV-Ef for qemu-devel@nongnu.org; Fri, 26 Apr 2013 04:43:55 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UVeG0-0007PY-0x for qemu-devel@nongnu.org; Fri, 26 Apr 2013 04:43:53 -0400 Received: from mx1.redhat.com ([209.132.183.28]:34781) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UVeFz-0007PT-PT for qemu-devel@nongnu.org; Fri, 26 Apr 2013 04:43:51 -0400 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r3Q8hntl002728 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 26 Apr 2013 04:43:49 -0400 Received: from amd-6168-8-1.englab.nay.redhat.com (amd-6168-8-1.englab.nay.redhat.com [10.66.104.52]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id r3Q8hg18022139; Fri, 26 Apr 2013 04:43:45 -0400 From: Jason Wang To: aliguori@us.ibm.com, mst@redhat.com, qemu-devel@nongnu.org Date: Fri, 26 Apr 2013 16:34:03 +0800 Message-Id: <1366965244-20542-2-git-send-email-jasowang@redhat.com> In-Reply-To: <1366965244-20542-1-git-send-email-jasowang@redhat.com> References: <1366965244-20542-1-git-send-email-jasowang@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.12 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: Cornelia Huck , Jason Wang , pmatouse@redhat.com, Alexander Graf , Richard Henderson Subject: [Qemu-devel] [PATCH 2/3] virtio-ccw: check config length before accessing it X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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 --- 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);