From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:49890) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Taqfz-00072R-3s for qemu-devel@nongnu.org; Tue, 20 Nov 2012 11:27:58 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Taqfu-0002kG-H5 for qemu-devel@nongnu.org; Tue, 20 Nov 2012 11:27:54 -0500 Received: from mx1.redhat.com ([209.132.183.28]:5019) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Taqfu-0002jx-9k for qemu-devel@nongnu.org; Tue, 20 Nov 2012 11:27:50 -0500 Received: from int-mx12.intmail.prod.int.phx2.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.25]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id qAKGRnku025598 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Tue, 20 Nov 2012 11:27:49 -0500 From: Kevin Wolf Date: Tue, 20 Nov 2012 17:27:43 +0100 Message-Id: <1353428864-19505-2-git-send-email-kwolf@redhat.com> In-Reply-To: <1353428864-19505-1-git-send-email-kwolf@redhat.com> References: <1353428864-19505-1-git-send-email-kwolf@redhat.com> Subject: [Qemu-devel] [PATCH 1/2] ide: Fix crash with too long PRD List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: stefanha@redhat.com Cc: kwolf@redhat.com, qemu-devel@nongnu.org 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 --- hw/ide/core.c | 12 ++++++++++++ 1 files changed, 12 insertions(+), 0 deletions(-) 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) -- 1.7.6.5