From patchwork Wed Nov 21 10:12:31 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Hajnoczi X-Patchwork-Id: 200629 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 1DF8F2C008E for ; Wed, 21 Nov 2012 21:33:07 +1100 (EST) Received: from localhost ([::1]:38973 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Tb7UJ-0004DQ-U4 for incoming@patchwork.ozlabs.org; Wed, 21 Nov 2012 05:24:59 -0500 Received: from eggs.gnu.org ([208.118.235.92]:34090) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Tb7Tk-0002du-G6 for qemu-devel@nongnu.org; Wed, 21 Nov 2012 05:24:25 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Tb7Te-0004WL-JA for qemu-devel@nongnu.org; Wed, 21 Nov 2012 05:24:24 -0500 Received: from mx1.redhat.com ([209.132.183.28]:55026) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Tb7Te-0004VK-Bk for qemu-devel@nongnu.org; Wed, 21 Nov 2012 05:24:18 -0500 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id qALAOHKm002102 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Wed, 21 Nov 2012 05:24:17 -0500 Received: from localhost (ovpn-112-23.ams2.redhat.com [10.36.112.23]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id qALAOGiT001668; Wed, 21 Nov 2012 05:24:17 -0500 From: Stefan Hajnoczi To: Anthony Liguori Date: Wed, 21 Nov 2012 11:12:31 +0100 Message-Id: <1353492752-16084-5-git-send-email-stefanha@redhat.com> In-Reply-To: <1353492752-16084-1-git-send-email-stefanha@redhat.com> References: <1353492752-16084-1-git-send-email-stefanha@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: Kevin Wolf , qemu-devel@nongnu.org, Stefan Hajnoczi Subject: [Qemu-devel] [PATCH 4/5] ide: Fix crash with too long PRD 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 From: Kevin Wolf Without this, s->nsector can become negative and badness happens (trying to malloc huge amount of memory and glib calls abort()) Signed-off-by: Kevin Wolf Signed-off-by: Stefan Hajnoczi --- hw/ide/core.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/hw/ide/core.c b/hw/ide/core.c index 7d6b0fa..c2ab787 100644 --- a/hw/ide/core.c +++ b/hw/ide/core.c @@ -579,6 +579,7 @@ void ide_dma_cb(void *opaque, int ret) IDEState *s = opaque; int n; int64_t sector_num; + bool stay_active = false; if (ret < 0) { int op = BM_STATUS_DMA_RETRY; @@ -594,6 +595,14 @@ void ide_dma_cb(void *opaque, int ret) } n = s->io_buffer_size >> 9; + if (n > s->nsector) { + /* The PRDs were longer than needed for this request. Shorten them so + * we don't get a negative remainder. The Active bit must remain set + * after the request completes. */ + n = s->nsector; + stay_active = true; + } + sector_num = ide_get_sector(s); if (n > 0) { dma_buf_commit(s); @@ -646,6 +655,9 @@ eot: bdrv_acct_done(s->bs, &s->acct); } ide_set_inactive(s); + if (stay_active) { + s->bus->dma->ops->add_status(s->bus->dma, BM_STATUS_DMAING); + } } static void ide_sector_start_dma(IDEState *s, enum ide_dma_cmd dma_cmd)