From patchwork Wed Jul 28 15:13:22 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gleb Natapov X-Patchwork-Id: 60154 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 7A824B6F01 for ; Thu, 29 Jul 2010 01:17:24 +1000 (EST) Received: from localhost ([127.0.0.1]:45947 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Oe8Nl-00064A-S7 for incoming@patchwork.ozlabs.org; Wed, 28 Jul 2010 11:17:21 -0400 Received: from [140.186.70.92] (port=41319 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Oe8K0-0003w0-39 for qemu-devel@nongnu.org; Wed, 28 Jul 2010 11:13:29 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1Oe8Jx-0005eu-Qh for qemu-devel@nongnu.org; Wed, 28 Jul 2010 11:13:27 -0400 Received: from mx1.redhat.com ([209.132.183.28]:50409) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1Oe8Jx-0005eU-JT for qemu-devel@nongnu.org; Wed, 28 Jul 2010 11:13:25 -0400 Received: from int-mx04.intmail.prod.int.phx2.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.17]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o6SFDOca011728 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Wed, 28 Jul 2010 11:13:24 -0400 Received: from dhcp-1-237.tlv.redhat.com (dhcp-1-237.tlv.redhat.com [10.35.1.237]) by int-mx04.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o6SFDN43003975; Wed, 28 Jul 2010 11:13:23 -0400 Received: by dhcp-1-237.tlv.redhat.com (Postfix, from userid 13519) id 3443218D3C1; Wed, 28 Jul 2010 18:13:23 +0300 (IDT) From: Gleb Natapov To: qemu-devel@nongnu.org Date: Wed, 28 Jul 2010 18:13:22 +0300 Message-Id: <1280330003-1467-2-git-send-email-gleb@redhat.com> In-Reply-To: <1280330003-1467-1-git-send-email-gleb@redhat.com> References: <1280330003-1467-1-git-send-email-gleb@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.17 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. Cc: kvm@vger.kernel.org Subject: [Qemu-devel] [PATCH 1/2] Fix segfault in mmio subpage handling code. X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org It is possible that subpage mmio is registered over existing memory page. When this happens "memory" will have real memory address and not index into io_mem array so next access to the page will generate segfault. It is uncommon to have some part of a page to be accessed as memory and some as mmio, but qemu shouldn't crash even when guest does stupid things. So lets just pretend that the rest of the page is unassigned if guest configure part of the memory page as mmio. Signed-off-by: Gleb Natapov --- exec.c | 2 ++ 1 files changed, 2 insertions(+), 0 deletions(-) diff --git a/exec.c b/exec.c index 5e9a5b7..5945496 100644 --- a/exec.c +++ b/exec.c @@ -3363,6 +3363,8 @@ static int subpage_register (subpage_t *mmio, uint32_t start, uint32_t end, mmio, start, end, idx, eidx, memory); #endif memory = (memory >> IO_MEM_SHIFT) & (IO_MEM_NB_ENTRIES - 1); + if ((memory & ~TARGET_PAGE_MASK) == IO_MEM_RAM) + memory = IO_MEM_UNASSIGNED; for (; idx <= eidx; idx++) { mmio->sub_io_index[idx] = memory; mmio->region_offset[idx] = region_offset;